Fix possible buffer overflow.

This commit is contained in:
Stephen Williams 2019-11-21 18:48:57 -08:00
parent f147cf9c61
commit b25df08c99
1 changed files with 2 additions and 1 deletions

View File

@ -80,15 +80,16 @@ __inline__ static void draw_module_declarations(ivl_design_t des)
const char*cp = ivl_design_flag(des, "VPI_MODULE_LIST");
while (*cp) {
char buffer[128];
const char*comma = strchr(cp, ',');
if (comma == 0)
comma = cp + strlen(cp);
char*buffer = malloc(comma - cp + 1);
strncpy(buffer, cp, comma-cp);
buffer[comma-cp] = 0;
fprintf(vvp_out, ":vpi_module \"%s\";\n", buffer);
free(buffer);
cp = comma;
if (*cp) cp += 1;