jshn: fix off by one in jshn_parse_file
[oweals/libubox.git] / jshn.c
diff --git a/jshn.c b/jshn.c
index 963995191a0f16ffd583a81ccb09378e953377dc..28cfa8df7a21c0c7f97258812b3698d2dfc107b9 100644 (file)
--- 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;