Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with POST's #10

Closed
gummiboll opened this issue Sep 7, 2017 · 6 comments
Closed

Problem with POST's #10

gummiboll opened this issue Sep 7, 2017 · 6 comments
Assignees

Comments

@gummiboll
Copy link

Did a vanilla nginx/unit/php7/wordpress install on a fresh Ubuntu Xenial and noticed that I couldn't log in to wp-admin or post comments. Seems like $_POST doesn't get populated[1]?

Not sure if its a known issue, if it is you can just go ahead and close this. :)

[1]:
Did a simple test to verify:

test.php: <?php print_r($_POST); ?>

$ curl --data "foo=bar" http://host/test.php

Array
(
)
@mar0x mar0x self-assigned this Sep 7, 2017
@fblr fblr closed this as completed in d87a4fb Sep 7, 2017
@vladkras
Copy link

So, what was wrong? I'm expiriencing same problem. NGINX Unit is installed from latest source from this repo (0.4 so far) and no proxies are used

@VBart
Copy link
Contributor

VBart commented Jan 12, 2018

@vladkras that was broken recently and fixed again in b09227f. Have you checked this revision?

@vladkras
Copy link

vladkras commented Jan 12, 2018

Yes, I'm using latest master (and I checked this file too). This what I've got in log with
curl -v --data 'foo=bar' 127.0.0.1:8300

2018/01/12 13:11:59.332 [debug] 2490#2491 epoll_wait(12): 1
2018/01/12 13:11:59.332 [debug] 2490#2493 epoll_wait(16): 1
2018/01/12 13:11:59.332 [debug] 2490#2492 epoll_wait(14): 1
2018/01/12 13:11:59.332 [debug] 2490#2494 epoll_wait(18): 1
2018/01/12 13:11:59.332 [debug] 2490#2491 epoll: fd:11 ev:0001 d:561B8C32B680 rd:5 wr:0
2018/01/12 13:11:59.332 [debug] 2490#2493 epoll: fd:11 ev:0001 d:561B8C32DE80 rd:5 wr:0
2018/01/12 13:11:59.332 [debug] 2490#2492 epoll: fd:11 ev:0001 d:561B8C32B4C0 rd:5 wr:0
2018/01/12 13:11:59.332 [debug] 2490#2494 epoll: fd:11 ev:0001 d:561B8C32F360 rd:5 wr:0
2018/01/12 13:11:59.332 [debug] 2490#2491 timer expire minimum: 367409685:281090155
2018/01/12 13:11:59.332 [debug] 2490#2493 timer expire minimum: 367409689:281090155
2018/01/12 13:11:59.332 [debug] 2490#2492 timer expire minimum: 367409685:281090155
2018/01/12 13:11:59.332 [debug] 2490#2494 timer expire minimum: 367409685:281090155
2018/01/12 13:11:59.332 [debug] 2490#2491 work queue: accept
2018/01/12 13:11:59.332 [debug] 2490#2493 work queue: accept
2018/01/12 13:11:59.332 [debug] 2490#2492 work queue: accept
2018/01/12 13:11:59.332 [debug] 2490#2494 work queue: accept
2018/01/12 13:11:59.332 [debug] 2490#2491 accept4(11): 28
2018/01/12 13:11:59.332 [debug] 2490#2493 accept4(11) (11: Resource temporarily unavailable)
2018/01/12 13:11:59.332 [debug] 2490#2492 accept4(11) (11: Resource temporarily unavailable)
2018/01/12 13:11:59.332 [debug] 2490#2491 client: 127.0.0.1
2018/01/12 13:11:59.332 [debug] 2490#2494 accept4(11) (11: Resource temporarily unavailable)
2018/01/12 13:11:59.332 [debug] 2490#2493 epoll_wait(16) timeout:-1
2018/01/12 13:11:59.332 [debug] 2490#2492 epoll_wait(14) timeout:-1
2018/01/12 13:11:59.332 [debug] 2490#2491 malloc(168): 561B8C334940
2018/01/12 13:11:59.332 [debug] 2490#2494 epoll_wait(18) timeout:-1
2018/01/12 13:11:59.332 [debug] 2490#2491 posix_memalign(16, 464): 561B8C32DF80
2018/01/12 13:11:59.332 [debug] 2490#2491 *16 connections: 2
2018/01/12 13:11:59.332 [debug] 2490#2491 work queue: accept
2018/01/12 13:11:59.332 [debug] 2490#2491 accept4(11) (11: Resource temporarily unavailable)
2018/01/12 13:11:59.332 [debug] 2490#2491 work queue: read
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 http conn init
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 conn wait fd:28 rdy:0
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 timer add: 0:0 65000:281155155
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 timer change: 281155155:0
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 epoll 12 set event: fd:28 op:1 ev:80002001
2018/01/12 13:11:59.332 [debug] 2490#2491 timers changes: 1
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 timer rbtree insert: 281155155
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 timer found minimum: 281155155:281090155
2018/01/12 13:11:59.332 [debug] 2490#2491 epoll 12 changes:1
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 epoll_ctl(12): fd:28 op:1 ev:80002001
2018/01/12 13:11:59.332 [debug] 2490#2491 epoll_wait(12) timeout:65000
2018/01/12 13:11:59.332 [debug] 2490#2491 epoll_wait(12): 1
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 epoll: fd:28 ev:0001 d:561B8C2FE0C0 rd:5 wr:0
2018/01/12 13:11:59.332 [debug] 2490#2491 timer expire minimum: 281155155:281090155
2018/01/12 13:11:59.332 [debug] 2490#2491 work queue: accept
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 h1p read header
2018/01/12 13:11:59.332 [debug] 2490#2491 posix_memalign(16, 2160): 561B8C33F020
2018/01/12 13:11:59.332 [debug] 2490#2491 work queue: read
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 conn read fd:28 rdy:1 cl:0
2018/01/12 13:11:59.332 [debug] 2490#2491 recvbuf: 0, 561B8C33F068, 2048
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 recv(28, 561B8C33F068, 2048, 0x0): 154
2018/01/12 13:11:59.332 [debug] 2490#2491 work queue: fast
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 h1p header parse
2018/01/12 13:11:59.332 [debug] 2490#2491 malloc(136): 561B8C32E160
2018/01/12 13:11:59.332 [debug] 2490#2491 posix_memalign(128, 1024): 561B8C335780
2018/01/12 13:11:59.332 [debug] 2490#2491 malloc(168): 561B8C335BC0
2018/01/12 13:11:59.332 [debug] 2490#2491 malloc(136): 561B8C2FE2A0
2018/01/12 13:11:59.332 [debug] 2490#2491 posix_memalign(128, 1024): 561B8C33F900
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 h1p body read 7 te:0
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 h1p body rest: 0
2018/01/12 13:11:59.332 [debug] 2490#2491 work queue: fast
2018/01/12 13:11:59.332 [debug] 2490#2491 posix_memalign(16, 712): 561B8C339D60
2018/01/12 13:11:59.332 [debug] 2490#2491 mp 561B8C335BC0 retain: 2
2018/01/12 13:11:59.332 [debug] 2490#2491 malloc(136): 561B8C2FE340
2018/01/12 13:11:59.332 [debug] 2490#2491 posix_memalign(128, 1024): 561B8C33A080
2018/01/12 13:11:59.332 [debug] 2490#2491 posix_memalign(128, 128): 561B8C2FE400
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 rpc: stream #5 registered
2018/01/12 13:11:59.332 [debug] 2490#2491 pthread_mutex_lock(561B8C2FE760) enter
2018/01/12 13:11:59.332 [debug] 2490#2491 pthread_mutex_unlock(561B8C2FE760) exit
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 already have port for app 'default' 561B8C2FE760 
2018/01/12 13:11:59.332 [debug] 2490#2491 posix_memalign(128, 128): 561B8C33FD80
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 rpc: stream #5 assigned uniq pid 2501 (561B8C32AB88)
2018/01/12 13:11:59.332 [debug] 2490#2491 pthread_mutex_lock(561B8C2FDAA0) enter
2018/01/12 13:11:59.332 [debug] 2490#2491 process port (2490, 1) found
2018/01/12 13:11:59.332 [debug] 2490#2491 pthread_mutex_unlock(561B8C2FDAA0) exit
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 request 6 bytes shm buffer
2018/01/12 13:11:59.332 [debug] 2490#2491 mp 561B8C32A400 retain: 2
2018/01/12 13:11:59.332 [debug] 2490#2491 pthread_mutex_lock(561B8C2FDA68) enter
2018/01/12 13:11:59.332 [debug] 2490#2491 pthread_mutex_unlock(561B8C2FDA68) exit
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 outgoing mmap buf allocation: 561B8C330980 [7F192B668000,16384] 2490->2501,0,0
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 nxt_app_msg_write: 4 POST
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 nxt_app_msg_write: 1 /
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 nxt_app_msg_write: NULL
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 nxt_app_msg_write: 8 HTTP/1.1
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 nxt_app_msg_write: 9 127.0.0.1
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 nxt_app_msg_write: 9 127.0.0.1
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 nxt_app_msg_write: 14 127.0.0.1:8300
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 nxt_app_msg_write: NULL
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 nxt_app_msg_write: 33 application/x-www-form-urlencoded
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 nxt_app_msg_write: 1 7
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 nxt_app_msg_write_raw: 7
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 nxt_app_msg_write: 14 127.0.0.1:8300
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 nxt_app_msg_write: 11 curl/7.57.0
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 nxt_app_msg_write: 3 */*
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 nxt_app_msg_write: 1 7
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 nxt_app_msg_write: 33 application/x-www-form-urlencoded
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 nxt_app_msg_write: NULL
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 about to send 261 bytes buffer to worker port 29
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 request tracking for stream #5
2018/01/12 13:11:59.332 [debug] 2490#2491 pthread_mutex_lock(561B8C2FDA68) enter
2018/01/12 13:11:59.332 [debug] 2490#2491 pthread_mutex_unlock(561B8C2FDA68) exit
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 outgoing tracking allocation: 2490->2501,0,0
2018/01/12 13:11:59.332 [debug] 2490#2491 pthread_mutex_lock(561B8C334C50) enter
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 using mmap mode
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 sendbuf: 0, 7F192B668000, 261
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 prepare 261 bytes message for transfer to process 2501 via shared memory
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 mmap_msg={0, 0, 261} to 2501
2018/01/12 13:11:59.332 [debug] 2490#2491 sendmsg(29, -1, 2): 36
2018/01/12 13:11:59.332 [debug] 2490#2491 pthread_mutex_unlock(561B8C334C50) exit
2018/01/12 13:11:59.332 [debug] 2490#2491 pthread_mutex_lock(561B8C2FE760) enter
2018/01/12 13:11:59.332 [debug] 2501#2501 epoll_wait(3): 1
2018/01/12 13:11:59.332 [debug] 2490#2491 pthread_mutex_unlock(561B8C2FE760) exit
2018/01/12 13:11:59.332 [debug] 2501#2501 epoll: fd:10 ev:0001 d:561B8C2FFC40 rd:5 wr:0
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 app 'default' 561B8C2FE760 requests queue is empty, keep the port
2018/01/12 13:11:59.332 [debug] 2501#2501 timer expire minimum: 367409685:281090155
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 ra stream #5 update peer
2018/01/12 13:11:59.332 [debug] 2501#2501 work queue: fast
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 ra stream #5 release
2018/01/12 13:11:59.332 [debug] 2490#2491 work queue: fast
2018/01/12 13:11:59.332 [debug] 2501#2501 recvmsg(10, -1, 2): 36
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 timer found minimum: 281155155:281090155
2018/01/12 13:11:59.332 [debug] 2501#2501 pthread_mutex_lock(7F192CF361D0) enter
2018/01/12 13:11:59.332 [debug] 2490#2491 epoll_wait(12) timeout:65000
2018/01/12 13:11:59.332 [debug] 2501#2501 pthread_mutex_unlock(7F192CF361D0) exit
2018/01/12 13:11:59.332 [debug] 2501#2501 pthread_mutex_lock(561B8C3D9DB0) enter
2018/01/12 13:11:59.332 [debug] 2501#2501 pthread_mutex_unlock(561B8C3D9DB0) exit
2018/01/12 13:11:59.332 [debug] 2501#2501 tracking for stream #5 received
2018/01/12 13:11:59.332 [debug] 2501#2501 mmap_msg={0, 0, 261} from 2490
2018/01/12 13:11:59.332 [debug] 2501#2501 pthread_mutex_lock(7F192CF361D0) enter
2018/01/12 13:11:59.332 [debug] 2501#2501 pthread_mutex_unlock(7F192CF361D0) exit
2018/01/12 13:11:59.332 [debug] 2501#2501 pthread_mutex_lock(561B8C3D9DB0) enter
2018/01/12 13:11:59.332 [debug] 2501#2501 pthread_mutex_unlock(561B8C3D9DB0) exit
2018/01/12 13:11:59.332 [debug] 2501#2501 mp 561B8C2F8640 retain: 2
2018/01/12 13:11:59.332 [debug] 2501#2501 incoming mmap buf allocation: 561B8C2F8D80 [7F192AA00000,16384] 2490->2501,0,0
2018/01/12 13:11:59.332 [debug] 2501#2501 port 10: message type:12
2018/01/12 13:11:59.332 [debug] 2501#2501 app data: POST�/	HTTP/1.1
127.0.0.1
127.0.0.1127.0.0.1:8300"application/x-www-form-urlencoded�7foo=bar
HTTP_HOST127.0.0.1:8300�HTTP_USER_AGENT
                                       curl/7.57.0
                                                  HTTP_ACCEPT�*/*�HTTP_CONTENT_LENGTH�7�HTTP_CONTENT_TYPE"application/x-www-form-urlencoded ...
