Bug 1218949

Summary: GCC 14: grub2 package fails - malloc(sizeof(_pointer_))
Product: [openSUSE] openSUSE Tumbleweed Reporter: Michal Jireš <michal.jires>
Component: BootloaderAssignee: Michael Chang <mchang>
Status: RESOLVED FIXED QA Contact: E-mail List <qa-bugs>
Severity: Normal    
Priority: P5 - None CC: bootloader-maintainers, gery.schneider, hector.oron, mchang, mcowley, mjambor
Version: Current   
Target Milestone: ---   
Hardware: Other   
OS: Other   
See Also: https://bugzilla.linux.ibm.com/show_bug.cgi?id=205032
Whiteboard:
Found By: --- Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---

Description Michal Jireš 2024-01-18 13:52:27 UTC
Building grub2 with GCC 14 discovered several incorrect mallocs (using sizeof pointer, instead of the struct):
https://build.opensuse.org/package/live_build_log/devel:gcc:next:testing/grub2/devel_gcc_next_openSUSE_Tumbleweed/x86_64

[   73s] In file included from ../grub-core/osdep/ofpath.c:2:
[   73s] ../grub-core/osdep/linux/ofpath.c: In function 'of_find_fc_host':
[   73s] ../grub-core/osdep/linux/ofpath.c:427:22: error: allocation of insufficient size '8' for type 'struct ofpath_files_list_root' with size '16' [-Werror=alloc-size]
[   73s]   427 |   portnames_file_list=malloc(sizeof(portnames_file_list));
[   73s]       |                      ^
[   73s] ../grub-core/osdep/linux/ofpath.c: In function 'of_path_of_nvme':
[   73s] ../grub-core/osdep/linux/ofpath.c:589:21: error: allocation of insufficient size '8' for type 'struct ofpath_nvmeof_info' with size '32' [-Werror=alloc-size]
[   73s]   589 |         nvmeof_info = malloc(sizeof(nvmeof_info));
[   73s]       |                     ^
[   73s] ../grub-core/osdep/linux/ofpath.c:618:21: error: allocation of insufficient size '8' for type 'struct ofpath_nvmeof_info' with size '32' [-Werror=alloc-size]
[   73s]   618 |         nvmeof_info = malloc(sizeof(nvmeof_info));
[   73s]       |                     ^

All these mallocs come from:
0002-ieee1275-ofpath-enable-NVMeoF-logical-device-transla.patch

Fix should be simple:
-        nvmeof_info = malloc(sizeof(nvmeof_info));
+        nvmeof_info = malloc(sizeof(*nvmeof_info));
Comment 5 Géry Schneider 2024-01-29 15:14:27 UTC
Hello SUSE,
I have mirrored this bug to IBM LTC Bug 205032.
The IBM team update about it will show up here.
Thank you for your support.
Comment 6 Michael Chang 2024-02-06 07:29:41 UTC
The fix has been submitted to factory.

https://build.opensuse.org/request/show/1144467/changes
Comment 8 LTC BugProxy 2024-02-07 08:41:10 UTC
------- Comment From AVNISH.CHOUHAN@ibm.com 2024-02-07 03:35 EDT-------
Hi Michael,

We have done refinements on the NVMeOF patch series and sent to upstream "https://lists.gnu.org/archive/html/grub-devel/2023-05/msg00024.html". Waiting for review comments and acceptance of this NVMeOF patch series upstream.

Thank you,
Avnish Chouhan
Comment 13 Michael Chang 2024-02-26 04:27:55 UTC
(In reply to LTC BugProxy from comment #8)
> ------- Comment From AVNISH.CHOUHAN@ibm.com 2024-02-07 03:35 EDT-------
> Hi Michael,
> 
> We have done refinements on the NVMeOF patch series and sent to upstream
> "https://lists.gnu.org/archive/html/grub-devel/2023-05/msg00024.html".
> Waiting for review comments and acceptance of this NVMeOF patch series
> upstream.
> 
> Thank you,
> Avnish Chouhan

We have marked this bug report as closed, as the patch addressing the issue with $subject has been successfully submitted to openSUSE. Should there be a need to incorporate the PPC NVMEoF patch into the latest upstream version, please feel free to open a new bug report. Your feedback and contributions are always welcome.