mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-03 05:18:29 +03:00
Fix usage of readlink
Return value of readlink limits valid string size. Characters after returned size present some garbage to printf. Fix it by placing '\0' on the return size value.
This commit is contained in:
parent
2011571bf5
commit
218f657794
@ -1,5 +1,6 @@
|
|||||||
Version 2.02.85 -
|
Version 2.02.85 -
|
||||||
===================================
|
===================================
|
||||||
|
Fix readlink usage inside get_primary_dev().
|
||||||
Use format instance mempool where possible and adequate.
|
Use format instance mempool where possible and adequate.
|
||||||
Call destroy_instance for any PVs found in VG structure during vg_free call.
|
Call destroy_instance for any PVs found in VG structure during vg_free call.
|
||||||
Add new free_pv_fid fn and use it throughout to free all attached fids.
|
Add new free_pv_fid fn and use it throughout to free all attached fids.
|
||||||
|
@ -287,7 +287,7 @@ int get_primary_dev(const char *sysfs_dir,
|
|||||||
struct stat info;
|
struct stat info;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
uint32_t pri_maj, pri_min;
|
uint32_t pri_maj, pri_min;
|
||||||
int ret = 0;
|
int size, ret = 0;
|
||||||
|
|
||||||
/* check if dev is a partition */
|
/* check if dev is a partition */
|
||||||
if (dm_snprintf(path, PATH_MAX, "%s/dev/block/%d:%d/partition",
|
if (dm_snprintf(path, PATH_MAX, "%s/dev/block/%d:%d/partition",
|
||||||
@ -309,11 +309,13 @@ int get_primary_dev(const char *sysfs_dir,
|
|||||||
* - basename ../../block/md0/md0 = md0
|
* - basename ../../block/md0/md0 = md0
|
||||||
* Parent's 'dev' sysfs attribute = /sys/block/md0/dev
|
* Parent's 'dev' sysfs attribute = /sys/block/md0/dev
|
||||||
*/
|
*/
|
||||||
if (readlink(dirname(path), temp_path, PATH_MAX) < 0) {
|
if ((size = readlink(dirname(path), temp_path, PATH_MAX)) < 0) {
|
||||||
log_sys_error("readlink", path);
|
log_sys_error("readlink", path);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
temp_path[size] = '\0';
|
||||||
|
|
||||||
if (dm_snprintf(path, PATH_MAX, "%s/block/%s/dev",
|
if (dm_snprintf(path, PATH_MAX, "%s/block/%s/dev",
|
||||||
sysfs_dir, basename(dirname(temp_path))) < 0) {
|
sysfs_dir, basename(dirname(temp_path))) < 0) {
|
||||||
log_error("dm_snprintf dev failed");
|
log_error("dm_snprintf dev failed");
|
||||||
|
Loading…
Reference in New Issue
Block a user