lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <656c3b4a-0481-4634-9dd4-19bb9e4cd612@gmail.com>
Date: Fri, 10 May 2024 22:37:22 +0200
From: Mirsad Todorovac <mtodorovac69@...il.com>
To: linux-kselftest@...r.kernel.org
Cc: Jarkko Sakkinen <jarkko@...nel.org>,
 Dave Hansen <dave.hansen@...ux.intel.com>, Shuah Khan <shuah@...nel.org>,
 linux-sgx@...r.kernel.org, linux-kernel@...r.kernel.org,
 Edward Liaw <edliaw@...gle.com>
Subject: [PATCH v1 1/1] selftests/sgx: Fix the implicit declaration of
 asprintf() compiler error

The selftest/sgx/main.c didn't compile with [-Werror=implicit-function-declaration]
[edited]:

make[3]: Entering directory 'tools/testing/selftests/sgx'
gcc -Wall -Werror -g -Itools/testing/selftests/../../../tools/include -fPIC -c main.c \
        -o tools/testing/selftests/sgx/main.o
In file included from main.c:21:
./kselftest_harness.h: In function ‘__run_test’:
./kselftest_harness.h:1169:13: error: implicit declaration of function ‘asprintf’; \
        did you mean ‘vsprintf’? [-Werror=implicit-function-declaration]
 1169 |         if (asprintf(&test_name, "%s%s%s.%s", f->name,
      |             ^~~~~~~~
      |             vsprintf
cc1: all warnings being treated as errors
make[3]: *** [Makefile:36: tools/testing/selftests/sgx/main.o] Error 1

The cause is in the included <stdio.h> on Ubuntu 22.04 LTS:

 19 /*
 20  *      ISO C99 Standard: 7.19 Input/output     <stdio.h>
 21  */
.
.
.
387 #if __GLIBC_USE (LIB_EXT2)
388 /* Write formatted output to a string dynamically allocated with `malloc'.
389    Store the address of the string in *PTR.  */
390 extern int vasprintf (char **__restrict __ptr, const char *__restrict __f,
391                       __gnuc_va_list __arg)
392      __THROWNL __attribute__ ((__format__ (__printf__, 2, 0))) __wur;
393 extern int __asprintf (char **__restrict __ptr,
394                        const char *__restrict __fmt, ...)
395      __THROWNL __attribute__ ((__format__ (__printf__, 2, 3))) __wur;
396 extern int asprintf (char **__restrict __ptr,
397                      const char *__restrict __fmt, ...)
398      __THROWNL __attribute__ ((__format__ (__printf__, 2, 3))) __wur;
399 #endif

__GLIBC_USE (LIB_EXT2) expands into __GLIBC_USE_LIB_EXT2 as defined here:

/usr/include/features.h:186:#define __GLIBC_USE(F)      __GLIBC_USE_ ## F

Now, what is unobvious is that <stdio.h> includes

/usr/include/x86_64-linux-gnu/bits/libc-header-start.h:
------------------------------------------------------
 35 /* ISO/IEC TR 24731-2:2010 defines the __STDC_WANT_LIB_EXT2__
 36    macro.  */
 37 #undef __GLIBC_USE_LIB_EXT2
 38 #if (defined __USE_GNU                                                  \
 39      || (defined __STDC_WANT_LIB_EXT2__ && __STDC_WANT_LIB_EXT2__ > 0))
 40 # define __GLIBC_USE_LIB_EXT2 1
 41 #else
 42 # define __GLIBC_USE_LIB_EXT2 0
 43 #endif

This makes <stdio.h> exclude line 396 and asprintf() prototype from normal
include file processing.

The fix defines __USE_GNU before including <stdio.h> in case it isn't already
defined. After this intervention the module compiles OK.

Converting snprintf() to asprintf() in selftests/kselftest_harness.h:1169
created this new dependency and the implicit declaration broke the compilation.

Fixes: 809216233555 ("selftests/harness: remove use of LINE_MAX")
Cc: Edward Liaw <edliaw@...gle.com>
Cc: Jarkko Sakkinen <jarkko@...nel.org>
Cc: Dave Hansen <dave.hansen@...ux.intel.com>
Cc: Shuah Khan <shuah@...nel.org>
Cc: linux-sgx@...r.kernel.org
Cc: linux-kselftest@...r.kernel.org
Cc: linux-kernel@...r.kernel.org
Signed-off-by: Mirsad Todorovac <mtodorov69@...il.com>
---
 tools/testing/selftests/sgx/main.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/testing/selftests/sgx/main.c b/tools/testing/selftests/sgx/main.c
index 9820b3809c69..f5cb426bd797 100644
--- a/tools/testing/selftests/sgx/main.c
+++ b/tools/testing/selftests/sgx/main.c
@@ -6,6 +6,9 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <stdbool.h>
+#ifndef __USE_GNU
+#define __USE_GNU
+#endif
 #include <stdio.h>
 #include <stdint.h>
 #include <stdlib.h>
-- 
2.34.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