Skip to contentSkip to conversation

ffsX-utils: Fix integer overflow in jffs2dump.c

PATCH In review Anton Moryakov 2 participants 2 messages Dec 14, 2024 – Dec 16, 2024 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ffsX-utils: Fix integer overflow in jffs2dump.c

Report of the static analyzer:
Pointer 'path', returned from function 'xstrdup' at jffs2reader.c:690, may be NULL and is dereferenced at jffs2reader.c:692.

Corrections explained:
After calling xstrdup(p), a path == NULL check has been added. This prevents a possible NULL pointer dereference in the event of a memory allocation error.

Triggers found by static analyzer Svace.

---
 jffsX-utils/jffs2reader.c | 5 +++++
 1 file changed, 5 insertions(+)
jffsX-utils/jffs2reader.c +5 -0
index 87a2167..f776466 100644
@@ -694,6 +694,11 @@ static struct jffs2_raw_dirent *resolvepath0(char *o, size_t size, uint32_t ino,
 
 	pp = path = xstrdup(p);
 
+	if(path == NULL){
+		*inos = 0;
+		return NULL;
+	}
+
 	if (*path == '/') {
 		path++;
 		ino = 1;
Signature · 6 lines
2.30.2


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
#1 lore raw
Quoted 19 lines · Anton Moryakov

Report of the static analyzer:
Pointer 'path', returned from function 'xstrdup' at jffs2reader.c:690, may be NULL and is dereferenced at jffs2reader.c:692.

Corrections explained:
After calling xstrdup(p), a path == NULL check has been added. This prevents a possible NULL pointer dereference in the event of a memory allocation error.

Triggers found by static analyzer Svace.

---
  jffsX-utils/jffs2reader.c | 5 +++++
  1 file changed, 5 insertions(+)
jffsX-utils/jffs2reader.c +0 -0
index 87a2167..f776466 100644

jffsX-utils/jffs2reader.c static struct jffs2_raw_dirent *resolvepath0(char *o, size_t size, uint32_t ino, · line 701

Quoted 8 lines
jffsX-utils/jffs2reader.c +5 -0
@@ -694,6 +694,11 @@ static struct jffs2_raw_dirent *resolvepath0(char *o, size_t size, uint32_t ino,
 
  	pp = path = xstrdup(p);
 
+	if(path == NULL){
+		*inos = 0;
+		return NULL;
+	}
+

Hi Anton, please do some manual analysis before sending these patches scanned by static analyzer. According to the realization of 'xstrdup()', the program will exit if a failure memory allcation occurs.

jffsX-utils/jffs2reader.c static struct jffs2_raw_dirent *resolvepath0(char *o, size_t size, uint32_t ino, · line 704

Quoted 4 lines
jffsX-utils/jffs2reader.c +0 -0
  	if (*path == '/') {
  		path++;
  		ino = 1;

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/