]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
pe-binary: tweak pe_read_section_data() error codes
authorLennart Poettering <lennart@amutable.com>
Fri, 22 May 2026 02:36:15 +0000 (04:36 +0200)
committerLennart Poettering <lennart@amutable.com>
Fri, 22 May 2026 10:26:25 +0000 (12:26 +0200)
Let's return -EBADMSG if the PE headers reference stuff missing in the
file, regardless if that's because the offsets are larger than SSIZE_MAX
or just larger than the file size. We generally use EBADMSG for all
cases we deem the file to not be a conformant PE file, and these two
cases are the same. Hence, let's be systematic here.

src/shared/pe-binary.c

index 2f7764c1393a8fc4c51cdf10155d65d51cf648a4..12abc1f3bf571e226274bef34d769a84a47d6ab3 100644 (file)
@@ -200,7 +200,7 @@ int pe_read_section_data(
 
         size_t n = le32toh(section->VirtualSize);
         if (n > MIN(max_size, (size_t) SSIZE_MAX))
-                return -E2BIG;
+                return -EBADMSG;
 
         _cleanup_free_ void *data = malloc(n+1);
         if (!data)
@@ -210,7 +210,7 @@ int pe_read_section_data(
         if (ss < 0)
                 return -errno;
         if ((size_t) ss != n)
-                return -EIO;
+                return -EBADMSG;
 
         if (ret_size)
                 *ret_size = n;