2018/01/12 13:11:59.332 [debug] 2501#2501 process port (2490, 1) found
2018/01/12 13:11:59.332 [debug] 2501#2501 nxt_read_str: 4 POST
2018/01/12 13:11:59.332 [debug] 2501#2501 nxt_read_str: 1 /
2018/01/12 13:11:59.332 [debug] 2501#2501 nxt_read_str: NULL
2018/01/12 13:11:59.332 [debug] 2501#2501 nxt_read_size: 0
2018/01/12 13:11:59.332 [debug] 2501#2501 malloc(22): 561B8C2F89A0
2018/01/12 13:11:59.332 [debug] 2501#2501 nxt_read_str: 8 HTTP/1.1
2018/01/12 13:11:59.332 [debug] 2501#2501 nxt_read_str: 9 127.0.0.1
2018/01/12 13:11:59.332 [debug] 2501#2501 nxt_read_str: 9 127.0.0.1
2018/01/12 13:11:59.332 [debug] 2501#2501 nxt_read_str: 14 127.0.0.1:8300
2018/01/12 13:11:59.332 [debug] 2501#2501 nxt_read_str: NULL
2018/01/12 13:11:59.332 [debug] 2501#2501 nxt_read_str: 33 application/x-www-form-urlencoded
2018/01/12 13:11:59.332 [debug] 2501#2501 nxt_read_str: 1 7
2018/01/12 13:11:59.332 [debug] 2501#2501 nxt_read_size: 0
2018/01/12 13:11:59.332 [debug] 2501#2501 nxt_read_size: 7
2018/01/12 13:11:59.332 [debug] 2501#2501 handle.filename = '/app/default/index.php'
2018/01/12 13:11:59.332 [debug] 2501#2501 run script /app/default/index.php
2018/01/12 13:11:59.332 [debug] 2501#2501 nxt_php_read_post 0
2018/01/12 13:11:59.332 [debug] 2501#2501 nxt_php_read_cookies
2018/01/12 13:11:59.332 [debug] 2501#2501 nxt_app_msg_write_raw: 8
2018/01/12 13:11:59.332 [debug] 2501#2501 request 8 bytes shm buffer
2018/01/12 13:11:59.332 [debug] 2501#2501 malloc(136): 561B8C3BDF40
2018/01/12 13:11:59.332 [debug] 2501#2501 posix_memalign(128, 1024): 561B8C3BE000
2018/01/12 13:11:59.332 [debug] 2501#2501 mp 7F192CF36D20 retain: 2
2018/01/12 13:11:59.332 [debug] 2501#2501 pthread_mutex_lock(561B8C3D9DE8) enter
2018/01/12 13:11:59.332 [debug] 2501#2501 pthread_mutex_unlock(561B8C3D9DE8) exit
2018/01/12 13:11:59.332 [debug] 2501#2501 outgoing mmap buf allocation: 561B8C3BE000 [7F1929FFF000,16384] 2501->2490,0,0
2018/01/12 13:11:59.332 [debug] 2501#2501 nxt_app_msg_write_raw: 3
2018/01/12 13:11:59.332 [debug] 2501#2501 nxt_app_msg_write_raw: 2
2018/01/12 13:11:59.332 [debug] 2501#2501 nxt_app_msg_write_raw: 23
2018/01/12 13:11:59.332 [debug] 2501#2501 nxt_app_msg_write_raw: 2
2018/01/12 13:11:59.332 [debug] 2501#2501 nxt_app_msg_write_raw: 38
2018/01/12 13:11:59.332 [debug] 2501#2501 nxt_app_msg_write_raw: 2
2018/01/12 13:11:59.332 [debug] 2501#2501 nxt_app_msg_write_raw: 2
2018/01/12 13:11:59.332 [debug] 2501#2501 pthread_mutex_lock(561B8C2F8810) enter
2018/01/12 13:11:59.332 [debug] 2501#2501 using mmap mode
2018/01/12 13:11:59.332 [debug] 2501#2501 sendbuf: 0, 7F1929FFF000, 80
2018/01/12 13:11:59.332 [debug] 2501#2501 prepare 80 bytes message for transfer to process 2490 via shared memory
2018/01/12 13:11:59.332 [debug] 2501#2501 mmap_msg={0, 0, 80} to 2490
2018/01/12 13:11:59.332 [debug] 2501#2501 sendmsg(8, -1, 2): 28
2018/01/12 13:11:59.332 [debug] 2490#2491 epoll_wait(12): 1
2018/01/12 13:11:59.332 [debug] 2501#2501 pthread_mutex_unlock(561B8C2F8810) exit
2018/01/12 13:11:59.332 [debug] 2490#2491 epoll: fd:20 ev:0001 d:561B8C32A5A0 rd:5 wr:0
2018/01/12 13:11:59.332 [debug] 2501#2501 nxt_app_msg_write_raw: 13
2018/01/12 13:11:59.332 [debug] 2490#2491 timer expire minimum: 281155155:281090155
2018/01/12 13:11:59.332 [debug] 2501#2501 request 13 bytes shm buffer
2018/01/12 13:11:59.332 [debug] 2490#2491 work queue: fast
2018/01/12 13:11:59.332 [debug] 2501#2501 mp 7F192CF36D20 retain: 3
2018/01/12 13:11:59.332 [debug] 2501#2501 pthread_mutex_lock(561B8C3D9DE8) enter
2018/01/12 13:11:59.332 [debug] 2490#2491 recvmsg(20, -1, 2): 28
2018/01/12 13:11:59.332 [debug] 2501#2501 pthread_mutex_unlock(561B8C3D9DE8) exit
2018/01/12 13:11:59.332 [debug] 2490#2491 mmap_msg={0, 0, 80} from 2501
2018/01/12 13:11:59.332 [debug] 2501#2501 outgoing mmap buf allocation: 561B8C3BE080 [7F192A003000,16384] 2501->2490,0,1
2018/01/12 13:11:59.332 [debug] 2490#2491 pthread_mutex_lock(7F192CF361D0) enter
2018/01/12 13:11:59.332 [debug] 2501#2501 pthread_mutex_lock(561B8C2F8810) enter
2018/01/12 13:11:59.332 [debug] 2490#2491 pthread_mutex_unlock(7F192CF361D0) exit
2018/01/12 13:11:59.332 [debug] 2501#2501 using mmap mode
2018/01/12 13:11:59.332 [debug] 2490#2491 pthread_mutex_lock(561B8C2FDA30) enter
2018/01/12 13:11:59.332 [debug] 2501#2501 sendbuf: 0, 7F192A003000, 13
2018/01/12 13:11:59.332 [debug] 2490#2491 pthread_mutex_unlock(561B8C2FDA30) exit
2018/01/12 13:11:59.332 [debug] 2501#2501 prepare 13 bytes message for transfer to process 2490 via shared memory
2018/01/12 13:11:59.332 [debug] 2490#2491 mp 561B8C32A4E0 retain: 2
2018/01/12 13:11:59.332 [debug] 2501#2501 mmap_msg={0, 1, 13} to 2490
2018/01/12 13:11:59.332 [debug] 2490#2491 incoming mmap buf allocation: 561B8C32AA80 [7F192AC67000,16384] 2501->2490,0,0
2018/01/12 13:11:59.332 [debug] 2501#2501 sendmsg(8, -1, 2): 28
2018/01/12 13:11:59.332 [debug] 2490#2491 port 20: message type:12
2018/01/12 13:11:59.332 [debug] 2501#2501 pthread_mutex_unlock(561B8C2F8810) exit
2018/01/12 13:11:59.332 [debug] 2490#2491 rpc: stream #5 handler, type 12
2018/01/12 13:11:59.332 [debug] 2490#2491 router app data (80): Status: 200
X-Powered-By: PHP/7.1.9
Content-type: text/html; charset=UTF-8


