Corrected pathname buffer size handling in the dpp utility.

This resolves CID 66412 (Buffer not null terminated).
Note, however, that BUFSIZ should probably be PATH_MAX instead.
This commit is contained in:
Arto Bendiken 2014-10-14 22:13:13 +00:00
parent e13c07bd4a
commit ba3d8d907d

View file

@ -904,7 +904,8 @@ main(int argc, char **argv)
strcpy(filename, "-"); strcpy(filename, "-");
} else { } else {
in = fopen(argv[1],"r"); in = fopen(argv[1],"r");
strncpy(filename, argv[1], BUFSIZ); strncpy(filename, argv[1], BUFSIZ-1);
filename[BUFSIZ-1] = '\0';
} }
#ifdef _MSC_VER #ifdef _MSC_VER
/* Convert all backslashes in filename into slashes, /* Convert all backslashes in filename into slashes,
@ -916,10 +917,11 @@ main(int argc, char **argv)
#endif #endif
if (argc < 3 || !strcmp(argv[2],"-")) { if (argc < 3 || !strcmp(argv[2],"-")) {
out = stdout; out = stdout;
strncpy(outfile, "-", BUFSIZ); strcpy(outfile, "-");
} else { } else {
out = fopen(argv[2],"w"); out = fopen(argv[2],"w");
strncpy(outfile, argv[2], BUFSIZ); strncpy(outfile, argv[2], BUFSIZ-1);
outfile[BUFSIZ-1] = '\0';
} }
if (in == NULL) if (in == NULL)
error("can't open input file"); error("can't open input file");