[nft] Fix memleak in netlink_parse_fwd() error path

Message ID 20181012105409.8204-1-phil@nwl.cc
State Accepted
Delegated to: Pablo Neira
Headers show
Series
  • [nft] Fix memleak in netlink_parse_fwd() error path
Related show

Commit Message

Phil Sutter Oct. 12, 2018, 10:54 a.m.
Make sure allocated 'stmt' is freed before returning to caller.

Fixes: 30d45266bf38b ("expr: extend fwd statement to support address and family")
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 src/netlink_delinearize.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

Comments

Pablo Neira Ayuso Oct. 15, 2018, 12:09 p.m. | #1
On Fri, Oct 12, 2018 at 12:54:09PM +0200, Phil Sutter wrote:
> Make sure allocated 'stmt' is freed before returning to caller.

Applied, thanks.

Patch

diff --git a/src/netlink_delinearize.c b/src/netlink_delinearize.c
index 0a6ebe05ca7ca..cd058850f4df0 100644
--- a/src/netlink_delinearize.c
+++ b/src/netlink_delinearize.c
@@ -1227,9 +1227,11 @@  static void netlink_parse_fwd(struct netlink_parse_ctx *ctx,
 		reg2 = netlink_parse_register(nle, NFTNL_EXPR_FWD_SREG_ADDR);
 		if (reg2) {
 			addr = netlink_get_register(ctx, loc, reg2);
-			if (addr == NULL)
-				return netlink_error(ctx, loc,
-						     "fwd statement has no output expression");
+			if (addr == NULL) {
+				netlink_error(ctx, loc,
+					      "fwd statement has no output expression");
+				goto out_err;
+			}
 
 			switch (stmt->fwd.family) {
 			case AF_INET:
@@ -1241,8 +1243,9 @@  static void netlink_parse_fwd(struct netlink_parse_ctx *ctx,
 					      BYTEORDER_BIG_ENDIAN);
 				break;
 			default:
-				return netlink_error(ctx, loc,
-						     "fwd statement has no family");
+				netlink_error(ctx, loc,
+					      "fwd statement has no family");
+				goto out_err;
 			}
 			stmt->fwd.addr = addr;
 		}