]> git.ipfire.org Git - thirdparty/openwrt.git/commit
mtd: check malloc() return value in mtd_check() 23705/head
authorAnna Kiri <bredcorn@gmail.com>
Mon, 8 Jun 2026 09:06:32 +0000 (11:06 +0200)
committerJonas Jelonek <jelonek.jonas@gmail.com>
Mon, 8 Jun 2026 14:17:42 +0000 (16:17 +0200)
commit2818ac5ccd0cc7c44176010691929b843b7cb566
tree9838fcb667cb02fb729394e07620b636823c1478
parent2f809f9cff578141def1fd00baf22384afd75c21
mtd: check malloc() return value in mtd_check()

After malloc(erasesize) in mtd_check(), the result was never checked
for NULL. On allocation failure, the buf pointer remained NULL and
would later be used in image_check() via read(imagefd, buf + buflen,
...), causing a NULL pointer dereference.

Add a NULL check after the allocation and return early. The early
return path also closes the just-opened fd and frees the strdup'd
colon-separated device-list copy to avoid leaks.

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