From 2ef62c934d99ad5a3d5a01ac521c1ca9b1802952 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Fri, 7 Feb 2020 22:42:45 +0100 Subject: [PATCH] cp_getvar: force a limit to a string entered Issue a warning, truncate the string --- src/frontend/variable.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/frontend/variable.c b/src/frontend/variable.c index 5883b4c0a..0f0818ef4 100644 --- a/src/frontend/variable.c +++ b/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. */ 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; }