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
path: root/jshn.c
diff options
context:
space:
mode:
authorPetr Štetiar <ynezz@true.cz>2019-11-24 00:48:25 +0300
committerPetr Štetiar <ynezz@true.cz>2019-11-24 15:26:58 +0300
commit8e832a771d3ab6a852cd976a0264271be231c1b4 (patch)
tree0d5a97f75449cd1569350fb27eba5401a43730a0 /jshn.c
parentcb698e35409b898aedbbc3c673a0055dc1520ef6 (diff)
jshn: fix off by one in jshn_parse_file
Fixes following error: Invalid read of size 1 at 0x4C32D04: strlen by 0x5043367: json_tokener_parse_ex by 0x5045316: json_tokener_parse_verbose by 0x504537D: json_tokener_parse by 0x401AB1: jshn_parse (jshn.c:179) by 0x40190D: jshn_parse_file (jshn.c:370) by 0x40190D: main (jshn.c:434) Address 0x5848c4c is 0 bytes after a block of size 1,036 alloc'd at 0x4C2FB0F: malloc by 0x4018E2: jshn_parse_file (jshn.c:357) by 0x4018E2: main (jshn.c:434) Signed-off-by: Petr Štetiar <ynezz@true.cz>
Diffstat (limited to 'jshn.c')
-rw-r--r--jshn.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/jshn.c b/jshn.c
index 9639951..28cfa8d 100644
--- a/jshn.c
+++ b/jshn.c
@@ -354,7 +354,7 @@ static int jshn_parse_file(const char *path)
return 3;
}
- if (!(fbuf = malloc(sb.st_size))) {
+ if (!(fbuf = calloc(1, sb.st_size+1))) {
fprintf(stderr, "Error allocating memory for %s\n", path);
close(fd);
return 3;