mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
dmsetup: check for strncpy
Test whether device name fits into a given buffer.
This commit is contained in:
parent
a81a2406f1
commit
58734d2538
@ -3244,20 +3244,19 @@ static char *parse_loop_device_name(const char *dev, const char *dev_dir)
|
||||
device[strlen(dev_dir)] != '/')
|
||||
goto error;
|
||||
|
||||
strncpy(buf, strrchr(device, '/') + 1, PATH_MAX - 1);
|
||||
buf[PATH_MAX - 1] = '\0';
|
||||
if (!dm_strncpy(buf, strrchr(device, '/') + 1, PATH_MAX))
|
||||
goto error;
|
||||
dm_free(device);
|
||||
|
||||
} else {
|
||||
/* check for device number */
|
||||
if (!strncmp(dev, "loop", strlen("loop")))
|
||||
strncpy(buf, dev, (size_t) PATH_MAX);
|
||||
else
|
||||
if (strncmp(dev, "loop", sizeof("loop") - 1))
|
||||
goto error;
|
||||
|
||||
if (!dm_strncpy(buf, dev, PATH_MAX))
|
||||
goto error;
|
||||
}
|
||||
|
||||
return buf;
|
||||
|
||||
error:
|
||||
dm_free(device);
|
||||
dm_free(buf);
|
||||
|
Loading…
Reference in New Issue
Block a user