linux-audit / audit-userspace

Linux audit userspace repository
GNU General Public License v2.0
567 stars 201 forks source link

Fails to compile with musl via zig #358

Open RossComputerGuy opened 4 months ago

RossComputerGuy commented 4 months ago

Zig has a C compiler which wraps around clang and sets all warnings as errors. libaudit builds correctly for glibc but fails with musl.

/home/ross/.cache/zig/p/1220c5a736dd635e70e3132d5e87f8c7ec22626c4b98a6c00672c3d55448653a0993/auparse/interpret.c:263:27: error: passing 'const char *' to parameter of type 'const unsigned char *' converts between pointers to integer types where one is of the unique plain 'char' type and the other is not
   return need_tty_escape(s, len);
                          ^
/home/ross/.cache/zig/p/1220c5a736dd635e70e3132d5e87f8c7ec22626c4b98a6c00672c3d55448653a0993/auparse/interpret.c:159:58: note: passing argument to parameter 's' here
static unsigned int need_tty_escape(const unsigned char *s, unsigned int len)
                                                         ^
/home/ross/.cache/zig/p/1220c5a736dd635e70e3132d5e87f8c7ec22626c4b98a6c00672c3d55448653a0993/auparse/interpret.c:267:35: error: passing 'const char *' to parameter of type 'const unsigned char *' converts between pointers to integer types where one is of the unique plain 'char' type and the other is not
   return need_shell_quote_escape(s, len);
                                  ^
/home/ross/.cache/zig/p/1220c5a736dd635e70e3132d5e87f8c7ec22626c4b98a6c00672c3d55448653a0993/auparse/interpret.c:221:66: note: passing argument to parameter 's' here
static unsigned int need_shell_quote_escape(const unsigned char *s,
                                                                 ^
/home/ross/.cache/zig/p/1220c5a736dd635e70e3132d5e87f8c7ec22626c4b98a6c00672c3d55448653a0993/auparse/interpret.c:1000:18: error: call to undeclared function 'rawmemchr'; ISO C99 and later do not support implicit function declarations
  while ((ptr  = STRCHR(ptr, '\0'))) {
                 ^
/home/ross/.cache/zig/p/1220c5a736dd635e70e3132d5e87f8c7ec22626c4b98a6c00672c3d55448653a0993/auparse/interpret.c:985:16: note: expanded from macro 'STRCHR'
#define STRCHR rawmemchr
               ^
/home/ross/.cache/zig/p/1220c5a736dd635e70e3132d5e87f8c7ec22626c4b98a6c00672c3d55448653a0993/auparse/interpret.c:1000:16: error: incompatible integer to pointer conversion assigning to 'char *' from 'int'
  while ((ptr  = STRCHR(ptr, '\0'))) {
               ^~~~~~~~~~~~~~~~~~~
/home/ross/.cache/zig/p/1220c5a736dd635e70e3132d5e87f8c7ec22626c4b98a6c00672c3d55448653a0993/auparse/interpret.c:3042:14: error: passing 'const unsigned char *' to parameter of type 'const char *' converts between pointers to integer types where one is of the unique plain 'char' type and the other is not
  p = strchr(nk, '\0');
             ^
/nix/store/jxwqqh36xbhk31262zxvlssciv184xn2-zig-0.12.0-dev.e461c3a/lib/zig/libc/include/generic-musl/string.h:45:27: note: passing argument to parameter here
char *strchr (const char *, int);
                          ^
/home/ross/.cache/zig/p/1220c5a736dd635e70e3132d5e87f8c7ec22626c4b98a6c00672c3d55448653a0993/auparse/interpret.c:3042:5: error: assigning to 'const unsigned char *' from 'char *' converts between pointers to integer types where one is of the unique plain 'char' type and the other is not
  p = strchr(nk, '\0');
    ^~~~~~~~~~~~~~~~~~
/home/ross/.cache/zig/p/1220c5a736dd635e70e3132d5e87f8c7ec22626c4b98a6c00672c3d55448653a0993/auparse/interpret.c:3046:11: error: returning 'const unsigned char *' from a function with result type 'const char *' converts between pointers to integer types where one is of the unique plain 'char' type and the other is not
   return p + 1;
          ^~~~~
/home/ross/.cache/zig/p/1220c5a736dd635e70e3132d5e87f8c7ec22626c4b98a6c00672c3d55448653a0993/auparse/interpret.c:3048:15: error: passing 'const unsigned char *' to parameter of type 'const char *' converts between pointers to integer types where one is of the unique plain 'char' type and the other is not
  nk = strchr(p + 1, '\0') + 1;
              ^~~~~
/nix/store/jxwqqh36xbhk31262zxvlssciv184xn2-zig-0.12.0-dev.e461c3a/lib/zig/libc/include/generic-musl/string.h:45:27: note: passing argument to parameter here
char *strchr (const char *, int);
                          ^
/home/ross/.cache/zig/p/1220c5a736dd635e70e3132d5e87f8c7ec22626c4b98a6c00672c3d55448653a0993/auparse/interpret.c:3048:6: error: assigning to 'const unsigned char *' from 'char *' converts between pointers to integer types where one is of the unique plain 'char' type and the other is not
  nk = strchr(p + 1, '\0') + 1;
     ^~~~~~~~~~~~~~~~~~~~~~~~~
/home/ross/.cache/zig/p/1220c5a736dd635e70e3132d5e87f8c7ec22626c4b98a6c00672c3d55448653a0993/auparse/interpret.c:3061:7: error: assigning to 'unsigned char *' from 'char *' converts between pointers to integer types where one is of the unique plain 'char' type and the other is not
 data = au_unescape((char *)raw_data);
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
stevegrubb commented 4 months ago

There are a number of signed/unsigned conversions throughout the audit package. A number of these come from the i686 days. At this point, I no longer test 32 bit and would be afraid to make changes that may impact i686. While it's no longer a priority, I still don't want to knowingly break it.

The error around rawmemchr is somewhat concerning. It is inside an ifdef that configure tested to say it exists for the installed C library. For glibc, this also requires passing _GNU_SOURCE as a CFLAG which Makefile.am does. I suspect the ifdef was actually created for people using musl. Maybe config.h is not 100% right as I think we've met at the libcap-ng repo.