erofs-utils: lib: fix missing NULL checks after strdup() in tarerofs_parse_tar_header()
PATCH 1/1 erofs-utils: lib: fix missing NULL checks after strdup() in tarerofs_parse_tar_header()
strdup() calls for eh.path and eh.link had no NULL check. On memory allocation failure, eh.path or eh.link would silently become NULL and get dereferenced later, causing a crash.
Add NULL checks after each strdup() call and return -ENOMEM via the existing 'out' cleanup label on failure.
Signed-off-by Utkal Singh <[email protected]>
--- lib/tar.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
lib/tar.c +12 -2
@@ -719,10 +719,20 @@ int tarerofs_parse_tar(struct erofs_importer *im, struct erofs_tarfile *tar)int ckksum, ret, rem, j; root->dev = tar->dev; -if (eh.path) +if (eh.path) { eh.path =strdup (eh.path); -if (eh.link) +if (!eh.path) { + ret = -ENOMEM ; + goto out; + } + } +if (eh.link) { eh.link =strdup (eh.link); +if (!eh.link) { + ret = -ENOMEM ; + goto out; + } + }init_list_head (&eh.xattrs); restart:
Signature · 1 line
2.43.0