aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-01-24 23:40:45 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-02-09 22:13:18 +0100
commit24b0e6277b36c46075e2e23896aa9ec43729efab (patch)
treeaee635ca55a8b59f1551734eb93dac6a3a7239fa /lib
parent4233a39933277b0d715d59d72942a8fd65bcec4a (diff)
mtd-utils: Fix some simple cases of uninitialized value reads
This patch modifies the internal helpers to read and parse integers from sysfs files by initializing them first and removes turns an obscure "a = open(...) if (a >= 0) {...} if (a == -1) {...}" inside recv_image into a more straight forward if/else branch. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib')
-rw-r--r--lib/libmtd.c2
-rw-r--r--lib/libubi.c1
2 files changed, 3 insertions, 0 deletions
diff --git a/lib/libmtd.c b/lib/libmtd.c
index 564e5c0..9d8d0e8 100644
--- a/lib/libmtd.c
+++ b/lib/libmtd.c
@@ -217,6 +217,7 @@ static int read_hex_ll(const char *file, long long *value)
}
buf[rd] = '\0';
+ *value = 0;
if (sscanf(buf, "%llx\n", value) != 1) {
errmsg("cannot read integer from \"%s\"\n", file);
errno = EINVAL;
@@ -269,6 +270,7 @@ static int read_pos_ll(const char *file, long long *value)
goto out_error;
}
+ *value = 0;
if (sscanf(buf, "%lld\n", value) != 1) {
errmsg("cannot read integer from \"%s\"\n", file);
errno = EINVAL;
diff --git a/lib/libubi.c b/lib/libubi.c
index 4322a19..aaeeb38 100644
--- a/lib/libubi.c
+++ b/lib/libubi.c
@@ -94,6 +94,7 @@ static int read_positive_ll(const char *file, long long *value)
}
buf[rd] = '\0';
+ *value = 0;
if (sscanf(buf, "%lld\n", value) != 1) {
errmsg("cannot read integer from \"%s\"\n", file);
errno = EINVAL;