Avoid buffer overrun when identifies or filenames are extremely long.
OpenBSD revisions: C.c 1.4-1.5, ctags.c 1.5, fortran.c 1.3, lisp.c 1.3, tree.c 1.2 Obtained from: OpenBSD
This commit is contained in:
parent
fe71224650
commit
e58bac2e7f
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=97574
@ -239,6 +239,10 @@ c_entries()
|
||||
sp = tok;
|
||||
}
|
||||
else if (sp != tok || begtoken(c)) {
|
||||
if (sp == tok + sizeof tok - 1)
|
||||
/* Too long -- truncate it */
|
||||
*sp = EOS;
|
||||
else
|
||||
*sp++ = c;
|
||||
token = YES;
|
||||
}
|
||||
@ -337,6 +341,10 @@ hash_entry()
|
||||
return;
|
||||
if (iswhite(c))
|
||||
break;
|
||||
if (sp == tok + sizeof tok - 1)
|
||||
/* Too long -- truncate it */
|
||||
*sp = EOS;
|
||||
else
|
||||
*sp++ = c;
|
||||
}
|
||||
*sp = EOS;
|
||||
@ -349,6 +357,10 @@ hash_entry()
|
||||
break;
|
||||
}
|
||||
for (sp = tok;;) { /* get next token */
|
||||
if (sp == tok + sizeof tok - 1)
|
||||
/* Too long -- truncate it */
|
||||
*sp = EOS;
|
||||
else
|
||||
*sp++ = c;
|
||||
if (GETC(==, EOF))
|
||||
return;
|
||||
@ -391,6 +403,10 @@ str_entry(c)
|
||||
if (c == '{') /* it was "struct {" */
|
||||
return (YES);
|
||||
for (sp = tok;;) { /* get next token */
|
||||
if (sp == tok + sizeof tok - 1)
|
||||
/* Too long -- truncate it */
|
||||
*sp = EOS;
|
||||
else
|
||||
*sp++ = c;
|
||||
if (GETC(==, EOF))
|
||||
return (NO);
|
||||
|
@ -95,7 +95,7 @@ main(argc, argv)
|
||||
int exit_val; /* exit value */
|
||||
int step; /* step through args */
|
||||
int ch; /* getopts char */
|
||||
char cmd[100]; /* too ugly to explain */
|
||||
char *cmd;
|
||||
|
||||
aflag = uflag = NO;
|
||||
while ((ch = getopt(argc, argv, "BFadf:tuwvx")) != -1)
|
||||
@ -157,11 +157,14 @@ main(argc, argv)
|
||||
else {
|
||||
if (uflag) {
|
||||
for (step = 0; step < argc; step++) {
|
||||
(void)sprintf(cmd,
|
||||
(void)asprintf(&cmd,
|
||||
"mv %s OTAGS; fgrep -v '\t%s\t' OTAGS >%s; rm OTAGS",
|
||||
outfile, argv[step],
|
||||
outfile);
|
||||
outfile, argv[step], outfile);
|
||||
if (cmd == NULL)
|
||||
err(1, "out of space");
|
||||
system(cmd);
|
||||
free(cmd);
|
||||
cmd = NULL;
|
||||
}
|
||||
++aflag;
|
||||
}
|
||||
@ -170,9 +173,13 @@ main(argc, argv)
|
||||
put_entries(head);
|
||||
(void)fclose(outf);
|
||||
if (uflag) {
|
||||
(void)sprintf(cmd, "sort -o %s %s",
|
||||
(void)asprintf(&cmd, "sort -o %s %s",
|
||||
outfile, outfile);
|
||||
if (cmd == NULL)
|
||||
err(1, "out of space");
|
||||
system(cmd);
|
||||
free(cmd);
|
||||
cmd = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ PF_funcs()
|
||||
if ((cp = lbp + 1))
|
||||
continue;
|
||||
*cp = EOS;
|
||||
(void)strcpy(tok, lbp);
|
||||
(void)strlcpy(tok, lbp, sizeof(tok)); /* possible trunc */
|
||||
getline(); /* process line for ex(1) */
|
||||
pfnote(tok, lineno);
|
||||
pfcnt = YES;
|
||||
|
@ -101,7 +101,7 @@ l_entries()
|
||||
continue;
|
||||
savedc = *cp;
|
||||
*cp = EOS;
|
||||
(void)strcpy(tok, lbp);
|
||||
(void)strlcpy(tok, lbp, sizeof(tok)); /* possible trunc */
|
||||
*cp = savedc;
|
||||
getline();
|
||||
pfnote(tok, lineno);
|
||||
|
@ -78,7 +78,7 @@ pfnote(name, ln)
|
||||
fp = curfile;
|
||||
else
|
||||
++fp;
|
||||
(void)sprintf(nbuf, "M%s", fp);
|
||||
(void)snprintf(nbuf, sizeof(nbuf), "M%s", fp);
|
||||
fp = strrchr(nbuf, '.');
|
||||
if (fp && !fp[2])
|
||||
*fp = EOS;
|
||||
|
Loading…
Reference in New Issue
Block a user