Module Name: src
Committed By: riz
Date: Mon Nov 26 17:39:29 UTC 2012
Modified Files:
src/sys/net/npf [netbsd-6]: npf_impl.h
src/usr.sbin/npf/npfctl [netbsd-6]: npf_disassemble.c npf_extmod.c
npf_ncgen.c npf_parse.y npf_scan.l npf_var.c npfctl.c npfctl.h
Log Message:
Pull up following revision(s) (requested by rmind in ticket #718):
usr.sbin/npf/npfctl/npfctl.c: revision 1.22
usr.sbin/npf/npfctl/npfctl.c: revision 1.23
usr.sbin/npf/npfctl/npf_parse.y: revision 1.15
usr.sbin/npf/npfctl/npfctl.c: revision 1.24
usr.sbin/npf/npfctl/npf_parse.y: revision 1.16
usr.sbin/npf/npfctl/npfctl.h: revision 1.22
usr.sbin/npf/npfctl/npf_ncgen.c: revision 1.14
usr.sbin/npf/npfctl/npf_ncgen.c: revision 1.15
usr.sbin/npf/npfctl/npf_disassemble.c: revision 1.11
usr.sbin/npf/npfctl/npf_disassemble.c: revision 1.12
usr.sbin/npf/npfctl/npf_scan.l: revision 1.7
usr.sbin/npf/npfctl/npf_scan.l: revision 1.8
usr.sbin/npf/npfctl/npf_extmod.c: revision 1.2
usr.sbin/npf/npfctl/npf_extmod.c: revision 1.3
usr.sbin/npf/npfctl/npf_var.c: revision 1.6
usr.sbin/npf/npfctl/npf_var.c: revision 1.7
gcc 4.1 is not smart enough to notice "arg" is only used when
initialized
correctly and produces a "might be used unintialized" warning.
npfctl: switch to efun(3) routines.
npfctl: switch to ecalloc(3).
To generate a diff of this commit:
cvs rdiff -u -r1.10.2.10 -r1.10.2.11 src/sys/net/npf/npf_impl.h
cvs rdiff -u -r1.3.2.8 -r1.3.2.9 src/usr.sbin/npf/npfctl/npf_disassemble.c \
src/usr.sbin/npf/npfctl/npf_parse.y
cvs rdiff -u -r1.3.2.2 -r1.3.2.3 src/usr.sbin/npf/npfctl/npf_extmod.c
cvs rdiff -u -r1.7.2.5 -r1.7.2.6 src/usr.sbin/npf/npfctl/npf_ncgen.c
cvs rdiff -u -r1.1.2.4 -r1.1.2.5 src/usr.sbin/npf/npfctl/npf_scan.l
cvs rdiff -u -r1.3.2.1 -r1.3.2.2 src/usr.sbin/npf/npfctl/npf_var.c
cvs rdiff -u -r1.10.2.8 -r1.10.2.9 src/usr.sbin/npf/npfctl/npfctl.c
cvs rdiff -u -r1.11.2.8 -r1.11.2.9 src/usr.sbin/npf/npfctl/npfctl.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/net/npf/npf_impl.h
diff -u src/sys/net/npf/npf_impl.h:1.10.2.10 src/sys/net/npf/npf_impl.h:1.10.2.11
--- src/sys/net/npf/npf_impl.h:1.10.2.10 Sat Nov 24 04:34:42 2012
+++ src/sys/net/npf/npf_impl.h Mon Nov 26 17:39:29 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: npf_impl.h,v 1.10.2.10 2012/11/24 04:34:42 riz Exp $ */
+/* $NetBSD: npf_impl.h,v 1.10.2.11 2012/11/26 17:39:29 riz Exp $ */
/*-
* Copyright (c) 2009-2012 The NetBSD Foundation, Inc.
@@ -201,7 +201,7 @@ int npf_match_tcpfl(npf_cache_t *, nbuf
void npf_tableset_sysinit(void);
void npf_tableset_sysfini(void);
-const pt_tree_ops_t npf_table_ptree_ops;
+extern const pt_tree_ops_t npf_table_ptree_ops;
npf_tableset_t *npf_tableset_create(void);
void npf_tableset_destroy(npf_tableset_t *);
Index: src/usr.sbin/npf/npfctl/npf_disassemble.c
diff -u src/usr.sbin/npf/npfctl/npf_disassemble.c:1.3.2.8 src/usr.sbin/npf/npfctl/npf_disassemble.c:1.3.2.9
--- src/usr.sbin/npf/npfctl/npf_disassemble.c:1.3.2.8 Sat Nov 24 04:34:43 2012
+++ src/usr.sbin/npf/npfctl/npf_disassemble.c Mon Nov 26 17:39:29 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: npf_disassemble.c,v 1.3.2.8 2012/11/24 04:34:43 riz Exp $ */
+/* $NetBSD: npf_disassemble.c,v 1.3.2.9 2012/11/26 17:39:29 riz Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
* FIXME: config generation should be redesigned..
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: npf_disassemble.c,v 1.3.2.8 2012/11/24 04:34:43 riz Exp $");
+__RCSID("$NetBSD: npf_disassemble.c,v 1.3.2.9 2012/11/26 17:39:29 riz Exp $");
#include <stdio.h>
#include <stdlib.h>
@@ -48,8 +48,6 @@ __RCSID("$NetBSD: npf_disassemble.c,v 1.
#include <netinet/tcp.h>
#include <net/if.h>
-#include <util.h>
-
#define NPF_OPCODES_STRINGS
#include <net/npf_ncode.h>
@@ -108,7 +106,7 @@ npfctl_ncode_add_target(nc_inf_t *ni, co
/* Grow array, if needed, and add a new target. */
if (ni->ni_targidx == ni->ni_targsize) {
ni->ni_targsize += 16;
- ni->ni_targs = xrealloc(ni->ni_targs,
+ ni->ni_targs = erealloc(ni->ni_targs,
ni->ni_targsize * sizeof(uint32_t));
}
assert(ni->ni_targidx < ni->ni_targsize);
@@ -372,7 +370,7 @@ npfctl_ncode_operand(nc_inf_t *ni, char
nc_inf_t *
npfctl_ncode_disinf(FILE *fp)
{
- nc_inf_t *ni = zalloc(sizeof(nc_inf_t));
+ nc_inf_t *ni = ecalloc(1, sizeof(nc_inf_t));
memset(ni, 0, sizeof(nc_inf_t));
ni->ni_fp = fp;
Index: src/usr.sbin/npf/npfctl/npf_parse.y
diff -u src/usr.sbin/npf/npfctl/npf_parse.y:1.3.2.8 src/usr.sbin/npf/npfctl/npf_parse.y:1.3.2.9
--- src/usr.sbin/npf/npfctl/npf_parse.y:1.3.2.8 Sun Nov 18 22:38:28 2012
+++ src/usr.sbin/npf/npfctl/npf_parse.y Mon Nov 26 17:39:29 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: npf_parse.y,v 1.3.2.8 2012/11/18 22:38:28 riz Exp $ */
+/* $NetBSD: npf_parse.y,v 1.3.2.9 2012/11/26 17:39:29 riz Exp $ */
/*-
* Copyright (c) 2011-2012 The NetBSD Foundation, Inc.
@@ -54,7 +54,7 @@ yyerror(const char *fmt, ...)
extern int yyleng;
extern char *yytext;
- char *msg, *context = xstrndup(yytext, yyleng);
+ char *msg, *context = estrndup(yytext, yyleng);
bool eol = (*context == '\n');
va_list ap;
@@ -66,7 +66,7 @@ yyerror(const char *fmt, ...)
yylineno - (int)eol, yycolumn, msg);
if (!eol) {
size_t len = strlen(context);
- char *dst = zalloc(len * 4 + 1);
+ char *dst = ecalloc(1, len * 4 + 1);
strvisx(dst, context, len, VIS_WHITE|VIS_CSTYLE);
fprintf(stderr, " near '%s'", dst);
@@ -130,13 +130,13 @@ yyerror(const char *fmt, ...)
%token TYPE
%token <num> ICMP
%token <num> ICMP6
-%token <fpnum> FPNUM
%token <num> HEX
%token <str> IDENTIFIER
%token <str> IPV4ADDR
%token <str> IPV6ADDR
%token <num> NUM
+%token <fpnum> FPNUM
%token <str> STRING
%token <str> TABLE_ID
%token <str> VAR_ID
@@ -315,7 +315,7 @@ proc_call
{
proc_call_t pc;
- pc.pc_name = xstrdup($1);
+ pc.pc_name = estrdup($1);
pc.pc_opts = $3;
$$ = npfvar_create(".proc_call");
npfvar_add_element($$, NPFVAR_PROC, &pc, sizeof(pc));
@@ -338,8 +338,8 @@ proc_param
{
proc_param_t pp;
- pp.pp_param = xstrdup($1);
- pp.pp_value = $2 ? xstrdup($2) : NULL;
+ pp.pp_param = estrdup($1);
+ pp.pp_value = $2 ? estrdup($2) : NULL;
$$ = npfvar_create(".proc_param");
npfvar_add_element($$, NPFVAR_PROC_PARAM, &pp, sizeof(pp));
}
@@ -610,7 +610,6 @@ addr
| IPV6ADDR { $$ = $1; }
;
-
port_range
: PORT port /* just port */
{
Index: src/usr.sbin/npf/npfctl/npf_extmod.c
diff -u src/usr.sbin/npf/npfctl/npf_extmod.c:1.3.2.2 src/usr.sbin/npf/npfctl/npf_extmod.c:1.3.2.3
--- src/usr.sbin/npf/npfctl/npf_extmod.c:1.3.2.2 Sun Nov 18 22:38:28 2012
+++ src/usr.sbin/npf/npfctl/npf_extmod.c Mon Nov 26 17:39:29 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: npf_extmod.c,v 1.3.2.2 2012/11/18 22:38:28 riz Exp $ */
+/* $NetBSD: npf_extmod.c,v 1.3.2.3 2012/11/26 17:39:29 riz Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: npf_extmod.c,v 1.3.2.2 2012/11/18 22:38:28 riz Exp $");
+__RCSID("$NetBSD: npf_extmod.c,v 1.3.2.3 2012/11/26 17:39:29 riz Exp $");
#include <stdlib.h>
#include <inttypes.h>
@@ -81,8 +81,8 @@ npf_extmod_load(const char *name)
errx(EXIT_FAILURE, "dlopen: %s", dlerror());
}
- ext = zalloc(sizeof(npf_extmod_t));
- ext->name = xstrdup(name);
+ ext = ecalloc(1, sizeof(npf_extmod_t));
+ ext->name = estrdup(name);
ext->init = npf_extmod_sym(handle, name, "init");
ext->cons = npf_extmod_sym(handle, name, "construct");
ext->param = npf_extmod_sym(handle, name, "param");
Index: src/usr.sbin/npf/npfctl/npf_ncgen.c
diff -u src/usr.sbin/npf/npfctl/npf_ncgen.c:1.7.2.5 src/usr.sbin/npf/npfctl/npf_ncgen.c:1.7.2.6
--- src/usr.sbin/npf/npfctl/npf_ncgen.c:1.7.2.5 Wed Jul 25 20:45:23 2012
+++ src/usr.sbin/npf/npfctl/npf_ncgen.c Mon Nov 26 17:39:29 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: npf_ncgen.c,v 1.7.2.5 2012/07/25 20:45:23 jdc Exp $ */
+/* $NetBSD: npf_ncgen.c,v 1.7.2.6 2012/11/26 17:39:29 riz Exp $ */
/*-
* Copyright (c) 2009-2012 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: npf_ncgen.c,v 1.7.2.5 2012/07/25 20:45:23 jdc Exp $");
+__RCSID("$NetBSD: npf_ncgen.c,v 1.7.2.6 2012/11/26 17:39:29 riz Exp $");
#include <stdlib.h>
#include <stddef.h>
@@ -91,7 +91,7 @@ npfctl_ncgen_getptr(nc_ctx_t *ctx, size_
/* Otherwise, re-allocate the buffer and update the pointers. */
ctx->nc_len = NC_ALLOC_ROUND(reqlen);
- ctx->nc_buf = xrealloc(ctx->nc_buf, ctx->nc_len);
+ ctx->nc_buf = erealloc(ctx->nc_buf, ctx->nc_len);
ctx->nc_iptr = (uint8_t *)ctx->nc_buf + offset;
return ctx->nc_iptr;
}
@@ -126,7 +126,7 @@ npfctl_ncgen_addjmp(nc_ctx_t *ctx, uint3
reqlen = NC_ALLOC_ROUND(ctx->nc_jmp_it * sizeof(ptrdiff_t));
if (reqlen > NC_ALLOC_ROUND(ctx->nc_jmp_len)) {
- ctx->nc_jmp_list = xrealloc(ctx->nc_jmp_list, reqlen);
+ ctx->nc_jmp_list = erealloc(ctx->nc_jmp_list, reqlen);
ctx->nc_jmp_len = reqlen;
}
@@ -145,7 +145,7 @@ npfctl_ncgen_addjmp(nc_ctx_t *ctx, uint3
nc_ctx_t *
npfctl_ncgen_create(void)
{
- return zalloc(sizeof(nc_ctx_t));
+ return ecalloc(1, sizeof(nc_ctx_t));
}
/*
Index: src/usr.sbin/npf/npfctl/npf_scan.l
diff -u src/usr.sbin/npf/npfctl/npf_scan.l:1.1.2.4 src/usr.sbin/npf/npfctl/npf_scan.l:1.1.2.5
--- src/usr.sbin/npf/npfctl/npf_scan.l:1.1.2.4 Sun Nov 18 22:38:28 2012
+++ src/usr.sbin/npf/npfctl/npf_scan.l Mon Nov 26 17:39:29 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: npf_scan.l,v 1.1.2.4 2012/11/18 22:38:28 riz Exp $ */
+/* $NetBSD: npf_scan.l,v 1.1.2.5 2012/11/26 17:39:29 riz Exp $ */
/*-
* Copyright (c) 2011-2012 The NetBSD Foundation, Inc.
@@ -109,7 +109,7 @@ any return ANY;
"=" return EQ;
"0x"[0-9a-fA-F]+ {
- char *endp, *buf = zalloc(yyleng + 1);
+ char *endp, *buf = ecalloc(1, yyleng + 1);
buf[yyleng] = 0;
yylval.num = strtoul(buf+2, &endp, 16);
free(buf);
@@ -117,46 +117,46 @@ any return ANY;
}
{NUMBER}"."{NUMBER} {
- char *endp, *buf = xstrndup(yytext, yyleng);
+ char *endp, *buf = estrndup(yytext, yyleng);
yylval.fpnum = strtod(buf, &endp);
free(buf);
return FPNUM;
}
[0-9a-fA-F]+":"[0-9a-fA-F:]* {
- yylval.str = xstrndup(yytext, yyleng);
+ yylval.str = estrndup(yytext, yyleng);
return IPV6ADDR;
}
{NUMBER}"."[0-9][0-9.]* {
- yylval.str = xstrndup(yytext, yyleng);
+ yylval.str = estrndup(yytext, yyleng);
return IPV4ADDR;
}
{NUMBER} {
- char *endp, *buf = xstrndup(yytext, yyleng);
+ char *endp, *buf = estrndup(yytext, yyleng);
yylval.num = strtoul(buf, &endp, 10);
free(buf);
return NUM;
}
"<"{NID}">" {
- yylval.str = xstrndup(yytext + 1, yyleng - 2);
+ yylval.str = estrndup(yytext + 1, yyleng - 2);
return TABLE_ID;
}
"$"{NID} {
- yylval.str = xstrndup(yytext + 1, yyleng - 1);
+ yylval.str = estrndup(yytext + 1, yyleng - 1);
return VAR_ID;
}
{ID} {
- yylval.str = xstrndup(yytext, yyleng);
+ yylval.str = estrndup(yytext, yyleng);
return IDENTIFIER;
}
\"[^\"]*\" {
- yylval.str = xstrndup(yytext + 1, yyleng - 2);
+ yylval.str = estrndup(yytext + 1, yyleng - 2);
return STRING;
}
Index: src/usr.sbin/npf/npfctl/npf_var.c
diff -u src/usr.sbin/npf/npfctl/npf_var.c:1.3.2.1 src/usr.sbin/npf/npfctl/npf_var.c:1.3.2.2
--- src/usr.sbin/npf/npfctl/npf_var.c:1.3.2.1 Tue Jun 26 00:07:20 2012
+++ src/usr.sbin/npf/npfctl/npf_var.c Mon Nov 26 17:39:29 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: npf_var.c,v 1.3.2.1 2012/06/26 00:07:20 riz Exp $ */
+/* $NetBSD: npf_var.c,v 1.3.2.2 2012/11/26 17:39:29 riz Exp $ */
/*-
* Copyright (c) 2011-2012 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: npf_var.c,v 1.3.2.1 2012/06/26 00:07:20 riz Exp $");
+__RCSID("$NetBSD: npf_var.c,v 1.3.2.2 2012/11/26 17:39:29 riz Exp $");
#include <stdlib.h>
#include <string.h>
@@ -60,8 +60,8 @@ static size_t var_num = 0;
npfvar_t *
npfvar_create(const char *name)
{
- npfvar_t *vp = zalloc(sizeof(*vp));
- vp->v_key = xstrdup(name);
+ npfvar_t *vp = ecalloc(1, sizeof(*vp));
+ vp->v_key = estrdup(name);
var_num++;
return vp;
}
@@ -104,8 +104,8 @@ npfvar_add_element(npfvar_t *vp, int typ
return NULL;
}
vp->v_count++;
- el = zalloc(sizeof(*el));
- el->e_data = zalloc(len);
+ el = ecalloc(1, sizeof(*el));
+ el->e_data = ecalloc(1, len);
el->e_type = type;
memcpy(el->e_data, data, len);
Index: src/usr.sbin/npf/npfctl/npfctl.c
diff -u src/usr.sbin/npf/npfctl/npfctl.c:1.10.2.8 src/usr.sbin/npf/npfctl/npfctl.c:1.10.2.9
--- src/usr.sbin/npf/npfctl/npfctl.c:1.10.2.8 Sat Nov 24 04:34:43 2012
+++ src/usr.sbin/npf/npfctl/npfctl.c Mon Nov 26 17:39:29 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: npfctl.c,v 1.10.2.8 2012/11/24 04:34:43 riz Exp $ */
+/* $NetBSD: npfctl.c,v 1.10.2.9 2012/11/26 17:39:29 riz Exp $ */
/*-
* Copyright (c) 2009-2012 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: npfctl.c,v 1.10.2.8 2012/11/24 04:34:43 riz Exp $");
+__RCSID("$NetBSD: npfctl.c,v 1.10.2.9 2012/11/26 17:39:29 riz Exp $");
#include <sys/ioctl.h>
#include <sys/stat.h>
@@ -44,8 +44,6 @@ __RCSID("$NetBSD: npfctl.c,v 1.10.2.8 20
#include <unistd.h>
#include <errno.h>
-#include <util.h>
-
#include "npfctl.h"
extern int yylineno, yycolumn;
@@ -86,52 +84,6 @@ static const struct operations_s {
{ NULL, 0 }
};
-void *
-zalloc(size_t sz)
-{
- void *p = malloc(sz);
-
- if (p == NULL) {
- err(EXIT_FAILURE, "zalloc");
- }
- memset(p, 0, sz);
- return p;
-}
-
-void *
-xrealloc(void *ptr, size_t size)
-{
- void *p = realloc(ptr, size);
-
- if (p == NULL) {
- err(EXIT_FAILURE, "xrealloc");
- }
- return p;
-}
-
-char *
-xstrdup(const char *s)
-{
- char *p = strdup(s);
-
- if (p == NULL) {
- err(EXIT_FAILURE, "xstrdup");
- }
- return p;
-}
-
-char *
-xstrndup(const char *s, size_t len)
-{
- char *p;
-
- p = strndup(s, len);
- if (p == NULL) {
- err(EXIT_FAILURE, "xstrndup");
- }
- return p;
-}
-
__dead static void
usage(void)
{
@@ -211,7 +163,7 @@ npfctl_print_stats(int fd)
{ -1, "Other" },
{ NPF_STAT_ERROR, "unexpected errors" },
};
- uint64_t *st = zalloc(NPF_STATS_SIZE);
+ uint64_t *st = ecalloc(1, NPF_STATS_SIZE);
if (ioctl(fd, IOC_NPF_STATS, &st) != 0) {
err(EXIT_FAILURE, "ioctl(IOC_NPF_STATS)");
@@ -261,7 +213,7 @@ char *
npfctl_print_addrmask(int alen, npf_addr_t *addr, npf_netmask_t mask)
{
struct sockaddr_storage ss;
- char *buf = zalloc(64);
+ char *buf = ecalloc(1, 64);
int len;
switch (alen) {
@@ -307,7 +259,7 @@ npfctl_table(int fd, int argc, char **ar
npf_ioctl_table_t nct;
fam_addr_mask_t fam;
size_t buflen = 512;
- char *cmd, *arg;
+ char *cmd, *arg = NULL; /* XXX gcc */
int n, alen;
/* Default action is list. */
@@ -333,7 +285,7 @@ npfctl_table(int fd, int argc, char **ar
}
again:
if (nct.nct_action == NPF_IOCTL_TBLENT_LIST) {
- nct.nct_data.buf.buf = zalloc(buflen);
+ nct.nct_data.buf.buf = ecalloc(1, buflen);
nct.nct_data.buf.len = buflen;
} else {
if (!npfctl_parse_cidr(arg, &fam, &alen)) {
Index: src/usr.sbin/npf/npfctl/npfctl.h
diff -u src/usr.sbin/npf/npfctl/npfctl.h:1.11.2.8 src/usr.sbin/npf/npfctl/npfctl.h:1.11.2.9
--- src/usr.sbin/npf/npfctl/npfctl.h:1.11.2.8 Sat Nov 24 04:34:43 2012
+++ src/usr.sbin/npf/npfctl/npfctl.h Mon Nov 26 17:39:29 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: npfctl.h,v 1.11.2.8 2012/11/24 04:34:43 riz Exp $ */
+/* $NetBSD: npfctl.h,v 1.11.2.9 2012/11/26 17:39:29 riz Exp $ */
/*-
* Copyright (c) 2009-2012 The NetBSD Foundation, Inc.
@@ -33,6 +33,8 @@
#include <stdbool.h>
#include <inttypes.h>
#include <assert.h>
+#include <util.h>
+#undef ECHO /* XXX util.h */
#include <net/npf_ncode.h>
#include <net/npf.h>
@@ -90,10 +92,6 @@ typedef struct proc_param {
} proc_param_t;
void yyerror(const char *, ...) __printflike(1, 2) __dead;
-void * zalloc(size_t);
-void * xrealloc(void *, size_t);
-char * xstrdup(const char *);
-char * xstrndup(const char *, size_t);
void npfctl_print_error(const nl_error_t *);
char * npfctl_print_addrmask(int, npf_addr_t *, npf_netmask_t);