v1.14 from OpenBSD (jaredy):
- fix overflow when too many -a arguments are given - properly NUL-terminate -a arguments when copying - check strdup for error failure
This commit is contained in:
parent
8221a0eff7
commit
bd02b4a3e5
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: checknr.c,v 1.15 2005/02/02 17:14:29 wiz Exp $ */
|
/* $NetBSD: checknr.c,v 1.16 2005/03/30 14:18:41 wiz Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1980, 1993
|
* Copyright (c) 1980, 1993
|
||||||
@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1993\n\
|
|||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)checknr.c 8.1 (Berkeley) 6/6/93";
|
static char sccsid[] = "@(#)checknr.c 8.1 (Berkeley) 6/6/93";
|
||||||
#else
|
#else
|
||||||
__RCSID("$NetBSD: checknr.c,v 1.15 2005/02/02 17:14:29 wiz Exp $");
|
__RCSID("$NetBSD: checknr.c,v 1.16 2005/03/30 14:18:41 wiz Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
@ -138,7 +138,7 @@ struct brstr {
|
|||||||
{"TS", "TE"},
|
{"TS", "TE"},
|
||||||
/* Refer */
|
/* Refer */
|
||||||
{"[", "]"},
|
{"[", "]"},
|
||||||
{0, 0},
|
{0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -235,10 +235,14 @@ main(int argc, char **argv)
|
|||||||
for (i=0; br[i].opbr; i++)
|
for (i=0; br[i].opbr; i++)
|
||||||
;
|
;
|
||||||
for (cp=argv[1]+3; cp[-1]; cp += 6) {
|
for (cp=argv[1]+3; cp[-1]; cp += 6) {
|
||||||
br[i].opbr = malloc(3);
|
if (i >= MAXBR)
|
||||||
strncpy(br[i].opbr, cp, 2);
|
errx(1, "too many pairs");
|
||||||
br[i].clbr = malloc(3);
|
if ((br[i].opbr = malloc(3)) == NULL)
|
||||||
strncpy(br[i].clbr, cp+3, 2);
|
err(1, "malloc");
|
||||||
|
strlcpy(br[i].opbr, cp, 3);
|
||||||
|
if ((br[i].clbr = malloc(3)) == NULL)
|
||||||
|
err(1, "malloc");
|
||||||
|
strlcpy(br[i].clbr, cp+3, 3);
|
||||||
addmac(br[i].opbr); /* knows pairs are also known cmds */
|
addmac(br[i].opbr); /* knows pairs are also known cmds */
|
||||||
addmac(br[i].clbr);
|
addmac(br[i].clbr);
|
||||||
i++;
|
i++;
|
||||||
@ -592,8 +596,8 @@ addmac(char *mac)
|
|||||||
dest = src+1;
|
dest = src+1;
|
||||||
while (dest > loc)
|
while (dest > loc)
|
||||||
*dest-- = *src--;
|
*dest-- = *src--;
|
||||||
*loc = malloc(3);
|
if ((*loc = strdup(mac)) == NULL)
|
||||||
strcpy(*loc, mac);
|
err(1, "strdup");
|
||||||
ncmds++;
|
ncmds++;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("after: %s %s %s %s %s, %d cmds\n", knowncmds[slot-2],
|
printf("after: %s %s %s %s %s, %d cmds\n", knowncmds[slot-2],
|
||||||
|
Loading…
Reference in New Issue
Block a user