]> git.ipfire.org Git - thirdparty/openwrt.git/commit
mtd: jffs2: add missing malloc NULL check 23553/head
authorAnna Kiri <bredcorn@gmail.com>
Tue, 26 May 2026 17:25:14 +0000 (19:25 +0200)
committerJonas Jelonek <jelonek.jonas@gmail.com>
Sun, 31 May 2026 21:57:14 +0000 (23:57 +0200)
commitdf26b8723a7237588634c0ac0e7de82f2ead6c5d
tree2b0a0a2c13e6fad0e5c1a0fff8331c1c1300209c
parente13430ef1d4b00d2d37ac47b85e1f0866f5c8b1a
mtd: jffs2: add missing malloc NULL check

In mtd_replace_jffs2(), the return value of malloc(erasesize) is never
checked. If the allocation fails, buf remains NULL and the subsequent
memcpy(buf + ofs, ...) in add_data() will dereference NULL, causing a
segfault.

Add a NULL check and return -1 on allocation failure. Match the
diagnostic message used by the sibling mtd_write_jffs2() so the
out-of-memory cause is visible at the call site.

Signed-off-by: Anna Kiri <bredcorn@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/23553
Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
package/system/mtd/src/jffs2.c