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:
parent
bb7381765c
commit
7e5f8ed7bc
@ -162,7 +162,12 @@ static int config_parse_int(int *dest, const char *val)
|
|||||||
|
|
||||||
static int config_parse_str(char *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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user