mirror of
https://github.com/freebsd/freebsd-src
synced 2024-10-15 12:54:27 +00:00
bsdinstall: Replace correct, but fragile, string builder with open_memstream.
The old one triggered a false positive -Warray-bounds from GCC (the compiler assumed len was always 0), but it was also fragile with manually computed lengths paired with strcat vs using a string builder. Differential Revision: https://reviews.freebsd.org/D40658
This commit is contained in:
parent
f5e7330633
commit
f66a8328c3
|
@ -195,23 +195,26 @@ int parse_disk_config(char *input)
|
||||||
int
|
int
|
||||||
scripted_editor(int argc, const char **argv)
|
scripted_editor(int argc, const char **argv)
|
||||||
{
|
{
|
||||||
char *token;
|
FILE *fp;
|
||||||
int i, error = 0, len = 0;
|
char *input, *token;
|
||||||
|
size_t len;
|
||||||
|
int i, error = 0;
|
||||||
|
|
||||||
for (i = 1; i < argc; i++)
|
fp = open_memstream(&input, &len);
|
||||||
len += strlen(argv[i]) + 1;
|
fputs(argv[1], fp);
|
||||||
char inputbuf[len], *input = inputbuf;
|
|
||||||
strcpy(input, argv[1]);
|
|
||||||
for (i = 2; i < argc; i++) {
|
for (i = 2; i < argc; i++) {
|
||||||
strcat(input, " ");
|
fprintf(fp, " %s", argv[i]);
|
||||||
strcat(input, argv[i]);
|
|
||||||
}
|
}
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
while ((token = strsep(&input, ";")) != NULL) {
|
while ((token = strsep(&input, ";")) != NULL) {
|
||||||
error = parse_disk_config(token);
|
error = parse_disk_config(token);
|
||||||
if (error != 0)
|
if (error != 0) {
|
||||||
|
free(input);
|
||||||
return (error);
|
return (error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
free(input);
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue