cp_getvar: force a limit to a string entered

Issue a warning, truncate the string
This commit is contained in:
Holger Vogt 2020-02-07 22:42:45 +01:00
parent 01dda37f96
commit 2ef62c934d
1 changed files with 5 additions and 5 deletions

View File

@ -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. */
char *s = cp_unquote(v->va_string);
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);
break;
}