Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/npf/npfctl don't leak the branch target array.



details:   https://anonhg.NetBSD.org/src/rev/86ff058005a4
branches:  trunk
changeset: 778012:86ff058005a4
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Mar 12 15:32:02 2012 +0000

description:
don't leak the branch target array.

diffstat:

 usr.sbin/npf/npfctl/npf_disassemble.c |  16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)

diffs (58 lines):

diff -r b792b9b16476 -r 86ff058005a4 usr.sbin/npf/npfctl/npf_disassemble.c
--- a/usr.sbin/npf/npfctl/npf_disassemble.c     Mon Mar 12 09:09:40 2012 +0000
+++ b/usr.sbin/npf/npfctl/npf_disassemble.c     Mon Mar 12 15:32:02 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: npf_disassemble.c,v 1.2 2012/03/10 22:55:28 christos Exp $     */
+/*     $NetBSD: npf_disassemble.c,v 1.3 2012/03/12 15:32:02 christos Exp $     */
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: npf_disassemble.c,v 1.2 2012/03/10 22:55:28 christos Exp $");
+__RCSID("$NetBSD: npf_disassemble.c,v 1.3 2012/03/12 15:32:02 christos Exp $");
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -221,6 +221,7 @@
        char buf[256];
        const uint32_t **targ;
        size_t tlen, mlen, target;
+       int error = -1;
 
        targ = NULL;
        mlen = tlen = 0;
@@ -229,13 +230,13 @@
                if (*pc & ~0xff) {
                        warnx("bad opcode 0x%x at offset (%td)", *pc,
                            pc - st);
-                       return -1;
+                       goto out;
                }
                ni = &npf_instructions[*pc];
                if (ni->name == NULL) {
                        warnx("invalid opcode 0x%x at offset (%td)", *pc,
                            pc - st);
-                       return -1;
+                       goto out;
                }
                ipc = pc;
                target = npfctl_ncode_get_target(pc, targ, tlen);
@@ -250,10 +251,13 @@
                        op = npfctl_ncode_operand(buf, sizeof(buf), ni->op[i],
                            st, ipc, &pc, &len, &targ, &tlen, &mlen);
                        if (op == NULL)
-                               return -1;
+                               goto out;
                        fprintf(fp, "%s%s", i == 0 ? " " : ", ", op);
                }
                fprintf(fp, "\n");
        }
-       return 0;
+       error = 0;
+out:
+       free(targ);
+       return error;
 }



Home | Main Index | Thread Index | Old Index