mirror of
https://github.com/systemd/systemd.git
synced 2024-11-08 11:27:32 +03:00
util: fix handling of empty files in read_one_line_file()
https://bugs.freedesktop.org/show_bug.cgi?id=45362
This commit is contained in:
parent
89f134406a
commit
4099a281bb
15
src/util.c
15
src/util.c
@ -705,15 +705,22 @@ int read_one_line_file(const char *fn, char **line) {
|
|||||||
assert(fn);
|
assert(fn);
|
||||||
assert(line);
|
assert(line);
|
||||||
|
|
||||||
if (!(f = fopen(fn, "re")))
|
f = fopen(fn, "re");
|
||||||
|
if (!f)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
if (!(fgets(t, sizeof(t), f))) {
|
if (!fgets(t, sizeof(t), f)) {
|
||||||
r = feof(f) ? -EIO : -errno;
|
|
||||||
|
if (ferror(f)) {
|
||||||
|
r = -errno;
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(c = strdup(t))) {
|
t[0] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
c = strdup(t);
|
||||||
|
if (!c) {
|
||||||
r = -ENOMEM;
|
r = -ENOMEM;
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user