2018/01/12 13:11:59.332 [debug] 2490#2491 h1p request header send
2018/01/12 13:11:59.332 [debug] 2490#2491 recvmsg(20, -1, 2): 28
2018/01/12 13:11:59.332 [debug] 2501#2501 pthread_mutex_lock(561B8C2F8810) enter
2018/01/12 13:11:59.332 [debug] 2490#2491 mmap_msg={0, 1, 13} from 2501
2018/01/12 13:11:59.332 [debug] 2501#2501 sendmsg(8, -1, 1): 16
2018/01/12 13:11:59.332 [debug] 2490#2491 pthread_mutex_lock(7F192CF361D0) enter
2018/01/12 13:11:59.332 [debug] 2501#2501 pthread_mutex_unlock(561B8C2F8810) exit
2018/01/12 13:11:59.332 [debug] 2490#2491 pthread_mutex_unlock(7F192CF361D0) exit
2018/01/12 13:11:59.332 [debug] 2501#2501 free(561B8C2F89A0)
2018/01/12 13:11:59.332 [debug] 2490#2491 pthread_mutex_lock(561B8C2FDA30) enter
2018/01/12 13:11:59.332 [debug] 2501#2501 complete buffer 561B8C2F8D80
2018/01/12 13:11:59.332 [debug] 2490#2491 pthread_mutex_unlock(561B8C2FDA30) exit
2018/01/12 13:11:59.332 [debug] 2501#2501 recvmsg(10, -1, 2): -1
2018/01/12 13:11:59.332 [debug] 2490#2491 mp 561B8C32A4E0 retain: 3
2018/01/12 13:11:59.332 [debug] 2501#2501 recvmsg(10) not ready
2018/01/12 13:11:59.332 [debug] 2490#2491 incoming mmap buf allocation: 561B8C32AB00 [7F192AC6B000,16384] 2501->2490,0,1
2018/01/12 13:11:59.332 [debug] 2501#2501 epoll 3 set event: fd:10 op:3 ev:80002001
2018/01/12 13:11:59.332 [debug] 2490#2491 port 20: message type:12
2018/01/12 13:11:59.332 [debug] 2501#2501 work queue: fast
2018/01/12 13:11:59.332 [debug] 2490#2491 rpc: stream #5 handler, type 12
2018/01/12 13:11:59.332 [debug] 2501#2501 mmap buf completion: 561B8C3BE000 [7F1929FFF000,16384] (sent=1), 2501->2490,0,1
2018/01/12 13:11:59.332 [debug] 2490#2491 router app data (13): array(0) {
}

2018/01/12 13:11:59.332 [debug] 2501#2501 mp 7F192CF36D20 release: 2
2018/01/12 13:11:59.332 [debug] 2490#2491 h1p request send
2018/01/12 13:11:59.332 [debug] 2501#2501 work queue: fast
2018/01/12 13:11:59.332 [debug] 2490#2491 recvmsg(20, -1, 2): 16
2018/01/12 13:11:59.332 [debug] 2501#2501 mmap buf completion: 561B8C3BE080 [7F192A003000,16384] (sent=1), 2501->2490,0,2
2018/01/12 13:11:59.332 [debug] 2490#2491 port 20: message type:12
2018/01/12 13:11:59.332 [debug] 2501#2501 free(561B8C3BDF40)
2018/01/12 13:11:59.332 [debug] 2490#2491 free(561B8C2FE400)
2018/01/12 13:11:59.332 [debug] 2501#2501 free(561B8C3BE000)
2018/01/12 13:11:59.332 [debug] 2490#2491 rpc: stream #5 last handler, type 12
2018/01/12 13:11:59.332 [debug] 2501#2501 mp 7F192CF36D20 release: 1
2018/01/12 13:11:59.332 [debug] 2490#2491 last router app data (0): 
2018/01/12 13:11:59.332 [debug] 2501#2501 work queue: fast
2018/01/12 13:11:59.332 [debug] 2490#2491 router data create last buf
2018/01/12 13:11:59.332 [debug] 2501#2501 buf completion: 561B8C3DA300 0
2018/01/12 13:11:59.332 [debug] 2490#2491 pthread_mutex_lock(561B8C2FE760) enter
2018/01/12 13:11:59.332 [debug] 2501#2501 work queue: fast
2018/01/12 13:11:59.332 [debug] 2490#2491 pthread_mutex_unlock(561B8C2FE760) exit
2018/01/12 13:11:59.332 [debug] 2501#2501 mmap buf completion: 561B8C2F8D80 [7F192AA00000,16384] (sent=0), 2490->2501,0,0
2018/01/12 13:11:59.332 [debug] 2490#2491 app 'default' 561B8C2FE760 requests queue is empty, keep the port
2018/01/12 13:11:59.332 [debug] 2501#2501 mp 561B8C2F8640 release: 1
2018/01/12 13:11:59.332 [debug] 2490#2491 failed to cancel tracking for stream #5
2018/01/12 13:11:59.332 [debug] 2501#2501 epoll 3 changes:1
2018/01/12 13:11:59.332 [debug] 2490#2491 mmap buf completion: 561B8C330980 [7F192B668000,16384] (sent=1), 2490->2501,0,1
2018/01/12 13:11:59.332 [debug] 2501#2501 epoll_ctl(3): fd:10 op:3 ev:80002001
2018/01/12 13:11:59.332 [debug] 2490#2491 mp 561B8C32A400 release: 1
2018/01/12 13:11:59.332 [debug] 2501#2501 epoll_wait(3) timeout:-1
2018/01/12 13:11:59.332 [debug] 2490#2491 timer add: 0:0 0:281090155
2018/01/12 13:11:59.332 [debug] 2490#2491 timer change: 281090155:0
2018/01/12 13:11:59.332 [debug] 2490#2491 h1p request send
2018/01/12 13:11:59.332 [debug] 2490#2491 rpc: stream #5 remove first and last pid 2501 registration (561B8C32AB88)
2018/01/12 13:11:59.332 [debug] 2490#2491 free(561B8C33FD80)
2018/01/12 13:11:59.332 [debug] 2490#2491 rpc: stream #5 free registration
2018/01/12 13:11:59.332 [debug] 2490#2491 recvmsg(20, -1, 2): -1
2018/01/12 13:11:59.332 [debug] 2490#2491 recvmsg(20) not ready
2018/01/12 13:11:59.332 [debug] 2490#2491 epoll 12 set event: fd:20 op:3 ev:80002001
2018/01/12 13:11:59.332 [debug] 2490#2491 work queue: fast
2018/01/12 13:11:59.332 [debug] 2490#2491 mmap buf completion: 561B8C32AA80 [7F192AC67000,16384] (sent=0), 2501->2490,0,0
2018/01/12 13:11:59.332 [debug] 2490#2491 mp 561B8C32A4E0 release: 2
2018/01/12 13:11:59.332 [debug] 2490#2491 work queue: fast
2018/01/12 13:11:59.332 [debug] 2490#2491 work queue: write
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 conn write fd:28
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 sendbuf: 0, 561B8C33A1C8, 128
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 sendbuf: 1, 561B8C33FCC8, 5
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 sendbuf: 2, 7F192AC6B000, 13
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 sendbuf: 3, 561B8C33A348, 7
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 writev(28, 4): 153
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 event conn: 153 sent:153
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 timer disable: 0:0
2018/01/12 13:11:59.332 [debug] 2490#2491 work queue: fast
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 h1p sent
2018/01/12 13:11:59.332 [debug] 2490#2491 work queue: fast
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 buf completion: 561B8C33A180 561B8C33A1C8
2018/01/12 13:11:59.332 [debug] 2490#2491 work queue: fast
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 buf completion: 561B8C33FC80 561B8C33FCC8
2018/01/12 13:11:59.332 [debug] 2490#2491 work queue: fast
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 mmap buf completion: 561B8C32AB00 [7F192AC6B000,16384] (sent=0), 2501->2490,0,1
2018/01/12 13:11:59.332 [debug] 2490#2491 mp 561B8C32A4E0 release: 1
2018/01/12 13:11:59.332 [debug] 2490#2491 work queue: fast
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 buf completion: 561B8C33A300 561B8C33A348
2018/01/12 13:11:59.332 [debug] 2490#2491 work queue: fast
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 http request done
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 http request close handler
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 http request log: "127.0.0.1 "POST / HTTP/1.1" 200"
2018/01/12 13:11:59.332 [debug] 2490#2491 mp 561B8C335BC0 release: 1
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 h1p request close
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 h1p keepalive
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 setsockopt(28, 6, TCP_NODELAY): 1
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 conn wait fd:28 rdy:0
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 timer previous: 281155155:2
2018/01/12 13:11:59.332 [debug] 2490#2491 timers changes: 1
2018/01/12 13:11:59.332 [debug] 2490#2491 timer rbtree insert: 281090155
2018/01/12 13:11:59.332 [debug] 2490#2491 timer found minimum: 281090155:281090155
2018/01/12 13:11:59.332 [debug] 2490#2491 epoll 12 changes:1
2018/01/12 13:11:59.332 [debug] 2490#2491 epoll_ctl(12): fd:20 op:3 ev:80002001
2018/01/12 13:11:59.332 [debug] 2490#2491 epoll_wait(12) timeout:0
2018/01/12 13:11:59.332 [debug] 2490#2491 epoll_wait(12): 1
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 epoll: fd:28 ev:2001 d:561B8C2FE0C0 rd:5 wr:0
2018/01/12 13:11:59.332 [debug] 2490#2491 timer expire minimum: 281090155:281090155
2018/01/12 13:11:59.332 [debug] 2490#2491 timer expire delete: 281090155:2
2018/01/12 13:11:59.332 [debug] 2490#2491 work queue: fast
2018/01/12 13:11:59.332 [debug] 2490#2491 http app release
2018/01/12 13:11:59.332 [debug] 2490#2491 mp 561B8C335BC0 release: 0
2018/01/12 13:11:59.332 [debug] 2490#2491 free(561B8C339D60)
2018/01/12 13:11:59.332 [debug] 2490#2491 free(561B8C2FE340)
2018/01/12 13:11:59.332 [debug] 2490#2491 free(561B8C33A080)
2018/01/12 13:11:59.332 [debug] 2490#2491 free(561B8C2FE2A0)
2018/01/12 13:11:59.332 [debug] 2490#2491 free(561B8C33F900)
2018/01/12 13:11:59.332 [debug] 2490#2491 free(561B8C335BC0)
2018/01/12 13:11:59.332 [debug] 2490#2491 work queue: read
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 h1p read header
2018/01/12 13:11:59.332 [debug] 2490#2491 work queue: read
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 conn read fd:28 rdy:1 cl:0
2018/01/12 13:11:59.332 [debug] 2490#2491 recvbuf: 0, 561B8C33F068, 2048
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 recv(28, 561B8C33F068, 2048, 0x0): 0
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 timer disable: 281155155:2
2018/01/12 13:11:59.332 [debug] 2490#2491 work queue: fast
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 h1p conn close
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 h1p close
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 conn close fd:28, to:0
2018/01/12 13:11:59.332 [debug] 2490#2491 work queue: close
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 conn close handler fd:28
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 timer delete: 281155155:0
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 timer change: 0:2
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 epoll 12 set event: fd:28 op:2 ev:0
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 timer add: 0:0 0:281090155
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 timer change: 281090155:0
2018/01/12 13:11:59.332 [debug] 2490#2491 timers changes: 2
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 timer rbtree delete: 281155155:1
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 timer rbtree insert: 281090155
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 timer found minimum: 281090155:281090155
2018/01/12 13:11:59.332 [debug] 2490#2491 epoll 12 changes:1
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 epoll_ctl(12): fd:28 op:2 ev:0
2018/01/12 13:11:59.332 [debug] 2490#2491 epoll_wait(12) timeout:0
2018/01/12 13:11:59.332 [debug] 2490#2491 epoll_wait(12): 0
2018/01/12 13:11:59.332 [debug] 2490#2491 timer expire minimum: 281090155:281090155
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 timer expire delete: 281090155:2
2018/01/12 13:11:59.332 [debug] 2490#2491 work queue: fast
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 conn close timer handler fd:28
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 socket close(28)
2018/01/12 13:11:59.332 [debug] 2490#2491 work queue: fast
2018/01/12 13:11:59.332 [debug] 2490#2491 *14 router conn close done
2018/01/12 13:11:59.332 [debug] 2490#2491 free(561B8C2FE0C0)
2018/01/12 13:11:59.332 [debug] 2490#2491 mp 561B8C2F93C0 release: 0
2018/01/12 13:11:59.332 [debug] 2490#2491 conf joint 561B8C331C00 count: 2
2018/01/12 13:11:59.332 [debug] 2490#2491 free(561B8C32E160)
2018/01/12 13:11:59.332 [debug] 2490#2491 free(561B8C335780)
2018/01/12 13:11:59.332 [debug] 2490#2491 free(561B8C33F020)
2018/01/12 13:11:59.332 [debug] 2490#2491 free(561B8C2F93C0)
2018/01/12 13:11:59.332 [debug] 2490#2491 epoll_wait(12) timeout:-1

