[GH-ISSUE #96] error: performing pointer subtraction with a null pointer has undefined behavior [-Werror,-Wnull-pointer-subtraction] #72

Closed
opened 2026-03-04 12:18:42 +03:00 by kerem · 3 comments
Owner

Originally created by @jaygooby on GitHub (Jun 16, 2022).
Original GitHub issue: https://github.com/ADD-SP/ngx_waf/issues/96

  • How to trigger this bug?

Building nginx on MacOS 12.3.1 with Xcode gcc Apple clang version 13.1.6 (clang-1316.0.21.2.5), nginx 1.20.1 and ngx_waf current branch.

I downloaded the nginx and ngx_waf sources. Using the current branch of ngx_waf I added cjson and uthash:

cd ngx_waf_current
git clone -b v2.3.0 https://github.com/troydhanson/uthash.git lib/uthash
git clone -b v1.7.15 https://github.com/DaveGamble/cJSON.git lib/cjson 

nginx configures OK, but make generates these errors (and many more that I haven't pasted here for sake of clarity):

-o objs/addon/src/ngx_http_waf_module_config.o \
/tmp/nw/ngx_waf-current/src/ngx_http_waf_module_config.c
/tmp/nw/ngx_waf-current/src/ngx_http_waf_module_config.c:92:25: error: performing pointer subtraction with a null pointer has undefined behavior [-Werror,-Wnull-pointer-subtraction]
p = (ngx_str_t*)utarray_next(array, NULL);
        ^~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/nw/ngx_waf-current/lib/uthash/include/utarray.h:228:73: note: expanded from macro 'utarray_next'
#define utarray_next(a,e) (((e)==NULL) ? utarray_front(a) : (((a)->i != utarray_eltidx(a,e)+1) ? _utarray_eltptr(a,utarray_eltidx(a,e)+1) : NULL))
                                                        ^~~~~~~~~~~~~~~~~~~
/tmp/nw/ngx_waf-current/lib/uthash/include/utarray.h:231:42: note: expanded from macro 'utarray_eltidx'
#define utarray_eltidx(a,e) (((char*)(e) - (a)->d) / (a)->icd.sz)
              ~~~~~~~~~~ ^
/tmp/nw/ngx_waf-current/src/ngx_http_waf_module_config.c:92:25: error: performing pointer subtraction with a null pointer has undefined behavior [-Werror,-Wnull-pointer-subtraction]
p = (ngx_str_t*)utarray_next(array, NULL);
        ^~~~~~~~~~~~~~~~~~~~~~~~~

Which I guess are coming from the uthash library?

  • The version or branch of ngx_waf.
    current

  • Output of nginx -V.

    It doesn't compile, but this is how it was configured:

    LIB_MODSECURITY=/opt/modsecurity ./configure --add-module=/tmp/nw/ngx_waf-current
    

Optional Info

MacOS 12.3.1

  • Whether nginx is running in a virtual environment such as Docker. If it is running in Docker, please provide the image name.

Not running under Docker

Originally created by @jaygooby on GitHub (Jun 16, 2022). Original GitHub issue: https://github.com/ADD-SP/ngx_waf/issues/96 * How to trigger this bug? Building nginx on MacOS 12.3.1 with Xcode gcc `Apple clang version 13.1.6 (clang-1316.0.21.2.5)`, `nginx 1.20.1` and ngx_waf `current` branch. I downloaded the nginx and ngx_waf sources. Using the `current` branch of ngx_waf I added `cjson` and `uthash`: cd ngx_waf_current git clone -b v2.3.0 https://github.com/troydhanson/uthash.git lib/uthash git clone -b v1.7.15 https://github.com/DaveGamble/cJSON.git lib/cjson nginx configures OK, but `make` generates these errors (and many more that I haven't pasted here for sake of clarity): -o objs/addon/src/ngx_http_waf_module_config.o \ /tmp/nw/ngx_waf-current/src/ngx_http_waf_module_config.c /tmp/nw/ngx_waf-current/src/ngx_http_waf_module_config.c:92:25: error: performing pointer subtraction with a null pointer has undefined behavior [-Werror,-Wnull-pointer-subtraction] p = (ngx_str_t*)utarray_next(array, NULL); ^~~~~~~~~~~~~~~~~~~~~~~~~ /tmp/nw/ngx_waf-current/lib/uthash/include/utarray.h:228:73: note: expanded from macro 'utarray_next' #define utarray_next(a,e) (((e)==NULL) ? utarray_front(a) : (((a)->i != utarray_eltidx(a,e)+1) ? _utarray_eltptr(a,utarray_eltidx(a,e)+1) : NULL)) ^~~~~~~~~~~~~~~~~~~ /tmp/nw/ngx_waf-current/lib/uthash/include/utarray.h:231:42: note: expanded from macro 'utarray_eltidx' #define utarray_eltidx(a,e) (((char*)(e) - (a)->d) / (a)->icd.sz) ~~~~~~~~~~ ^ /tmp/nw/ngx_waf-current/src/ngx_http_waf_module_config.c:92:25: error: performing pointer subtraction with a null pointer has undefined behavior [-Werror,-Wnull-pointer-subtraction] p = (ngx_str_t*)utarray_next(array, NULL); ^~~~~~~~~~~~~~~~~~~~~~~~~ Which I guess are coming from the `uthash` library? * The version or branch of `ngx_waf`. `current` * Output of `nginx -V`. It doesn't compile, but this is how it was configured: LIB_MODSECURITY=/opt/modsecurity ./configure --add-module=/tmp/nw/ngx_waf-current ## Optional Info MacOS 12.3.1 * Whether `nginx` is running in a virtual environment such as `Docker`. If it is running in `Docker`, please provide the image name. Not running under Docker
kerem 2026-03-04 12:18:42 +03:00
Author
Owner

@jaygooby commented on GitHub (Jun 16, 2022):

If I remove -Werror from the nginx objs/Makefile then it will compile

<!-- gh-comment-id:1157789972 --> @jaygooby commented on GitHub (Jun 16, 2022): If I remove `-Werror` from the nginx `objs/Makefile` then it will compile
Author
Owner

@ADD-SP commented on GitHub (Jun 27, 2022):

It looks like the compiler's dataflow analysis is behaving differently, not a bug.

<!-- gh-comment-id:1167541292 --> @ADD-SP commented on GitHub (Jun 27, 2022): It looks like the compiler's dataflow analysis is behaving differently, not a bug.
Author
Owner

@stale[bot] commented on GitHub (Jul 4, 2022):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
此 issue 因为最近没有任何活动已经被标记,如果在此之后的一段时间内仍没有任何活动则会被关闭。感谢您对项目的支持。

<!-- gh-comment-id:1173985443 --> @stale[bot] commented on GitHub (Jul 4, 2022): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. 此 issue 因为最近没有任何活动已经被标记,如果在此之后的一段时间内仍没有任何活动则会被关闭。感谢您对项目的支持。
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ngx_waf#72
No description provided.