mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
dev-type: fix TOCTOU order
Doing 'stat' checking first and later opening is racy. And since we do not really care about any 'status' info here and we read 'sysfs' here - just drop whole 'stat()' call and directly handle error from failing 'fopen()'.
This commit is contained in:
parent
80c3fb786c
commit
fa1d730847
@ -1,5 +1,6 @@
|
|||||||
Version 2.02.135 -
|
Version 2.02.135 -
|
||||||
====================================
|
====================================
|
||||||
|
Drop unneeded stat() call when checking for sysfs file.
|
||||||
Fix memory leak on error path of failing thin-pool percentage check.
|
Fix memory leak on error path of failing thin-pool percentage check.
|
||||||
Add missing test for failing node allocation in lvmetad.
|
Add missing test for failing node allocation in lvmetad.
|
||||||
Correct configure messages when enabling/disabling lvmlockd.
|
Correct configure messages when enabling/disabling lvmlockd.
|
||||||
|
@ -462,7 +462,6 @@ int dev_get_primary_dev(struct dev_types *dt, struct device *dev, dev_t *result)
|
|||||||
*result = dev->dev;
|
*result = dev->dev;
|
||||||
ret = 1;
|
ret = 1;
|
||||||
goto out; /* dev is not a partition! */
|
goto out; /* dev is not a partition! */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -486,17 +485,11 @@ int dev_get_primary_dev(struct dev_types *dt, struct device *dev, dev_t *result)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* finally, parse 'dev' attribute and create corresponding dev_t */
|
/* finally, parse 'dev' attribute and create corresponding dev_t */
|
||||||
if (stat(path, &info) == -1) {
|
if (!(fp = fopen(path, "r"))) {
|
||||||
if (errno == ENOENT)
|
if (errno == ENOENT)
|
||||||
log_error("sysfs file %s does not exist", path);
|
log_error("sysfs file %s does not exist.", path);
|
||||||
else
|
else
|
||||||
log_sys_error("stat", path);
|
log_sys_error("fopen", path);
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
fp = fopen(path, "r");
|
|
||||||
if (!fp) {
|
|
||||||
log_sys_error("fopen", path);
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user