as you can see data was recieved but result was empty

array(0) {
}

PS I use:
Alpine Linux 3.7 with Docker https://github.com/vladkras/nginx-unit-php7

@vladkras
Copy link

I added logging to that part

    if (r->body != NULL) {
	nxt_debug(task, "body: %*s\n", 100, r->body);
        ar->r.body.buf = r->body;
        ar->r.body.preread_size = r->content_length_n;
    } else {
    	nxt_debug(task, "no body");	
    }

I'm not sure how to set length correctly but now I see

2018/01/12 15:01:52.454 [debug] 21541#21544 *11 body: @3�u�U��7t�UȊ�u�Uϊ�u�UȊ�u�Uϊ�u�Ufoo=bar

in log. So that patch works but everything else is still like in my previous post.

@VBart
Copy link
Contributor

VBart commented Jan 12, 2018

@vladkras it seems the previous attempt to fix isn't complete, please try the following patch:

--- a/src/nxt_http_request.c    Fri Jan 12 16:37:42 2018 +0300
+++ b/src/nxt_http_request.c    Fri Jan 12 16:39:18 2018 +0300
@@ -221,6 +221,7 @@ nxt_http_app_request(nxt_task_t *task, v
     if (r->body != NULL) {
         ar->r.body.buf = r->body;
         ar->r.body.preread_size = r->content_length_n;
+        ar->r.header.parsed_content_length = r->content_length_n;
     }
 
     ar->r.body.done = 1;

@vladkras
Copy link

vladkras commented Jan 12, 2018

@VBart yes, this line helps

/unit # curl -d 'foo=bar' 127.0.0.1:8300
2018/01/12 15:34:59.757 [debug] 23960#23961 router app data (43): array(1) {
  ["foo"]=>
  string(3) "bar"
}

I'll try to send more data and files too.

nginx-hg-mirror pushed a commit that referenced this issue May 18, 2023
There are a couple of reports on GitHub about issues accessing Python
ASGI based applications over IPv6.

A request over IPv6 would result in an error like

2023/05/13 17:49:12 [alert] 47202#47202 [unit] #10: Python failed to create 'client' pair
2023/05/13 17:49:12 [alert] 47202#47202 [unit] Python failed to call 'loop.call_soon'
ValueError: invalid literal for int() with base 10: 'db8:1:1:1ee7:dead:beef:cafe'

The above error was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib64/python3.11/asyncio/base_events.py", line 765, in call_soon
    handle = self._call_soon(callback, args, context)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/asyncio/base_events.py", line 781, in _call_soon
    handle = events.Handle(callback, args, self, context)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SystemError: <class 'asyncio.events.Handle'> returned a result with an exception set

This issue occurred in the nxt_py_asgi_create_ip_address() function
where it tries to create an IP address / port number pair.

It does this by looking for the first ':' in the address and taking
everything after it as the port number. Like in the above error message,
if we tried to access the server @ 2001:db8:1:1:1ee7:dead:beef:cafe,
then we'd end up with the port number as 'db8:1:1:1ee7:dead:beef:cafe'.

There are two issues with this

 1) The IP address and port number are already flowed through
    separately.
 2) Even if (1) wasn't true, it would still be broken for IPv6 as we'd
    expect to a get an address literal like
    [2001:db8:1:1:1ee7:dead:beef:cafe]:8080, however there was no code to
    handle the []'s.

The fix is to simply not try looking for a port number. We pass a port
number into this function to use in the case where we don't find a port
number, we never will...

A further cleanup would be to flow through the server port number when
creating the 'server pair' PyTuple, rather than just using the hard
coded 80.

Closes: <#793>
Closes: <#874>
Reviewed-by: Alejandro Colomar <[email protected]>
Signed-off-by: Andrew Clayton <[email protected]>
ac000 added a commit to ac000/unit that referenced this issue Nov 8, 2023
If ruby/rack tried to send an empty header, e.g

  app = Proc.new do |env|
      ["200", {
          "Content-Type" => "text/plain",
          "X-Empty-Header" => nil,
      }, ["Hello World\n"]]
  end

  run app

you would get an error like

  2023/10/20 11:24:56 [error] 24829#24829 [unit] nginx#10: Ruby: Wrong header entry 'value' from application
  2023/10/20 11:24:56 [error] 24829#24829 [unit] nginx#10: Ruby: Failed to run ruby script

Empty headers are a thing, so we need to allow the ruby type T_NIL
(along with T_STRING) as a valid header value.

This factors out the setting of value & value_end into a macro as what
these get set to now depends on if we have a T_NIL or a T_STRING and
this prevents an increase in duplicated code.

Signed-off-by: Andrew Clayton <[email protected]>
ac000 added a commit to ac000/unit that referenced this issue Nov 8, 2023
If ruby/rack tried to send an empty header, e.g

  app = Proc.new do |env|
      ["200", {
          "Content-Type" => "text/plain",
          "X-Empty-Header" => nil,
      }, ["Hello World\n"]]
  end

  run app

you would get an error like

  2023/10/20 11:24:56 [error] 24829#24829 [unit] nginx#10: Ruby: Wrong header entry 'value' from application
  2023/10/20 11:24:56 [error] 24829#24829 [unit] nginx#10: Ruby: Failed to run ruby script

Empty headers are a thing, so we need to allow the ruby type T_NIL
(along with T_STRING) as a valid header value.

This factors out the setting of value & value_end into a macro as what
these get set to now depends on if we have a T_NIL or a T_STRING and
this prevents an increase in duplicated code.

Signed-off-by: Andrew Clayton <[email protected]>
andrey-zelenkov added a commit to andrey-zelenkov/unit that referenced this issue Jan 31, 2024
Can be reproduced by test/test_rewrite.py::test_rewrite_njs
with enabled UndefinedBehaviorSanitizer:

src/nxt_http_js.c:169:52: runtime error: applying zero offset to null pointer
    #0 0x10255b044 in nxt_http_js_ext_get_args nxt_http_js.c:169
    nginx#1 0x102598ad0 in njs_value_property njs_value.c:1175
    nginx#2 0x10259c2c8 in njs_vm_object_prop njs_vm.c:1398
    nginx#3 0x102559d74 in nxt_js_call nxt_js.c:445
    nginx#4 0x1023c0da0 in nxt_tstr_query nxt_tstr.c:276
    nginx#5 0x102516ec4 in nxt_http_rewrite nxt_http_rewrite.c:56
    nginx#6 0x1024fd86c in nxt_http_request_action nxt_http_request.c:565
    nginx#7 0x1024d71b0 in nxt_h1p_request_body_read nxt_h1proto.c:998
    nginx#8 0x1023f5c48 in nxt_event_engine_start nxt_event_engine.c:542
    nginx#9 0x1023e2838 in nxt_thread_trampoline nxt_thread.c:126
    nginx#10 0x18133e030 in _pthread_start+0x84 (libsystem_pthread.dylib:arm64e+0x7030)
    nginx#11 0x181338e38 in thread_start+0x4 (libsystem_pthread.dylib:arm64e+0x1e38)

SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/nxt_http_js.c:169:52

Same fix was introduced in NJS:
http://hg.nginx.org/njs/rev/4fba78789fe4
andrey-zelenkov added a commit to andrey-zelenkov/unit that referenced this issue Jan 31, 2024
Can be reproduced by test/test_rewrite.py::test_rewrite_njs
with enabled UndefinedBehaviorSanitizer:

src/nxt_http_js.c:169:52: runtime error: applying zero offset to null pointer
    #0 0x10255b044 in nxt_http_js_ext_get_args nxt_http_js.c:169
    nginx#1 0x102598ad0 in njs_value_property njs_value.c:1175
    nginx#2 0x10259c2c8 in njs_vm_object_prop njs_vm.c:1398
    nginx#3 0x102559d74 in nxt_js_call nxt_js.c:445
    nginx#4 0x1023c0da0 in nxt_tstr_query nxt_tstr.c:276
    nginx#5 0x102516ec4 in nxt_http_rewrite nxt_http_rewrite.c:56
    nginx#6 0x1024fd86c in nxt_http_request_action nxt_http_request.c:565
    nginx#7 0x1024d71b0 in nxt_h1p_request_body_read nxt_h1proto.c:998
    nginx#8 0x1023f5c48 in nxt_event_engine_start nxt_event_engine.c:542
    nginx#9 0x1023e2838 in nxt_thread_trampoline nxt_thread.c:126
    nginx#10 0x18133e030 in _pthread_start+0x84 (libsystem_pthread.dylib:arm64e+0x7030)
    nginx#11 0x181338e38 in thread_start+0x4 (libsystem_pthread.dylib:arm64e+0x1e38)

SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/nxt_http_js.c:169:52

Same fix was introduced in NJS:
http://hg.nginx.org/njs/rev/4fba78789fe4
andrey-zelenkov added a commit to andrey-zelenkov/unit that referenced this issue Feb 7, 2024
These tests cause router crash when run with AddressSanitizer:

