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)] != '/')
|
device[strlen(dev_dir)] != '/')
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
strncpy(buf, strrchr(device, '/') + 1, PATH_MAX - 1);
|
if (!dm_strncpy(buf, strrchr(device, '/') + 1, PATH_MAX))
|
||||||
buf[PATH_MAX - 1] = '\0';
|
goto error;
|
||||||
dm_free(device);
|
dm_free(device);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/* check for device number */
|
/* check for device number */
|
||||||
if (!strncmp(dev, "loop", strlen("loop")))
|
if (strncmp(dev, "loop", sizeof("loop") - 1))
|
||||||
strncpy(buf, dev, (size_t) PATH_MAX);
|
goto error;
|
||||||
else
|
|
||||||
|
if (!dm_strncpy(buf, dev, PATH_MAX))
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
dm_free(device);
|
dm_free(device);
|
||||||
dm_free(buf);
|
dm_free(buf);
|
||||||
|
Loading…
Reference in New Issue
Block a user