[LTP] [PATCH v2 11/15] ujson: reader: Reject files with zero size
Andrea Cervesato
andrea.cervesato@suse.de
Tue Oct 13 14:02:07 CEST 2026
From: Andrea Cervesato <andrea.cervesato@suse.com>
Empty files and pseudo-files like sysfs or procfs report a size of 0
with lseek(). An empty file is not valid JSON, and reading JSON from
pseudo-files is unsupported. Reject files with zero size in
ujson_reader_load().
Fixes: c50a0e0751c8 ("libs: Vendor ujson library")
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
libs/ujson/ujson_reader.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/libs/ujson/ujson_reader.c b/libs/ujson/ujson_reader.c
index 21425f848..9d17bbf4b 100644
--- a/libs/ujson/ujson_reader.c
+++ b/libs/ujson/ujson_reader.c
@@ -1028,6 +1028,11 @@ ujson_reader *ujson_reader_load(const char *path)
goto err0;
}
+ if (!len) {
+ fprintf(stderr, "File is empty\n");
+ goto err0;
+ }
+
if (lseek(fd, 0, SEEK_SET) == (off_t)-1) {
fprintf(stderr, "lseek() failed\n");
goto err0;
--
2.51.0
More information about the ltp
mailing list