Project

General

Profile

Actions

Bug #15487

open

smbios: storing the address of local variable

Added by Toomas Soome 3 months ago. Updated 3 months ago.

Status:
In Progress
Priority:
Normal
Assignee:
Category:
kernel
Start date:
Due date:
% Done:

90%

Estimated time:
Difficulty:
Medium
Tags:
Gerrit CR:
External Bug:

Description

Error from build with gcc 12:

    ../../../common/smbios/smb_info.c: In function 'smbios_info_extmemdevice':
    ../../../common/smbios/smb_info.c:1562:27: error: storing the address of local variable 'exmd' in '*emdp.smbmdeve_cs' [-Werror=dangling-pointer=]
     1562 |         emdp->smbmdeve_cs = exmd.smbmdeve_cs;
          |         ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
    ../../../common/smbios/smb_info.c:1548:29: note: 'exmd' declared here
     1548 |         smb_memdevice_ext_t exmd;
          |                             ^~~~
    ../../../common/smbios/smb_info.c:1548:29: note: 'emdp' declared here
    cc1: all warnings being treated as errors

The issue is that smb_memdevice_ext_t does does define struct, which last entry is array with unspecified size, and therefore we can not just copy data blindly to/from it, without taking care of handling the memory allocation.

To fix this, I did convert struct smb_memdevice_ext to use flexible array for last entry, this will allow us to use sizeof() to get size of structure without flexible array. Then we allocate buffer space for array, fill it with data and return to caller. This also means, we need to take care of releasing this buffer space.

Testing done: build. Since this structure is used for Sun OEM memory, there is probably little chance to test with real hardware.

Actions

Also available in: Atom PDF