ngx_http_js_challenge_module icon indicating copy to clipboard operation
ngx_http_js_challenge_module copied to clipboard

Build errors with GCC 4.8.5

Open w796933 opened this issue 5 years ago • 43 comments
trafficstars

sir make error . -o objs/addon/ngx_http_js_challenge_module/ngx_http_js_challenge.o
/root/ngx_http_js_challenge_module//ngx_http_js_challenge.c /root/ngx_http_js_challenge_module//ngx_http_js_challenge.c: In function ‘get_challenge_string’: /root/ngx_http_js_challenge_module//ngx_http_js_challenge.c:261:5: error: implicit declaration of function ‘SHA1’ [-Werror=implicit-function-declaration] SHA1((unsigned char *) buf, (size_t) (sizeof(int32_t) + addr.len + secret.len), md); ^~~~ cc1: all warnings being treated as errors objs/Makefile:1203: recipe for target 'objs/addon/ngx_http_js_challenge_module/ngx_http_js_challenge.o' failed make[1]: *** [objs/addon/ngx_http_js_challenge_module/ngx_http_js_challenge.o] Error 1 make[1]: Leaving directory '/root/nginx-1.16.1' Makefile:8: recipe for target 'build' failed make: *** [build] Error 2

w796933 avatar Mar 24 '20 02:03 w796933

Hi, can you give me the output of nginx -V please?

simon987 avatar Mar 24 '20 13:03 simon987

before error , i fix 。 but not this error

w796933 avatar Mar 24 '20 13:03 w796933

/root/ngx_http_js_challenge_module/ngx_http_js_challenge.c: In function ‘get_cookie’: /root/ngx_http_js_challenge_module/ngx_http_js_challenge.c:306:5: error: ‘for’ loop initial declarations are only allowed in C99 mode for (ngx_uint_t i = 0; i < r->headers_in.cookies.nelts; i++) {

how to use c99 mode make ?

w796933 avatar Mar 24 '20 13:03 w796933

this error is fix
just add

CFLAGS=-std=c99

To the top of your makefile, or you can make the code compliant with C90 (as LukeN suggests.)

w796933 avatar Mar 24 '20 13:03 w796933

I modified the build script with the CFLAGS=-std=c99 variable, thank you

simon987 avatar Mar 24 '20 14:03 simon987

use c99 mode i have make no pass

[root@nginx-test nginx-1.16.1]# gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper Target: x86_64-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux Thread model: posix gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)

[root@nginx-test nginx-1.16.1]# ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module --with-openssl=openssl-1.1.1d --add-module=/root/ngx_http_js_challenge_module

/root/ngx_http_js_challenge_module/ngx_http_js_challenge.c: In function ‘ngx_http_js_challenge_handler’: src/core/ngx_string.h:40:57: error: expected expression before ‘)’ token #define ngx_string(str) { sizeof(str) - 1, (u_char *) str } ^ /root/ngx_http_js_challenge_module/ngx_http_js_challenge.c:344:43: note: in expansion of macro ‘ngx_string’ int ret = get_cookie(r, &((ngx_str_t) ngx_string("res")), &response); ^ src/core/ngx_string.h:40:56: error: invalid operands to binary * (have ‘struct ngx_command_t *’ and ‘struct ngx_command_t *’) #define ngx_string(str) { sizeof(str) - 1, (u_char *) str } ^ /root/ngx_http_js_challenge_module/ngx_http_js_challenge.c:344:43: note: in expansion of macro ‘ngx_string’ int ret = get_cookie(r, &((ngx_str_t) ngx_string("res")), &response); ^ src/core/ngx_string.h:40:57: warning: initialization from incompatible pointer type [enabled by default] #define ngx_string(str) { sizeof(str) - 1, (u_char *) str } ^ /root/ngx_http_js_challenge_module/ngx_http_js_challenge.c:344:43: note: in expansion of macro ‘ngx_string’ int ret = get_cookie(r, &((ngx_str_t) ngx_string("res")), &response); ^ src/core/ngx_string.h:40:57: warning: (near initialization for ‘(anonymous).data’) [enabled by default] #define ngx_string(str) { sizeof(str) - 1, (u_char *) str } ^ /root/ngx_http_js_challenge_module/ngx_http_js_challenge.c:344:43: note: in expansion of macro ‘ngx_string’ int ret = get_cookie(r, &((ngx_str_t) ngx_string("res")), &response); ^ src/core/ngx_string.h:40:57: warning: passing argument 2 of ‘get_cookie’ from incompatible pointer type [enabled by default] #define ngx_string(str) { sizeof(str) - 1, (u_char *) str } ^ /root/ngx_http_js_challenge_module/ngx_http_js_challenge.c:344:43: note: in expansion of macro ‘ngx_string’ int ret = get_cookie(r, &((ngx_str_t) ngx_string("res")), &response); ^ /root/ngx_http_js_challenge_module/ngx_http_js_challenge.c:301:5: note: expected ‘struct ngx_str_t ’ but argument is of type ‘struct ngx_command_t ()[1]’ int get_cookie(ngx_http_request_t *r, ngx_str_t *name, ngx_str_t *value) { ^ make[1]: *** [objs/addon/ngx_http_js_challenge_module/ngx_http_js_challenge.o] Error 1 make[1]: Leaving directory `/usr/local/src/nginx-1.16.1' make: *** [build] Error 2

