Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.openwrt.org/project/libubox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetr Štetiar <ynezz@true.cz>2020-01-18 20:32:55 +0300
committerPetr Štetiar <ynezz@true.cz>2020-01-20 18:54:10 +0300
commit5c0faaf4f5e26180dcc31b7e8558d57426d84085 (patch)
tree332940834d2e8ec9a8e9ac219db908d9188b2834 /tests/test-blob-parse.c
parent1ffa41535369f5bb67d1eb5bdcb306671ca1d2e4 (diff)
tests: prefer dynamically allocated buffers
Help detecting Valgrind OOB reads and other issues. Conditional jump or move depends on uninitialised value(s) at 0x5452886: blobmsg_parse (blobmsg.c:203) by 0x400A8E: test_blobmsg (tests/test-blobmsg-parse.c:66) by 0x400A8E: main (tests/test-blobmsg-parse.c:82) Conditional jump or move depends on uninitialised value(s) at 0x545247F: blobmsg_check_name (blobmsg.c:39) by 0x545247F: blobmsg_check_attr_len (blobmsg.c:79) by 0x5452710: blobmsg_parse_array (blobmsg.c:159) by 0x400AB8: test_blobmsg (tests/test-blobmsg-parse.c:69) by 0x400AB8: main (tests/test-blobmsg-parse.c:82) Conditional jump or move depends on uninitialised value(s) at 0x54524A0: blobmsg_check_name (blobmsg.c:42) by 0x54524A0: blobmsg_check_attr_len (blobmsg.c:79) by 0x5452710: blobmsg_parse_array (blobmsg.c:159) by 0x400AB8: test_blobmsg (tests/test-blobmsg-parse.c:69) by 0x400AB8: main (tests/test-blobmsg-parse.c:82) Ref: http://lists.infradead.org/pipermail/openwrt-devel/2020-January/021204.html Signed-off-by: Petr Štetiar <ynezz@true.cz>
Diffstat (limited to 'tests/test-blob-parse.c')
-rw-r--r--tests/test-blob-parse.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/tests/test-blob-parse.c b/tests/test-blob-parse.c
index 6d65eb4..5f58201 100644
--- a/tests/test-blob-parse.c
+++ b/tests/test-blob-parse.c
@@ -68,7 +68,7 @@ static int cert_load(const char *certfile, struct list_head *chain)
struct blob_attr *certtb[CERT_ATTR_MAX];
struct blob_attr *bufpt;
struct cert_object *cobj;
- char filebuf[CERT_BUF_LEN];
+ char *filebuf = NULL;
int ret = 0, pret = 0;
size_t len, pos = 0;
@@ -76,14 +76,22 @@ static int cert_load(const char *certfile, struct list_head *chain)
if (!f)
return 1;
- len = fread(&filebuf, 1, CERT_BUF_LEN - 1, f);
- if (len < 64)
+ filebuf = malloc(CERT_BUF_LEN+1);
+ if (!filebuf)
return 1;
+ len = fread(filebuf, 1, CERT_BUF_LEN, f);
+ if (len < 64) {
+ free(filebuf);
+ return 1;
+ }
+
ret = ferror(f) || !feof(f);
fclose(f);
- if (ret)
+ if (ret) {
+ free(filebuf);
return 1;
+ }
bufpt = (struct blob_attr *)filebuf;
do {
@@ -112,6 +120,7 @@ static int cert_load(const char *certfile, struct list_head *chain)
/* repeat parsing while there is still enough remaining data in buffer */
} while(len > pos + sizeof(struct blob_attr) && (bufpt = blob_next(bufpt)));
+ free(filebuf);
return (ret <= 0);
}