1
0
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:
Zdenek Kabelac 2012-02-10 18:34:12 +01:00
parent a81a2406f1
commit 58734d2538

View File

@ -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);