w796933 avatar Mar 24 '20 14:03 w796933

@w796933 please let me know if you can build with the latest commit

simon987 avatar Mar 24 '20 14:03 simon987

yes . latest commit build

w796933 avatar Mar 24 '20 14:03 w796933

/root/ngx_http_js_challenge_module//ngx_http_js_challenge.c:54:17: error: initializer element is not constant str_js_challenge, ^ /root/ngx_http_js_challenge_module//ngx_http_js_challenge.c:54:17: error: (near initialization for ‘ngx_http_js_challenge_commands[0].name’) /root/ngx_http_js_challenge_module//ngx_http_js_challenge.c:62:17: error: initializer element is not constant str_js_challenge_bucket_duration, ^ /root/ngx_http_js_challenge_module//ngx_http_js_challenge.c:62:17: error: (near initialization for ‘ngx_http_js_challenge_commands[1].name’) /root/ngx_http_js_challenge_module//ngx_http_js_challenge.c:70:17: error: initializer element is not constant str_js_challenge_bucket_duration, ^ /root/ngx_http_js_challenge_module//ngx_http_js_challenge.c:70:17: error: (near initialization for ‘ngx_http_js_challenge_commands[2].name’) /root/ngx_http_js_challenge_module//ngx_http_js_challenge.c:78:17: error: initializer element is not constant str_js_challenge_html, ^ /root/ngx_http_js_challenge_module//ngx_http_js_challenge.c:78:17: error: (near initialization for ‘ngx_http_js_challenge_commands[3].name’) /root/ngx_http_js_challenge_module//ngx_http_js_challenge.c:86:17: error: initializer element is not constant str_js_challenge_title, ^ /root/ngx_http_js_challenge_module//ngx_http_js_challenge.c:86:17: error: (near initialization for ‘ngx_http_js_challenge_commands[4].name’) /root/ngx_http_js_challenge_module//ngx_http_js_challenge.c: In function ‘get_cookie’: /root/ngx_http_js_challenge_module//ngx_http_js_challenge.c:303:5: error: ‘for’ loop initial declarations are only allowed in C99 mode for (ngx_uint_t i = 0; i < r->headers_in.cookies.nelts; i++) { ^ /root/ngx_http_js_challenge_module//ngx_http_js_challenge.c:303:5: note: use option -std=c99 or -std=gnu99 to compile your code /root/ngx_http_js_challenge_module//ngx_http_js_challenge.c: At top level: /root/ngx_http_js_challenge_module//ngx_http_js_challenge.c:47:18: error: ‘str_js_challenge_secret’ defined but not used [-Werror=unused-variable] static ngx_str_t str_js_challenge_secret = ngx_string("js_challenge_secret"); ^ cc1: all warnings being treated as errors make[1]: *** [objs/addon/ngx_http_js_challenge_module/ngx_http_js_challenge.o] Error 1 make[1]: Leaving directory `/usr/local/src/nginx-1.16.1' make: *** [modules] Error 2 [root@nginx-test ngx_http_js_challenge_module]# cat build.sh #!/bin/bash

if [ -z ${NGINX_PATH+x} ]; then echo "Please set the NGINX_PATH variable"; exit fi

MODULE_PATH=$(pwd)/ CONFIG_ARGS=$(nginx -V 2>&1 | tail -n 1 | cut -c 21- | sed 's/--add-dynamic-module=.*//g') CONFIG_ARGS="${CONFIG_ARGS} --add-dynamic-module=${MODULE_PATH}" echo $CONFIG_ARGS

( cd ${NGINX_PATH} || exit bash -c "./configure ${CONFIG_ARGS}" CFLAGS=-std=c99 make modules -j "$(nproc)" )

w796933 avatar Mar 24 '20 14:03 w796933

Sorry about that, can you try again with the latest commit? I can't really test it myself because I don't have the same GCC version

simon987 avatar Mar 24 '20 14:03 simon987

my build os is centos 7 64bit

you build os is ?

i try other os build it .

w796933 avatar Mar 24 '20 15:03 w796933

I am building it with Debian testing (Debian 5.4.19-1 (2020-02-13) x86_64 GNU/Linux)

simon987 avatar Mar 24 '20 15:03 simon987

Debian 5.4.19-1 is to old os .

w796933 avatar Mar 24 '20 15:03 w796933

5.4.19-1 is the kernel version, I am using "bullseye" (Debian 11)

simon987 avatar Mar 24 '20 15:03 simon987

