Skip to contentSkip to conversation

ffsX-utils: Fix integer overflow in jffs2reader.c

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

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ffsX-utils: Fix integer overflow in jffs2reader.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 695

Quoted 2 lines
jffsX-utils/jffs2reader.c +0 -0
@@ -694,6 +694,11 @@ static struct jffs2_raw_dirent *resolvepath0(char *o, size_t size, uint32_t ino,
 
  	pp = path = xstrdup(p);

All callers for resolvepath0() make sure that argument 'p' is not NULL, so I think we can keep not to change it.

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

Quoted 10 lines
jffsX-utils/jffs2reader.c +5 -0
+	if(path == NULL){
+		*inos = 0;
+		return NULL;
+	}
+
  	if (*path == '/') {
  		path++;
  		ino = 1;
 

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