corazawaf / libcoraza

OWASP Coraza C connector
Other
18 stars 7 forks source link

error installing libcoraza #38

Closed Zerorigin closed 2 months ago

Zerorigin commented 8 months ago

I want to test coraza for nginx and for this I am trying to compile and install libcoraza on Alpine Linux 3.19.1.

# docker run -it alpine:latest ash
# uname -a
Linux ba4017be8bd2 6.6.14-0-lts #1-Alpine SMP PREEMPT_DYNAMIC Fri, 26 Jan 2024 11:08:07 +0000 x86_64 Linux

apk update && apk add \
    autoconf automake build-base libtool make \
    gawk mawk nawk \
    clang17-dev musl-dev \
    go

cd /tmp
git clone --depth 1 https://github.com/corazawaf/libcoraza libcoraza
cd libcoraza
go get -u github.com/corazawaf/coraza/v3@9184eeebf038decac73bf81616374c0932eb2ba7
go mod vendor && go mod tidy
# ./build.sh & output info:
./build.sh

libtoolize: putting auxiliary files in '.'.
libtoolize: copying file './ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'macros'.
libtoolize: copying file 'macros/libtool.m4'
libtoolize: copying file 'macros/ltoptions.m4'
libtoolize: copying file 'macros/ltsugar.m4'
libtoolize: copying file 'macros/ltversion.m4'
libtoolize: copying file 'macros/lt~obsolete.m4'
configure.ac:25: installing './ar-lib'
configure.ac:23: installing './compile'
configure.ac:36: installing './config.guess'
configure.ac:36: installing './config.sub'
configure.ac:13: installing './install-sh'
configure.ac:13: installing './missing'
Makefile.am: installing './depcomp'
# ./configure & output info:
./configure

checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a race-free mkdir -p... ./install-sh -c -d
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether make supports nested variables... (cached) yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether the compiler supports GNU C... yes
checking whether gcc accepts -g... yes
checking for gcc option to enable C11 features... none needed
checking whether gcc understands -c and -o together... yes
checking whether make supports the include directive... yes (GNU style)
checking dependency style of gcc... gcc3
checking how to run the C preprocessor... gcc -E
checking for ar... ar
checking the archiver (ar) interface... ar
checking whether make sets $(MAKE)... (cached) yes
checking for go... true
./configure: line 4873: PKG_PROG_PKG_CONFIG: not found
checking build system type... x86_64-pc-linux-musl
checking host system type... x86_64-pc-linux-musl
checking how to print strings... printf
checking for a sed that does not truncate output... /bin/sed
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for fgrep... /bin/grep -F
checking for ld used by gcc... /usr/x86_64-alpine-linux-musl/bin/ld
checking if the linker (/usr/x86_64-alpine-linux-musl/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 98304
checking how to convert x86_64-pc-linux-musl file names to x86_64-pc-linux-musl format... func_convert_file_noop
checking how to convert x86_64-pc-linux-musl file names to toolchain format... func_convert_file_noop
checking for /usr/x86_64-alpine-linux-musl/bin/ld option to reload object files... -r
checking for file... file
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for archiver @FILE support... @
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for sysroot... no
checking for a working dd... /bin/dd
checking how to truncate binary pipes... /bin/dd bs=4096 count=1
checking for mt... no
checking if : is a manifest tool... no
checking for stdio.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for strings.h... yes
checking for sys/stat.h... yes
checking for sys/types.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC -DPIC
checking if gcc PIC flag -fPIC -DPIC works... yes
checking if gcc static flag -static works... yes
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/usr/x86_64-alpine-linux-musl/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating Doxyfile
config.status: creating config.h
config.status: executing depfiles commands
config.status: executing libtool commands
----------------------------------------------------------------------

 libcoraza Version UNKNOWN configuration:

 OS Type        Linux
 Prefix         /usr/local
 Preprocessor   gcc -E
 C Compiler     gcc -g -O2
 Go Version     go1.21.8

-----------------------------------------------------------------------
# ./configure | grep no & output info
./configure | grep no

checking whether we are cross compiling... no
checking for gcc option to enable C11 features... none needed
./configure: line 4873: PKG_PROG_PKG_CONFIG: not found
checking for a sed that does not truncate output... /bin/sed
checking how to convert x86_64-pc-linux-musl file names to x86_64-pc-linux-musl format... func_convert_file_noop
checking how to convert x86_64-pc-linux-musl file names to toolchain format... func_convert_file_noop
checking for dlltool... no
checking for sysroot... no
checking for mt... no
checking if : is a manifest tool... no
checking if gcc supports -fno-rtti -fno-exceptions... no
checking whether -lc should be explicitly linked in... no
# make & ouput info
make

go tool cgo -exportheader coraza/coraza.h libcoraza/coraza.go libcoraza/log.go
go build -buildmode=c-archive -o libcoraza.a libcoraza/coraza.go libcoraza/log.go
go build -buildmode=c-shared -o libcoraza.so libcoraza/coraza.go libcoraza/log.go
make  all-am
make[1]: Entering directory '/tmp/libcoraza'
make[1]: Leaving directory '/tmp/libcoraza'

Configure and make work correctly, but when doing make install I receive the following error:

# make install & output info
make install

make[1]: Entering directory '/tmp/libcoraza'
make[1]: Nothing to be done for 'install-exec-am'.
make  all-am
make[2]: Entering directory '/tmp/libcoraza'
make[2]: Leaving directory '/tmp/libcoraza'
  CC       tests/simple_get.o
tests/simple_get.c: In function 'main':
tests/simple_get.c:26:28: warning: passing argument 2 of 'coraza_set_log_cb' from incompatible pointer type [-Wincompatible-pointer-types]
   26 |     coraza_set_log_cb(waf, logcb);
      |                            ^~~~~
      |                            |
      |                            void (*)(void *, const void *)
In file included from tests/simple_get.c:3:
cgo-gcc-export-header-prolog:89:63: note: expected 'coraza_log_cb' {aka 'void (*)(const void *)'} but argument is of type 'void (*)(void *, const void *)'
  CCLD     tests/simple_get
make  tests/simple_get
make[2]: Entering directory '/tmp/libcoraza'
make[2]: 'tests/simple_get' is up to date.
make[2]: Leaving directory '/tmp/libcoraza'
./tests/simple_get
Starting...
make[1]: *** [Makefile:851: check] Segmentation fault (core dumped)
make[1]: Leaving directory '/tmp/libcoraza'
make: *** [Makefile:702: install-am] Error 2
s3rj1k commented 5 months ago

@Zerorigin It's actually erroring on make check

$ make check
  CC       tests/simple_get.o
tests/simple_get.c: In function ‘main’:
tests/simple_get.c:26:28: error: passing argument 2 of ‘coraza_set_log_cb’ from incompatible pointer type [-Wincompatible-pointer-types]
   26 |     coraza_set_log_cb(waf, logcb);
      |                            ^~~~~
      |                            |
      |                            void (*)(void *, const void *)
In file included from tests/simple_get.c:3:
cgo-gcc-export-header-prolog:89:63: note: expected ‘coraza_log_cb’ {aka ‘void (*)(const void *)’} but argument is of type ‘void (*)(void *, const void *)’
make: *** [Makefile:431: tests/simple_get.o] Error 1