okay . i test debian 11 . so thanks .

w796933 avatar Mar 24 '20 15:03 w796933

I made the code C90 compatible, with the last commit, you should no longer see the C99 errors. @w796933 Please let me know if this works

simon987 avatar Mar 24 '20 15:03 simon987

okay . i test it . how can auto drop JavaScript challenge no pass ip address .

w796933 avatar Mar 24 '20 15:03 w796933

how can auto drop JavaScript challenge no pass ip address .

Can you reformulate the question? I don't understand what you mean at all

simon987 avatar Mar 24 '20 15:03 simon987

js verification failed attack IP. How to automatically block access ? how to use iptables auto drop access ?

w796933 avatar Mar 24 '20 15:03 w796933

  how to use iptables auto drop access ?

I'm not sure, you would need to ask someone who is more experienced than me with iptables.

simon987 avatar Mar 24 '20 17:03 simon987

i use debian 11 run build.sh this error .

make -f objs/Makefile modules make[1]: Entering directory '/root/nginx-1.16.1' cc -c -fPIC -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs -I src/http -I src/http/modules
-o objs/addon/ngx_http_js_challenge_module/ngx_http_js_challenge.o
/root/ngx_http_js_challenge_module//ngx_http_js_challenge.c /root/ngx_http_js_challenge_module//ngx_http_js_challenge.c: In function ‘get_challenge_string’: /root/ngx_http_js_challenge_module//ngx_http_js_challenge.c:253:5: error: implicit declaration of function ‘SHA1’ [-Werror=implicit-function-declaration] SHA1((unsigned char *) buf, (size_t) (sizeof(int32_t) + addr.len + secret.len), md); ^~~~ cc1: all warnings being treated as errors make[1]: *** [objs/Makefile:1219: objs/addon/ngx_http_js_challenge_module/ngx_http_js_challenge.o] Error 1 make[1]: Leaving directory '/root/nginx-1.16.1' make: *** [Makefile:14: modules] Error 2

w796933 avatar Mar 25 '20 13:03 w796933

@w796933 please let me know if you still have this error after the last commit

simon987 avatar Mar 28 '20 14:03 simon987

use last commit the some error .

make -f objs/Makefile modules make[1]: Entering directory '/root/nginx-1.16.1' cc -c -fPIC -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs -I src/http -I src/http/modules
-o objs/addon/ngx_http_js_challenge_module/ngx_http_js_challenge.o
/root/ngx_http_js_challenge_module//ngx_http_js_challenge.c /root/ngx_http_js_challenge_module//ngx_http_js_challenge.c: In function ‘verify_response’: /root/ngx_http_js_challenge_module//ngx_http_js_challenge.c:287:5: error: implicit declaration of function ‘SHA1’ [-Werror=implicit-function-declaration] SHA1((unsigned char *) response.data, response.len, md); ^~~~ cc1: all warnings being treated as errors make[1]: *** [objs/Makefile:1219: objs/addon/ngx_http_js_challenge_module/ngx_http_js_challenge.o] Error 1 make[1]: Leaving directory '/root/nginx-1.16.1' make: *** [Makefile:14: modules] Error 2

w796933 avatar Mar 29 '20 14:03 w796933

Sorry about that. Can you retry with the latest commit?

simon987 avatar May 08 '20 00:05 simon987

sir . how to add white ip or url or ua ?

w796933 avatar May 19 '20 05:05 w796933

how to add white ip or url or ua ?

You can do that with basic nginx configuration, this is out of the scope of this project

simon987 avatar May 19 '20 20:05 simon987

i mean how to add white ip or url or ua . because if enabled js challenge module , will deny app load . and deny search engines to crawl.

w796933 avatar May 20 '20 12:05 w796933

The compilation has been unsuccessful, what versions of gcc and openssl?

w796933 avatar May 20 '20 13:05 w796933

The compilation has been unsuccessful

Please send the logs

what versions of gcc and openssl?

It should work with any recent version of GCC. OpenSSL is not required

simon987 avatar May 20 '20 21:05 simon987

cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs -I src/http -I src/http/modules
-o objs/addon/ngx_http_js_challenge_module/ngx_http_js_challenge.o
/root/ngx_http_js_challenge_module//ngx_http_js_challenge.c /root/ngx_http_js_challenge_module//ngx_http_js_challenge.c: In function 'verify_response': /root/ngx_http_js_challenge_module//ngx_http_js_challenge.c:285:5: error: implicit declaration of function 'SHA1' [-Werror=implicit-function-declaration] SHA1((unsigned char *) response.data, response.len, md); ^~~~ cc1: all warnings being treated as errors make[1]: *** [objs/Makefile:1203: objs/addon/ngx_http_js_challenge_module/ngx_http_js_challenge.o] Error 1 make[1]: Leaving directory '/root/nginx-1.16.1' make: *** [Makefile:8: build] Error 2

w796933 avatar May 20 '20 23:05 w796933