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)] != '/') 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);