1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-22 17:35:59 +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:
Zdenek Kabelac 2015-11-08 17:15:24 +01:00
parent 80c3fb786c
commit fa1d730847
2 changed files with 4 additions and 10 deletions

View File

@ -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.

View File

@ -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,16 +485,10 @@ 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);
goto out;
}
fp = fopen(path, "r");
if (!fp) {
log_sys_error("fopen", path); log_sys_error("fopen", path);
goto out; goto out;
} }