=================================================================
==77196==ERROR: AddressSanitizer: heap-use-after-free on address 0x60c000079340 at pc 0x55d56b132d4b bp 0x7f8cc7f346b0 sp 0x7f8cc7f346a0
READ of size 1 at 0x60c000079340 thread T1
    #0 0x55d56b132d4a in nxt_openssl_conn_io_shutdown src/nxt_openssl.c:1466
    nginx#1 0x55d56b0f6a25 in nxt_h1p_closing src/nxt_h1proto.c:2069
    nginx#2 0x55d56b1009a6 in nxt_h1p_shutdown src/nxt_h1proto.c:2038
    nginx#3 0x55d56b1014c3 in nxt_h1p_request_close src/nxt_h1proto.c:1718
    nginx#4 0x55d56b1045c0 in nxt_http_request_close_handler src/nxt_http_request.c:864
    nginx#5 0x55d56b104988 in nxt_http_request_done src/nxt_http_request.c:795
    nginx#6 0x55d56b0ba0c3 in nxt_event_engine_start src/nxt_event_engine.c:542
    nginx#7 0x55d56b0dcac2 in nxt_router_thread_start src/nxt_router.c:3645
    nginx#8 0x55d56b0b421b in nxt_thread_trampoline src/nxt_thread.c:126
    nginx#9 0x7f8ccab95ac2  (/lib/x86_64-linux-gnu/libc.so.6+0x94ac2)
    nginx#10 0x7f8ccac2784f  (/lib/x86_64-linux-gnu/libc.so.6+0x12684f)
andrey-zelenkov added a commit to andrey-zelenkov/unit that referenced this issue Feb 9, 2024
Can be reproduced by test/test_rewrite.py::test_rewrite_njs
with enabled UndefinedBehaviorSanitizer:

src/nxt_http_js.c:169:52: runtime error: applying zero offset to null pointer
    #0 0x10255b044 in nxt_http_js_ext_get_args nxt_http_js.c:169
    nginx#1 0x102598ad0 in njs_value_property njs_value.c:1175
    nginx#2 0x10259c2c8 in njs_vm_object_prop njs_vm.c:1398
    nginx#3 0x102559d74 in nxt_js_call nxt_js.c:445
    nginx#4 0x1023c0da0 in nxt_tstr_query nxt_tstr.c:276
    nginx#5 0x102516ec4 in nxt_http_rewrite nxt_http_rewrite.c:56
    nginx#6 0x1024fd86c in nxt_http_request_action nxt_http_request.c:565
    nginx#7 0x1024d71b0 in nxt_h1p_request_body_read nxt_h1proto.c:998
    nginx#8 0x1023f5c48 in nxt_event_engine_start nxt_event_engine.c:542
    nginx#9 0x1023e2838 in nxt_thread_trampoline nxt_thread.c:126
    nginx#10 0x18133e030 in _pthread_start+0x84 (libsystem_pthread.dylib:arm64e+0x7030)
    nginx#11 0x181338e38 in thread_start+0x4 (libsystem_pthread.dylib:arm64e+0x1e38)

SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/nxt_http_js.c:169:52

Same fix was introduced in NJS:
<http://hg.nginx.org/njs/rev/4fba78789fe4>
andrey-zelenkov added a commit to andrey-zelenkov/unit that referenced this issue Feb 21, 2024
Can be reproduced by test/test_rewrite.py::test_rewrite_njs
with enabled UndefinedBehaviorSanitizer:

src/nxt_http_js.c:169:52: runtime error: applying zero offset to null pointer
    #0 0x10255b044 in nxt_http_js_ext_get_args nxt_http_js.c:169
    nginx#1 0x102598ad0 in njs_value_property njs_value.c:1175
    nginx#2 0x10259c2c8 in njs_vm_object_prop njs_vm.c:1398
    nginx#3 0x102559d74 in nxt_js_call nxt_js.c:445
    nginx#4 0x1023c0da0 in nxt_tstr_query nxt_tstr.c:276
    nginx#5 0x102516ec4 in nxt_http_rewrite nxt_http_rewrite.c:56
    nginx#6 0x1024fd86c in nxt_http_request_action nxt_http_request.c:565
    nginx#7 0x1024d71b0 in nxt_h1p_request_body_read nxt_h1proto.c:998
    nginx#8 0x1023f5c48 in nxt_event_engine_start nxt_event_engine.c:542
    nginx#9 0x1023e2838 in nxt_thread_trampoline nxt_thread.c:126
    nginx#10 0x18133e030 in _pthread_start+0x84 (libsystem_pthread.dylib:arm64e+0x7030)
    nginx#11 0x181338e38 in thread_start+0x4 (libsystem_pthread.dylib:arm64e+0x1e38)

SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/nxt_http_js.c:169:52

Same fix was introduced in NJS:
<http://hg.nginx.org/njs/rev/4fba78789fe4>
andrey-zelenkov added a commit that referenced this issue Feb 21, 2024
These tests cause router crash when run with AddressSanitizer:

=================================================================
==77196==ERROR: AddressSanitizer: heap-use-after-free on address 0x60c000079340 at pc 0x55d56b132d4b bp 0x7f8cc7f346b0 sp 0x7f8cc7f346a0
READ of size 1 at 0x60c000079340 thread T1
    #0 0x55d56b132d4a in nxt_openssl_conn_io_shutdown src/nxt_openssl.c:1466
    #1 0x55d56b0f6a25 in nxt_h1p_closing src/nxt_h1proto.c:2069
    #2 0x55d56b1009a6 in nxt_h1p_shutdown src/nxt_h1proto.c:2038
    #3 0x55d56b1014c3 in nxt_h1p_request_close src/nxt_h1proto.c:1718
    #4 0x55d56b1045c0 in nxt_http_request_close_handler src/nxt_http_request.c:864
    #5 0x55d56b104988 in nxt_http_request_done src/nxt_http_request.c:795
    #6 0x55d56b0ba0c3 in nxt_event_engine_start src/nxt_event_engine.c:542
    #7 0x55d56b0dcac2 in nxt_router_thread_start src/nxt_router.c:3645
    #8 0x55d56b0b421b in nxt_thread_trampoline src/nxt_thread.c:126
    #9 0x7f8ccab95ac2  (/lib/x86_64-linux-gnu/libc.so.6+0x94ac2)
    #10 0x7f8ccac2784f  (/lib/x86_64-linux-gnu/libc.so.6+0x12684f)
andrey-zelenkov added a commit to andrey-zelenkov/unit that referenced this issue Feb 22, 2024
Can be reproduced by test/test_rewrite.py::test_rewrite_njs
with enabled UndefinedBehaviorSanitizer:

src/nxt_http_js.c:169:52: runtime error: applying zero offset to null pointer
    #0 0x10255b044 in nxt_http_js_ext_get_args nxt_http_js.c:169
    nginx#1 0x102598ad0 in njs_value_property njs_value.c:1175
    nginx#2 0x10259c2c8 in njs_vm_object_prop njs_vm.c:1398
    nginx#3 0x102559d74 in nxt_js_call nxt_js.c:445
    nginx#4 0x1023c0da0 in nxt_tstr_query nxt_tstr.c:276
    nginx#5 0x102516ec4 in nxt_http_rewrite nxt_http_rewrite.c:56
    nginx#6 0x1024fd86c in nxt_http_request_action nxt_http_request.c:565
    nginx#7 0x1024d71b0 in nxt_h1p_request_body_read nxt_h1proto.c:998
    nginx#8 0x1023f5c48 in nxt_event_engine_start nxt_event_engine.c:542
    nginx#9 0x1023e2838 in nxt_thread_trampoline nxt_thread.c:126
    nginx#10 0x18133e030 in _pthread_start+0x84 (libsystem_pthread.dylib:arm64e+0x7030)
    nginx#11 0x181338e38 in thread_start+0x4 (libsystem_pthread.dylib:arm64e+0x1e38)

SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/nxt_http_js.c:169:52

Same fix was introduced in NJS:
<http://hg.nginx.org/njs/rev/4fba78789fe4>

Reviewed-by: Andrew Clayton <[email protected]>
andrey-zelenkov added a commit to andrey-zelenkov/unit that referenced this issue Feb 22, 2024
Can be reproduced by test/test_rewrite.py::test_rewrite_njs
with enabled UndefinedBehaviorSanitizer:

src/nxt_http_js.c:169:52: runtime error: applying zero offset to null pointer
    #0 0x10255b044 in nxt_http_js_ext_get_args nxt_http_js.c:169
    nginx#1 0x102598ad0 in njs_value_property njs_value.c:1175
    nginx#2 0x10259c2c8 in njs_vm_object_prop njs_vm.c:1398
    nginx#3 0x102559d74 in nxt_js_call nxt_js.c:445
    nginx#4 0x1023c0da0 in nxt_tstr_query nxt_tstr.c:276
    nginx#5 0x102516ec4 in nxt_http_rewrite nxt_http_rewrite.c:56
    nginx#6 0x1024fd86c in nxt_http_request_action nxt_http_request.c:565
    nginx#7 0x1024d71b0 in nxt_h1p_request_body_read nxt_h1proto.c:998
    nginx#8 0x1023f5c48 in nxt_event_engine_start nxt_event_engine.c:542
    nginx#9 0x1023e2838 in nxt_thread_trampoline nxt_thread.c:126
    nginx#10 0x18133e030 in _pthread_start+0x84 (libsystem_pthread.dylib:arm64e+0x7030)
    nginx#11 0x181338e38 in thread_start+0x4 (libsystem_pthread.dylib:arm64e+0x1e38)

SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/nxt_http_js.c:169:52

Same fix was introduced in NJS:
<http://hg.nginx.org/njs/rev/4fba78789fe4>

Reviewed-by: Andrew Clayton <[email protected]>
andrey-zelenkov added a commit to andrey-zelenkov/unit that referenced this issue Feb 23, 2024
Can be reproduced by test/test_rewrite.py::test_rewrite_njs
with enabled UndefinedBehaviorSanitizer:

src/nxt_http_js.c:169:52: runtime error: applying zero offset to null pointer
    #0 0x10255b044 in nxt_http_js_ext_get_args nxt_http_js.c:169
    nginx#1 0x102598ad0 in njs_value_property njs_value.c:1175
    nginx#2 0x10259c2c8 in njs_vm_object_prop njs_vm.c:1398
    nginx#3 0x102559d74 in nxt_js_call nxt_js.c:445
    nginx#4 0x1023c0da0 in nxt_tstr_query nxt_tstr.c:276
    nginx#5 0x102516ec4 in nxt_http_rewrite nxt_http_rewrite.c:56
    nginx#6 0x1024fd86c in nxt_http_request_action nxt_http_request.c:565
    nginx#7 0x1024d71b0 in nxt_h1p_request_body_read nxt_h1proto.c:998
    nginx#8 0x1023f5c48 in nxt_event_engine_start nxt_event_engine.c:542
    nginx#9 0x1023e2838 in nxt_thread_trampoline nxt_thread.c:126
    nginx#10 0x18133e030 in _pthread_start+0x84 (libsystem_pthread.dylib:arm64e+0x7030)
    nginx#11 0x181338e38 in thread_start+0x4 (libsystem_pthread.dylib:arm64e+0x1e38)

SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/nxt_http_js.c:169:52

Same fix was introduced in NJS:
<http://hg.nginx.org/njs/rev/4fba78789fe4>

