Bug 1084639

Summary: GCC 8: libX11 build fails
Product: [openSUSE] openSUSE Tumbleweed Reporter: Martin Liška <martin.liska>
Component: X.OrgAssignee: Michal Srb <msrb>
Status: RESOLVED FIXED QA Contact: E-mail List <xorg-maintainer-bugs>
Severity: Normal    
Priority: P5 - None CC: msrb, sndirsch
Version: Current   
Target Milestone: ---   
Hardware: Other   
OS: Other   
Whiteboard:
Found By: --- Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---
Bug Depends on:    
Bug Blocks: 1084649    
Attachments: Use flexible array member instead of fake size.

Description Martin Liška 2018-03-09 10:04:07 UTC
Build the package with GCC 8, there's error:

[  108s] /usr/include/bits/string_fortified.h:90:10: error: '__builtin_strcpy' forming offset 2 is out of the bounds [0, 1] [-Werror=array-bounds]

Please build the project as follows to reproduce the issue:
osc build --alternative-project=openSUSE:Factory:Staging:Gcc7
Comment 1 Michal Srb 2018-03-15 07:56:33 UTC
Confirmed. The full error is:

> In file included from /usr/include/string.h:494,
>                  from /usr/include/X11/Xos.h:62,
>                  from imLcIm.c:42:
> In function 'strcpy',
>     inlined from '_XimWriteCachedDefaultTree' at imLcIm.c:479:5,
>     inlined from '_XimCreateDefaultTree' at imLcIm.c:616:2,
>     inlined from '_XimLocalOpenIM' at imLcIm.c:700:5:
> /usr/include/bits/string_fortified.h:90:10: error: '__builtin_strcpy'
> forming offset 2 is out of the bounds [0, 1] [-Werror=array-bounds]
>    return __builtin___strcpy_chk (__dest, __src, __bos (__dest));

The offending line is:

> imLcIm.c:479:  strcpy (m->fname+strlen(name)+1, encoding);

The `m` is `struct _XimCacheStruct*` and the `fname` field is `char fname[1]`.

So gcc is complaining that we are going to write past this 1-element array. The  allocated memory for `m` is actually big enough to store the full fname plus encoding behind the `_XimCacheStruct` struct, so it works.

No idea why the original author decided that `char fname[1]` is a good way to declare it. I'll change it to something that doesn't trigger the warning.
Comment 2 Michal Srb 2018-03-15 08:53:50 UTC
Created attachment 763761 [details]
Use flexible array member instead of fake size.

Fix for the build error. Also sent to xorg-devel:
https://lists.x.org/archives/xorg-devel/2018-March/056312.html
Comment 3 Stefan Dirsch 2018-03-15 10:55:25 UTC
Thanks, Michal! Could you do a SR for X11:XOrg/libX11, so we can close the bugreport?
Comment 4 Stefan Dirsch 2018-03-15 11:02:53 UTC
(In reply to Stefan Dirsch from comment #3)
> Thanks, Michal! Could you do a SR for X11:XOrg/libX11, so we can close the
> bugreport?

OMG. It was already queued. Thanks!