]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
pe-binary: fix array overrun
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 18 Feb 2025 18:09:38 +0000 (03:09 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 3 Mar 2025 20:18:15 +0000 (05:18 +0900)
This is a kind of paranoia, as memeqzero() does not read anyting if
length is zero. But, strictly speaking C language does not allow such,
and Coverity warn about that.

Fixes CID#1561177.

src/shared/pe-binary.c

index d754ac1aa5fbe170e6e2615c9608bdf46b33dd99..6bfc4868aecd5808216ac3e28796daf2adf6a7ef 100644 (file)
@@ -58,7 +58,7 @@ const IMAGE_SECTION_HEADER* pe_section_table_find(
 
         FOREACH_ARRAY(section, sections, n_sections)
                 if (memcmp(section->Name, name, n) == 0 &&
-                    memeqzero(section->Name + n, sizeof(section->Name) - n))
+                    (n == sizeof(sections[0].Name) || memeqzero(section->Name + n, sizeof(section->Name) - n)))
                         return section;
 
         return NULL;