Reviewed-by: Andrew Clayton <[email protected]>
andrey-zelenkov added a commit that referenced this issue Feb 27, 2024
These tests cause router crash when run with AddressSanitizer:

=================================================================
==77196==ERROR: AddressSanitizer: heap-use-after-free on address 0x60c000079340 at pc 0x55d56b132d4b bp 0x7f8cc7f346b0 sp 0x7f8cc7f346a0
READ of size 1 at 0x60c000079340 thread T1
    #0 0x55d56b132d4a in nxt_openssl_conn_io_shutdown src/nxt_openssl.c:1466
    #1 0x55d56b0f6a25 in nxt_h1p_closing src/nxt_h1proto.c:2069
    #2 0x55d56b1009a6 in nxt_h1p_shutdown src/nxt_h1proto.c:2038
    #3 0x55d56b1014c3 in nxt_h1p_request_close src/nxt_h1proto.c:1718
    #4 0x55d56b1045c0 in nxt_http_request_close_handler src/nxt_http_request.c:864
    #5 0x55d56b104988 in nxt_http_request_done src/nxt_http_request.c:795
    #6 0x55d56b0ba0c3 in nxt_event_engine_start src/nxt_event_engine.c:542
    #7 0x55d56b0dcac2 in nxt_router_thread_start src/nxt_router.c:3645
    #8 0x55d56b0b421b in nxt_thread_trampoline src/nxt_thread.c:126
    #9 0x7f8ccab95ac2  (/lib/x86_64-linux-gnu/libc.so.6+0x94ac2)
    #10 0x7f8ccac2784f  (/lib/x86_64-linux-gnu/libc.so.6+0x12684f)
andrey-zelenkov added a commit that referenced this issue Mar 11, 2024
Can be reproduced by test/test_rewrite.py::test_rewrite_njs
with enabled UndefinedBehaviorSanitizer:

src/nxt_http_js.c:169:52: runtime error: applying zero offset to null pointer
    #0 0x10255b044 in nxt_http_js_ext_get_args nxt_http_js.c:169
    #1 0x102598ad0 in njs_value_property njs_value.c:1175
    #2 0x10259c2c8 in njs_vm_object_prop njs_vm.c:1398
    #3 0x102559d74 in nxt_js_call nxt_js.c:445
    #4 0x1023c0da0 in nxt_tstr_query nxt_tstr.c:276
    #5 0x102516ec4 in nxt_http_rewrite nxt_http_rewrite.c:56
    #6 0x1024fd86c in nxt_http_request_action nxt_http_request.c:565
    #7 0x1024d71b0 in nxt_h1p_request_body_read nxt_h1proto.c:998
    #8 0x1023f5c48 in nxt_event_engine_start nxt_event_engine.c:542
    #9 0x1023e2838 in nxt_thread_trampoline nxt_thread.c:126
    #10 0x18133e030 in _pthread_start+0x84 (libsystem_pthread.dylib:arm64e+0x7030)
    #11 0x181338e38 in thread_start+0x4 (libsystem_pthread.dylib:arm64e+0x1e38)

SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/nxt_http_js.c:169:52

Same fix was introduced in NJS:
<http://hg.nginx.org/njs/rev/4fba78789fe4>

Reviewed-by: Andrew Clayton <[email protected]>
pkillarjun pushed a commit to pkillarjun/unit that referenced this issue May 29, 2024
These tests cause router crash when run with AddressSanitizer:

=================================================================
==77196==ERROR: AddressSanitizer: heap-use-after-free on address 0x60c000079340 at pc 0x55d56b132d4b bp 0x7f8cc7f346b0 sp 0x7f8cc7f346a0
READ of size 1 at 0x60c000079340 thread T1
    #0 0x55d56b132d4a in nxt_openssl_conn_io_shutdown src/nxt_openssl.c:1466
    nginx#1 0x55d56b0f6a25 in nxt_h1p_closing src/nxt_h1proto.c:2069
    nginx#2 0x55d56b1009a6 in nxt_h1p_shutdown src/nxt_h1proto.c:2038
    nginx#3 0x55d56b1014c3 in nxt_h1p_request_close src/nxt_h1proto.c:1718
    nginx#4 0x55d56b1045c0 in nxt_http_request_close_handler src/nxt_http_request.c:864
    nginx#5 0x55d56b104988 in nxt_http_request_done src/nxt_http_request.c:795
    nginx#6 0x55d56b0ba0c3 in nxt_event_engine_start src/nxt_event_engine.c:542
    nginx#7 0x55d56b0dcac2 in nxt_router_thread_start src/nxt_router.c:3645
    nginx#8 0x55d56b0b421b in nxt_thread_trampoline src/nxt_thread.c:126
    nginx#9 0x7f8ccab95ac2  (/lib/x86_64-linux-gnu/libc.so.6+0x94ac2)
    nginx#10 0x7f8ccac2784f  (/lib/x86_64-linux-gnu/libc.so.6+0x12684f)
pkillarjun pushed a commit to pkillarjun/unit that referenced this issue May 29, 2024
Can be reproduced by test/test_rewrite.py::test_rewrite_njs
with enabled UndefinedBehaviorSanitizer:

src/nxt_http_js.c:169:52: runtime error: applying zero offset to null pointer
    #0 0x10255b044 in nxt_http_js_ext_get_args nxt_http_js.c:169
    nginx#1 0x102598ad0 in njs_value_property njs_value.c:1175
    nginx#2 0x10259c2c8 in njs_vm_object_prop njs_vm.c:1398
    nginx#3 0x102559d74 in nxt_js_call nxt_js.c:445
    nginx#4 0x1023c0da0 in nxt_tstr_query nxt_tstr.c:276
    nginx#5 0x102516ec4 in nxt_http_rewrite nxt_http_rewrite.c:56
    nginx#6 0x1024fd86c in nxt_http_request_action nxt_http_request.c:565
    nginx#7 0x1024d71b0 in nxt_h1p_request_body_read nxt_h1proto.c:998
    nginx#8 0x1023f5c48 in nxt_event_engine_start nxt_event_engine.c:542
    nginx#9 0x1023e2838 in nxt_thread_trampoline nxt_thread.c:126
    nginx#10 0x18133e030 in _pthread_start+0x84 (libsystem_pthread.dylib:arm64e+0x7030)
    nginx#11 0x181338e38 in thread_start+0x4 (libsystem_pthread.dylib:arm64e+0x1e38)

SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/nxt_http_js.c:169:52

Same fix was introduced in NJS:
<http://hg.nginx.org/njs/rev/4fba78789fe4>

Reviewed-by: Andrew Clayton <[email protected]>
ac000 pushed a commit to ac000/unit that referenced this issue Jun 25, 2024
This issue was found with oss-fuzz.

  ==18420==WARNING: MemorySanitizer: use-of-uninitialized-value
	      #0 0x55dd798a5797 in nxt_vsprintf unit/src/nxt_sprintf.c:163:31
	      #1 0x55dd798d5bdb in nxt_conf_vldt_error unit/src/nxt_conf_validation.c:1525:11
	      #2 0x55dd798dd4cd in nxt_conf_vldt_var unit/src/nxt_conf_validation.c:1560:16
	      #3 0x55dd798dd4cd in nxt_conf_vldt_if unit/src/nxt_conf_validation.c:1592:16
	      nginx#4 0x55dd798d55f4 in nxt_conf_vldt_object unit/src/nxt_conf_validation.c:2815:23
	      nginx#5 0x55dd798d6f84 in nxt_conf_vldt_access_log unit/src/nxt_conf_validation.c:3426:11
	      nginx#6 0x55dd798d55f4 in nxt_conf_vldt_object unit/src/nxt_conf_validation.c:2815:23
	      nginx#7 0x55dd798d47bd in nxt_conf_validate unit/src/nxt_conf_validation.c:1421:11
	      nginx#8 0x55dd79871c82 in LLVMFuzzerTestOneInput unit/fuzzing/nxt_json_fuzz.c:67:5
	      nginx#9 0x55dd79770620 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:614:13
	      nginx#10 0x55dd7975adb4 in fuzzer::RunOneTest(fuzzer::Fuzzer*, char const*, unsigned long) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:327:6
	      nginx#11 0x55dd7976084a in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:862:9
	      nginx#12 0x55dd7978cc42 in main /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerMain.cpp:20:10
	      nginx#13 0x7e8192213082 in __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/libc-start.c:308:16
	      nginx#14 0x55dd7975188d in _start

	    Uninitialized value was created by an allocation of 'error.i' in the stack frame
	      #0 0x55dd798dd42b in nxt_conf_vldt_var unit/src/nxt_conf_validation.c:1557:5
	      #1 0x55dd798dd42b in nxt_conf_vldt_if unit/src/nxt_conf_validation.c:1592:16

The issue was in nxt_tstr_test() where we create an error message with
nxt_sprintf(), where this error message is then later used with the
'%s' format specifier which expects a nul-terminated string, but by
default nxt_sprintf() doesn't nul-terminate, you must use the '%Z'
specifier to signify a '\0' at the end of the string.

Link: <https://github.com/google/oss-fuzz>
Link: <https://oss-fuzz.com/testcase-detail/5545917827055616>
Co-developed-by: Zhidao HONG <[email protected]>
Signed-off-by: Zhidao HONG <[email protected]>
Reviewed-by: Andrew Clayton <[email protected]>
Signed-off-by: Arjun <[email protected]>
[ Commit message/subject - Andrew ]
Signed-off-by: Andrew Clayton <[email protected]>
ac000 pushed a commit to ac000/unit that referenced this issue Jun 25, 2024
This issue was found with oss-fuzz.

  ==18420==WARNING: MemorySanitizer: use-of-uninitialized-value
	      #0 0x55dd798a5797 in nxt_vsprintf unit/src/nxt_sprintf.c:163:31
	      #1 0x55dd798d5bdb in nxt_conf_vldt_error unit/src/nxt_conf_validation.c:1525:11
	      #2 0x55dd798dd4cd in nxt_conf_vldt_var unit/src/nxt_conf_validation.c:1560:16
	      #3 0x55dd798dd4cd in nxt_conf_vldt_if unit/src/nxt_conf_validation.c:1592:16
	      nginx#4 0x55dd798d55f4 in nxt_conf_vldt_object unit/src/nxt_conf_validation.c:2815:23
	      nginx#5 0x55dd798d6f84 in nxt_conf_vldt_access_log unit/src/nxt_conf_validation.c:3426:11
	      nginx#6 0x55dd798d55f4 in nxt_conf_vldt_object unit/src/nxt_conf_validation.c:2815:23
	      nginx#7 0x55dd798d47bd in nxt_conf_validate unit/src/nxt_conf_validation.c:1421:11
	      nginx#8 0x55dd79871c82 in LLVMFuzzerTestOneInput unit/fuzzing/nxt_json_fuzz.c:67:5
	      nginx#9 0x55dd79770620 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:614:13
	      nginx#10 0x55dd7975adb4 in fuzzer::RunOneTest(fuzzer::Fuzzer*, char const*, unsigned long) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:327:6
	      nginx#11 0x55dd7976084a in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:862:9
	      nginx#12 0x55dd7978cc42 in main /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerMain.cpp:20:10
	      nginx#13 0x7e8192213082 in __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/libc-start.c:308:16
	      nginx#14 0x55dd7975188d in _start

	    Uninitialized value was created by an allocation of 'error.i' in the stack frame
	      #0 0x55dd798dd42b in nxt_conf_vldt_var unit/src/nxt_conf_validation.c:1557:5
	      #1 0x55dd798dd42b in nxt_conf_vldt_if unit/src/nxt_conf_validation.c:1592:16

