Avoid buffer overrun in config_parse_str()

The previous implementation only read a prefix from the configuration
file if the configuration value was too long and forgot to terminate the
string with a NUL character.

Return 0 if the string is too long instead.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
This commit is contained in:
Lukas Fleischer 2018-05-26 11:44:30 +02:00
parent bb7381765c
commit 7e5f8ed7bc

View File

@ -162,7 +162,12 @@ static int config_parse_int(int *dest, const char *val)
static int config_parse_str(char *dest, const char *val)
{
strncpy(dest, val, BUFSIZ);
int len = strlen(val);
if (len >= BUFSIZ)
return 0;
memcpy(dest, val, len + 1);
return 1;
}