Bug 1084639 - GCC 8: libX11 build fails
GCC 8: libX11 build fails
Status: RESOLVED FIXED
Classification: openSUSE
Product: openSUSE Tumbleweed
Classification: openSUSE
Component: X.Org
Current
Other Other
: P5 - None : Normal (vote)
: ---
Assigned To: Michal Srb
E-mail List
:
Depends on:
Blocks: 1084649
  Show dependency treegraph
 
Reported: 2018-03-09 10:04 UTC by Martin Liška
Modified: 2018-03-15 11:02 UTC (History)
2 users (show)

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments
Use flexible array member instead of fake size. (2.52 KB, patch)
2018-03-15 08:53 UTC, Michal Srb
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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!