Bug 13778 - Samba's public ZERO_STRUCT() uses undefined C11 function memset_s()
Summary: Samba's public ZERO_STRUCT() uses undefined C11 function memset_s()
Alias: None
Product: Samba 4.1 and newer
Classification: Unclassified
Component: Build (show other bugs)
Version: 4.10.0rc1
Hardware: All All
: P5 normal (vote)
Target Milestone: ---
Assignee: Karolin Seeger
QA Contact: Samba QA Contact
Depends on:
Reported: 2019-02-06 14:57 UTC by Milan Crha
Modified: 2019-02-22 08:34 UTC (History)
2 users (show)

See Also:

Patch for 4.10 (36.17 KB, patch)
2019-02-15 07:12 UTC, Andreas Schneider
metze: review+

Note You need to log in before you can comment on or make changes to this bug.
Description Milan Crha 2019-02-06 14:57:59 UTC
Moving from downstream bug report:

The mass rebuild of OpenChange [1] shows a failure of the build due to reference
to memset_s() in macros provided by samba. Part of the error message is here [3].

Am I able to do anything about it in the openchange package? Eventually, am I supposed to do anything with it at all? I mean, it feels like a regression, but I do not know whether the memset_s() had been used in those macros before. If the memset_s() requires any special defines being defined, then those should be added by samba headers. 

I tried to move ndr.h include as the first include in the openchange's ndr_mapi.c file, but it didn't help at all [2]. My idea was that maybe something includes string.h before samba has a chance to influence it, but it was not it.

[1] https://koji.fedoraproject.org/koji/taskinfo?taskID=32428399
[2] https://koji.fedoraproject.org/koji/taskinfo?taskID=32531263
[3] Part of the build log from [1]:

Compiling ndr_mapi.c with -fPIC
BUILDSTDERR: In file included from /usr/include/samba-4.0/ndr.h:29,
BUILDSTDERR:                  from /usr/include/samba-4.0/dcerpc.h:32,
BUILDSTDERR:                  from libmapi/libmapi.h:45,
BUILDSTDERR:                  from ndr_mapi.c:22:
BUILDSTDERR: ndr_mapi.c: In function 'ndr_pull_EcDoRpc':
BUILDSTDERR: /usr/include/samba-4.0/util/memory.h:54:24: warning: implicit declaration of function 'memset_s'; did you mean 'memset'? [-Wimplicit-function-declaration]
BUILDSTDERR:    54 | #define ZERO_STRUCT(x) memset_s((char *)&(x), sizeof(x), 0, sizeof(x))
BUILDSTDERR:       |                        ^~~~~~~~
BUILDSTDERR: ndr_mapi.c:924:3: note: in expansion of macro 'ZERO_STRUCT'
BUILDSTDERR:   924 |   ZERO_STRUCT(r->out);
BUILDSTDERR:       |   ^~~~~~~~~~~
BUILDSTDERR: /usr/bin/ld: libmapi-openchange.so.2.3: undefined reference to `memset_s'
BUILDSTDERR: collect2: error: ld returned 1 exit status
BUILDSTDERR: make: *** [Makefile:450: bin/libmapixx-test] Error 1
BUILDSTDERR: error: Bad exit status from /var/tmp/rpm-tmp.aoXFCs (%build)
Comment 1 Andreas Schneider 2019-02-06 15:27:44 UTC
I've pushed a fix to https://gitlab.com/samba-team/samba/merge_requests/238
Comment 2 Stefan Metzmacher 2019-02-06 23:19:22 UTC
(In reply to Andreas Schneider from comment #1)

Can't you just build openchange with -D__STDC_WANT_LIB_EXT1__=1 ?
Comment 3 Andreas Schneider 2019-02-07 07:38:11 UTC
Stefan, memset_s() is C11 and glibc doesn't provide this call (yet). Also the C standard doesn't require to implement memset_s() it is optional which really sucks!

objdump -T /lib64/libc.so.6 | grep memset
00000000000a60d0  w  iD  .text  0000000000000047  GLIBC_2.2.5 wmemset
000000000010bd10 g   iD  .text  0000000000000047  GLIBC_2.4   __wmemset_chk
000000000008b120 g   iD  .text  0000000000000091  GLIBC_2.2.5 memset
000000000010a4c0 g   iD  .text  0000000000000091  GLIBC_2.3.4 __memset_chk
Comment 4 Andreas Schneider 2019-02-15 07:12:42 UTC
Created attachment 14848 [details]
Patch for 4.10
Comment 5 Andreas Schneider 2019-02-15 12:21:07 UTC
Karolin, please add the patch to the 4.10 branch. Thanks!
Comment 6 Karolin Seeger 2019-02-21 11:27:02 UTC
(In reply to Andreas Schneider from comment #5)
Pushed to autobuild-v4-10-test.
Comment 7 Karolin Seeger 2019-02-22 08:34:34 UTC
(In reply to Karolin Seeger from comment #6)
Pushed to v4-10-test.
Closing out bug report.