mirror of
https://github.com/pi-hole/dnsmasq.git
synced 2026-04-02 00:18:40 +01:00
Fix crash with empty DHCP SNAME option.
dhcp-option=66, sets the servername to nothing, and causes a segfault at DHCP transaction time. There may be other ways to provoke this, for instance by using an empty filename. The patch make safe_strncpy() even safer, by handing a NULL src argument. Thanks to Jeff Allen for spotting and reporting this.
This commit is contained in:
@@ -327,13 +327,15 @@ void *safe_malloc(size_t size)
|
||||
}
|
||||
|
||||
/* Ensure limited size string is always terminated.
|
||||
* Can be replaced by (void)strlcpy() on some platforms */
|
||||
Can be replaced by (void)strlcpy() on some platforms.
|
||||
src may be NULL in which case we return an empty string. */
|
||||
void safe_strncpy(char *dest, const char *src, size_t size)
|
||||
{
|
||||
if (size != 0)
|
||||
{
|
||||
dest[size-1] = '\0';
|
||||
strncpy(dest, src, size-1);
|
||||
dest[0] = dest[size-1] = '\0';
|
||||
if (src)
|
||||
strncpy(dest, src, size-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user