The issue was in nxt_tstr_test() where we create an error message with
nxt_sprintf(), where this error message is then later used with the
'%s' format specifier which expects a nul-terminated string, but by
default nxt_sprintf() doesn't nul-terminate, you must use the '%Z'
specifier to signify a '\0' at the end of the string.

Link: <https://github.com/google/oss-fuzz>
Link: <https://oss-fuzz.com/testcase-detail/5545917827055616>
Co-developed-by: Zhidao HONG <[email protected]>
Signed-off-by: Zhidao HONG <[email protected]>
Reviewed-by: Andrew Clayton <[email protected]>
Signed-off-by: Arjun <[email protected]>
[ Commit message/subject - Andrew ]
Signed-off-by: Andrew Clayton <[email protected]>
ac000 pushed a commit to ac000/unit that referenced this issue Jun 25, 2024
This issue was found with oss-fuzz.

  ==18420==WARNING: MemorySanitizer: use-of-uninitialized-value
	      #0 0x55dd798a5797 in nxt_vsprintf unit/src/nxt_sprintf.c:163:31
	      #1 0x55dd798d5bdb in nxt_conf_vldt_error unit/src/nxt_conf_validation.c:1525:11
	      #2 0x55dd798dd4cd in nxt_conf_vldt_var unit/src/nxt_conf_validation.c:1560:16
	      #3 0x55dd798dd4cd in nxt_conf_vldt_if unit/src/nxt_conf_validation.c:1592:16
	      nginx#4 0x55dd798d55f4 in nxt_conf_vldt_object unit/src/nxt_conf_validation.c:2815:23
	      nginx#5 0x55dd798d6f84 in nxt_conf_vldt_access_log unit/src/nxt_conf_validation.c:3426:11
	      nginx#6 0x55dd798d55f4 in nxt_conf_vldt_object unit/src/nxt_conf_validation.c:2815:23
	      nginx#7 0x55dd798d47bd in nxt_conf_validate unit/src/nxt_conf_validation.c:1421:11
	      nginx#8 0x55dd79871c82 in LLVMFuzzerTestOneInput unit/fuzzing/nxt_json_fuzz.c:67:5
	      nginx#9 0x55dd79770620 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:614:13
	      nginx#10 0x55dd7975adb4 in fuzzer::RunOneTest(fuzzer::Fuzzer*, char const*, unsigned long) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:327:6
	      nginx#11 0x55dd7976084a in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:862:9
	      nginx#12 0x55dd7978cc42 in main /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerMain.cpp:20:10
	      nginx#13 0x7e8192213082 in __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/libc-start.c:308:16
	      nginx#14 0x55dd7975188d in _start

	    Uninitialized value was created by an allocation of 'error.i' in the stack frame
	      #0 0x55dd798dd42b in nxt_conf_vldt_var unit/src/nxt_conf_validation.c:1557:5
	      #1 0x55dd798dd42b in nxt_conf_vldt_if unit/src/nxt_conf_validation.c:1592:16

The issue was in nxt_tstr_test() where we create an error message with
nxt_sprintf(), where this error message is then later used with the
'%s' format specifier which expects a nul-terminated string, but by
default nxt_sprintf() doesn't nul-terminate, you must use the '%Z'
specifier to signify a '\0' at the end of the string.

Link: <https://github.com/google/oss-fuzz>
Link: <https://oss-fuzz.com/testcase-detail/5545917827055616>
Co-developed-by: Zhidao HONG <[email protected]>
Signed-off-by: Zhidao HONG <[email protected]>
Reviewed-by: Andrew Clayton <[email protected]>
Signed-off-by: Arjun <[email protected]>
[ Commit message/subject - Andrew ]
Signed-off-by: Andrew Clayton <[email protected]>
ac000 pushed a commit to ac000/unit that referenced this issue Jun 25, 2024
This issue was found with oss-fuzz.

  ==18420==WARNING: MemorySanitizer: use-of-uninitialized-value
	      #0 0x55dd798a5797 in nxt_vsprintf unit/src/nxt_sprintf.c:163:31
	      #1 0x55dd798d5bdb in nxt_conf_vldt_error unit/src/nxt_conf_validation.c:1525:11
	      #2 0x55dd798dd4cd in nxt_conf_vldt_var unit/src/nxt_conf_validation.c:1560:16
	      #3 0x55dd798dd4cd in nxt_conf_vldt_if unit/src/nxt_conf_validation.c:1592:16
	      nginx#4 0x55dd798d55f4 in nxt_conf_vldt_object unit/src/nxt_conf_validation.c:2815:23
	      nginx#5 0x55dd798d6f84 in nxt_conf_vldt_access_log unit/src/nxt_conf_validation.c:3426:11
	      nginx#6 0x55dd798d55f4 in nxt_conf_vldt_object unit/src/nxt_conf_validation.c:2815:23
	      nginx#7 0x55dd798d47bd in nxt_conf_validate unit/src/nxt_conf_validation.c:1421:11
	      nginx#8 0x55dd79871c82 in LLVMFuzzerTestOneInput unit/fuzzing/nxt_json_fuzz.c:67:5
	      nginx#9 0x55dd79770620 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:614:13
	      nginx#10 0x55dd7975adb4 in fuzzer::RunOneTest(fuzzer::Fuzzer*, char const*, unsigned long) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:327:6
	      nginx#11 0x55dd7976084a in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:862:9
	      nginx#12 0x55dd7978cc42 in main /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerMain.cpp:20:10
	      nginx#13 0x7e8192213082 in __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/libc-start.c:308:16
	      nginx#14 0x55dd7975188d in _start

	    Uninitialized value was created by an allocation of 'error.i' in the stack frame
	      #0 0x55dd798dd42b in nxt_conf_vldt_var unit/src/nxt_conf_validation.c:1557:5
	      #1 0x55dd798dd42b in nxt_conf_vldt_if unit/src/nxt_conf_validation.c:1592:16

The issue was in nxt_tstr_test() where we create an error message with
nxt_sprintf(), where this error message is then later used with the
'%s' format specifier which expects a nul-terminated string, but by
default nxt_sprintf() doesn't nul-terminate, you must use the '%Z'
specifier to signify a '\0' at the end of the string.

Signed-off-by: Arjun <[email protected]>
Co-developed-by: Zhidao HONG <[email protected]>
Signed-off-by: Zhidao HONG <[email protected]>
Link: <https://github.com/google/oss-fuzz>
Link: <https://oss-fuzz.com/testcase-detail/5545917827055616>
Reviewed-by: Andrew Clayton <[email protected]>
[ Commit message/subject - Andrew ]
Signed-off-by: Andrew Clayton <[email protected]>
ac000 pushed a commit to ac000/unit that referenced this issue Jun 25, 2024
This issue was found with oss-fuzz.

  ==18420==WARNING: MemorySanitizer: use-of-uninitialized-value
	      #0 0x55dd798a5797 in nxt_vsprintf unit/src/nxt_sprintf.c:163:31
	      #1 0x55dd798d5bdb in nxt_conf_vldt_error unit/src/nxt_conf_validation.c:1525:11
	      #2 0x55dd798dd4cd in nxt_conf_vldt_var unit/src/nxt_conf_validation.c:1560:16
	      #3 0x55dd798dd4cd in nxt_conf_vldt_if unit/src/nxt_conf_validation.c:1592:16
	      nginx#4 0x55dd798d55f4 in nxt_conf_vldt_object unit/src/nxt_conf_validation.c:2815:23
	      nginx#5 0x55dd798d6f84 in nxt_conf_vldt_access_log unit/src/nxt_conf_validation.c:3426:11
	      nginx#6 0x55dd798d55f4 in nxt_conf_vldt_object unit/src/nxt_conf_validation.c:2815:23
	      nginx#7 0x55dd798d47bd in nxt_conf_validate unit/src/nxt_conf_validation.c:1421:11
	      nginx#8 0x55dd79871c82 in LLVMFuzzerTestOneInput unit/fuzzing/nxt_json_fuzz.c:67:5
	      nginx#9 0x55dd79770620 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:614:13
	      nginx#10 0x55dd7975adb4 in fuzzer::RunOneTest(fuzzer::Fuzzer*, char const*, unsigned long) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:327:6
	      nginx#11 0x55dd7976084a in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:862:9
	      nginx#12 0x55dd7978cc42 in main /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerMain.cpp:20:10
	      nginx#13 0x7e8192213082 in __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/libc-start.c:308:16
	      nginx#14 0x55dd7975188d in _start

	    Uninitialized value was created by an allocation of 'error.i' in the stack frame
	      #0 0x55dd798dd42b in nxt_conf_vldt_var unit/src/nxt_conf_validation.c:1557:5
	      #1 0x55dd798dd42b in nxt_conf_vldt_if unit/src/nxt_conf_validation.c:1592:16

The issue was in nxt_tstr_test() where we create an error message with
nxt_sprintf(), where this error message is then later used with the
'%s' format specifier which expects a nul-terminated string, but by
default nxt_sprintf() doesn't nul-terminate, you must use the '%Z'
specifier to signify a '\0' at the end of the string.

Signed-off-by: Arjun <[email protected]>
Co-developed-by: Zhidao HONG <[email protected]>
Signed-off-by: Zhidao HONG <[email protected]>
Link: <https://github.com/google/oss-fuzz>
Reviewed-by: Andrew Clayton <[email protected]>
[ Commit message/subject - Andrew ]
Signed-off-by: Andrew Clayton <[email protected]>
ac000 added a commit to ac000/unit that referenced this issue Oct 16, 2024
Under Ubuntu 24.04 the pytest for
test/test_php_isolation.py::test_php_isolation_rootfs fails due to Unit
aborting (SIGABRT) in the PHP language module due to FORIFY_SOURCE
hardening detecting a buffer overflow

  2024/10/16 16:46:54 [info] 11661#11661 "phpinfo" application started
  *** buffer overflow detected ***: terminated
  2024/10/16 16:46:54 [alert] 11660#11660 app process 11661 exited on signal 6

