Browse Source

cp_getvar: force a limit to a string entered

Issue a warning, truncate the string
pre-master-46
Holger Vogt 6 years ago
parent
commit
8639144093
  1. 10
      src/frontend/variable.c

10
src/frontend/variable.c

@ -729,12 +729,12 @@ cp_getvar(char *name, enum cp_types type, void *retval, size_t rsize)
case CP_STRING: { /* Gotta be careful to have room. */ case CP_STRING: { /* Gotta be careful to have room. */
char *s = cp_unquote(v->va_string); char *s = cp_unquote(v->va_string);
cp_wstrip(s); cp_wstrip(s);
if (strlen(s) >= rsize - 1) {
fprintf(stderr, "Internal Error: string length for variable %s is limited to %zu chars\n", v->va_name, rsize);
controlled_exit(EXIT_BAD);
if (strlen(s) > rsize) {
fprintf(stderr, "Warning: string length for variable %s is limited to %zu chars\n", v->va_name, rsize);
/* limit the string length */
s[rsize] = '\0';
} }
else
strcpy((char*) retval, s);
strcpy((char*) retval, s);
tfree(s); tfree(s);
break; break;
} }

Loading…
Cancel
Save