After spending an extraordinary amount of time faffing around with
Ubuntu and pytests (they don't make for a pleasant combination) I was
able to reproduce it.

The crash was occurring here

  nginx#4  0x00007ebe818288ff in __GI_abort () at ./stdlib/abort.c:79
  nginx#5  0x00007ebe818297b6 in __libc_message_impl (
      fmt=fmt@entry=0x7ebe819ce765 "*** %s ***: terminated\n")
      at ../sysdeps/posix/libc_fatal.c:132
  nginx#6  0x00007ebe81936c19 in __GI___fortify_fail (
      msg=msg@entry=0x7ebe819ce74c "buffer overflow detected")
      at ./debug/fortify_fail.c:24
  nginx#7  0x00007ebe819365d4 in __GI___chk_fail () at ./debug/chk_fail.c:28
  nginx#8  0x00007ebe8134a055 in mempcpy (__len=10, __src=0x7ebe8160ade8,
      __dest=0x571ba9bd0930)
      at /usr/include/x86_64-linux-gnu/bits/string_fortified.h:45
  nginx#9  fake_data_segment (info=0x0, sysdb=0x571ba9bcf080)
      at /usr/src/php8.1-8.1.30-1+ubuntu24.04.1+deb.sury.org+1/ext/date/lib/parse_tz.c:921
  nginx#10 timelib_builtin_db ()
      at /usr/src/php8.1-8.1.30-1+ubuntu24.04.1+deb.sury.org+1/ext/date/lib/parse_tz.c:1084
  nginx#11 0x00007ebe812e0885 in zm_info_date (zend_module=0x571ba9a14420)

[Well as best as I can tell, as this is from the php 8.1 packages from
<https://github.com/oerdnj/deb.sury.org>, I don't know where the
packages (I'm assuming it's packages) shivammathur/setup-php@v2
installs come from.]

So we get killed in fake_data_segment(), the thing is, that function (as
well as timelib_builtin_db()) doesn't exist in upstream PHP.

It turns out these come from a patch that is applied by distributions to
make PHP use the system installed timezone database rather than the one
built into PHP.

I was unable to reproduce this with vanilla PHP 8.1.

It can be triggered on affected builds with the following config

  {
      "listeners": {
          "[::1]:8080": {
              "pass": "applications/php"
          }
      },

      "applications": {
          "php": {
              "type": "php",
              "root": "/app/php",

      	      "isolation": {
  	          "rootfs": "/tmp/unit-root",

                  "namespaces": {
  	              "mount": true,
  		      "credential": true,
  		      "pid": true
                  }
  	      }
          }
      }
  }

The crux of the issue seems to come down to in this case PHP can't open
the tz database as it's not contained in the new mount namespace.

  190437 openat(AT_FDCWD, "/usr/share/zoneinfo/", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = -1 ENOENT (No such file or directory)
  190437 openat(AT_FDCWD, "/usr/share/zoneinfo/zone.tab", O_RDONLY) = -1 ENOENT (No such file or directory)
  190437 writev(2, [{iov_base="*** ", iov_len=4}, {iov_base="buffer overflow detected", iov_len=24}, {iov_base=" ***: terminated\n", iov_len=17}], 3) = 45
  ...
  190437 --- SIGABRT {si_signo=SIGABRT, si_code=SI_TKILL, si_pid=2, si_uid=65534} ---
  190437 +++ killed by SIGABRT +++

Specifically the issue is with the following code in the patch
(certainly an earlier version of the patch, this is from a Debian patch
<https://sources.debian.org/src/php8.2/8.2.20-1~deb12u1/debian/patches/0007-Add-support-for-use-of-the-system-timezone-database.patch/>)

  +        data = malloc(3 * sysdb->index_size + 7);
  +
  +        p = mempcpy(data, FAKE_HEADER, sizeof(FAKE_HEADER) - 1);

If the zone file hasn't been found then sysdb->index_size is 0. So we
malloc(3) a total of 7 bytes.

However, sizeof(FAKE_HEADER) - 1 is 10. (Hence the __len=10 in the
mempcpy(3) in the above backtrace).

Of course 10 doesn't fit into 7 and the FORTIFY_SOURCE hardening kicks
in and SIGABRTs the process.

Now, it's worth noting that this issue doesn't occur with PHP 8.2 and
8.3.

As can been seen from the Fedora patch for this
<https://src.fedoraproject.org/rpms/php/blob/rawhide/f/php-8.4.0-systzdata-v24.patch>

They actually have a fix incorporated

  r23: fix possible buffer overflow

So the above patch now does

  +        data = malloc(3 * sysdb->index_size + sizeof(FAKE_HEADER) - 1);
  +
  +        p = mempcpy(data, FAKE_HEADER, sizeof(FAKE_HEADER) - 1);

So you will always get at least the required 10 bytes allocated.

I assume the PHP 8.2 & 8.3 packages either no longer use this patch or
have the fixed version. I don't know... I haven't found the sources...

Anyway the above was more about satisfying myself that the problem
wasn't with Unit.

PHP 8.1 is now in security maintenance mode and people are actively
encouraged to upgrade to 8.2/8.3

So lets just remove 8.1 from our testing...

[It's also worth noting that after all this, the ubuntu-latest runners
seemed to have switched back from 24.04 to 22.04. However lets stick
with this and the other ci fixes as who knows when it'll go back to
24.04 (or some other version) again...]

Link: <https://www.php.net/supported-versions.php>
Signed-off-by: Andrew Clayton <[email protected]>
avahahn pushed a commit to javorszky/unit that referenced this issue Oct 22, 2024
Under Ubuntu 24.04 the pytest for
test/test_php_isolation.py::test_php_isolation_rootfs fails due to Unit
aborting (SIGABRT) in the PHP language module due to FORIFY_SOURCE
hardening detecting a buffer overflow

  2024/10/16 16:46:54 [info] 11661#11661 "phpinfo" application started
  *** buffer overflow detected ***: terminated
  2024/10/16 16:46:54 [alert] 11660#11660 app process 11661 exited on signal 6

After spending an extraordinary amount of time faffing around with
Ubuntu and pytests (they don't make for a pleasant combination) I was
able to reproduce it.

The crash was occurring here

  nginx#4  0x00007ebe818288ff in __GI_abort () at ./stdlib/abort.c:79
  nginx#5  0x00007ebe818297b6 in __libc_message_impl (
      fmt=fmt@entry=0x7ebe819ce765 "*** %s ***: terminated\n")
      at ../sysdeps/posix/libc_fatal.c:132
  nginx#6  0x00007ebe81936c19 in __GI___fortify_fail (
      msg=msg@entry=0x7ebe819ce74c "buffer overflow detected")
      at ./debug/fortify_fail.c:24
  nginx#7  0x00007ebe819365d4 in __GI___chk_fail () at ./debug/chk_fail.c:28
  nginx#8  0x00007ebe8134a055 in mempcpy (__len=10, __src=0x7ebe8160ade8,
      __dest=0x571ba9bd0930)
      at /usr/include/x86_64-linux-gnu/bits/string_fortified.h:45
  nginx#9  fake_data_segment (info=0x0, sysdb=0x571ba9bcf080)
      at /usr/src/php8.1-8.1.30-1+ubuntu24.04.1+deb.sury.org+1/ext/date/lib/parse_tz.c:921
  nginx#10 timelib_builtin_db ()
      at /usr/src/php8.1-8.1.30-1+ubuntu24.04.1+deb.sury.org+1/ext/date/lib/parse_tz.c:1084
  nginx#11 0x00007ebe812e0885 in zm_info_date (zend_module=0x571ba9a14420)

[Well as best as I can tell, as this is from the php 8.1 packages from
<https://github.com/oerdnj/deb.sury.org>, I don't know where the
packages (I'm assuming it's packages) shivammathur/setup-php@v2
installs come from.]

So we get killed in fake_data_segment(), the thing is, that function (as
well as timelib_builtin_db()) doesn't exist in upstream PHP.

It turns out these come from a patch that is applied by distributions to
make PHP use the system installed timezone database rather than the one
built into PHP.

I was unable to reproduce this with vanilla PHP 8.1.

It can be triggered on affected builds with the following config

  {
      "listeners": {
          "[::1]:8080": {
              "pass": "applications/php"
          }
      },

      "applications": {
          "php": {
              "type": "php",
              "root": "/app/php",

      	      "isolation": {
  	          "rootfs": "/tmp/unit-root",

                  "namespaces": {
  	              "mount": true,
  		      "credential": true,
  		      "pid": true
                  }
  	      }
          }
      }
  }

The crux of the issue seems to come down to in this case PHP can't open
the tz database as it's not contained in the new mount namespace.

  190437 openat(AT_FDCWD, "/usr/share/zoneinfo/", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = -1 ENOENT (No such file or directory)
  190437 openat(AT_FDCWD, "/usr/share/zoneinfo/zone.tab", O_RDONLY) = -1 ENOENT (No such file or directory)
  190437 writev(2, [{iov_base="*** ", iov_len=4}, {iov_base="buffer overflow detected", iov_len=24}, {iov_base=" ***: terminated\n", iov_len=17}], 3) = 45
  ...
  190437 --- SIGABRT {si_signo=SIGABRT, si_code=SI_TKILL, si_pid=2, si_uid=65534} ---
  190437 +++ killed by SIGABRT +++

Specifically the issue is with the following code in the patch
(certainly an earlier version of the patch, this is from a Debian patch
<https://sources.debian.org/src/php8.2/8.2.20-1~deb12u1/debian/patches/0007-Add-support-for-use-of-the-system-timezone-database.patch/>)

  +        data = malloc(3 * sysdb->index_size + 7);
  +
  +        p = mempcpy(data, FAKE_HEADER, sizeof(FAKE_HEADER) - 1);

If the zone file hasn't been found then sysdb->index_size is 0. So we
malloc(3) a total of 7 bytes.

However, sizeof(FAKE_HEADER) - 1 is 10. (Hence the __len=10 in the
mempcpy(3) in the above backtrace).

Of course 10 doesn't fit into 7 and the FORTIFY_SOURCE hardening kicks
in and SIGABRTs the process.

Now, it's worth noting that this issue doesn't occur with PHP 8.2 and
8.3.

As can been seen from the Fedora patch for this
<https://src.fedoraproject.org/rpms/php/blob/rawhide/f/php-8.4.0-systzdata-v24.patch>

They actually have a fix incorporated

  r23: fix possible buffer overflow

So the above patch now does

  +        data = malloc(3 * sysdb->index_size + sizeof(FAKE_HEADER) - 1);
  +
  +        p = mempcpy(data, FAKE_HEADER, sizeof(FAKE_HEADER) - 1);

So you will always get at least the required 10 bytes allocated.

I assume the PHP 8.2 & 8.3 packages either no longer use this patch or
have the fixed version. I don't know... I haven't found the sources...

Anyway the above was more about satisfying myself that the problem
wasn't with Unit.

PHP 8.1 is now in security maintenance mode and people are actively
encouraged to upgrade to 8.2/8.3

So lets just remove 8.1 from our testing...

[It's also worth noting that after all this, the ubuntu-latest runners
seemed to have switched back from 24.04 to 22.04. However lets stick
with this and the other ci fixes as who knows when it'll go back to
24.04 (or some other version) again...]

Link: <https://www.php.net/supported-versions.php>
Signed-off-by: Andrew Clayton <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants