annotate auto/endianness @ 6359:dac6eda40475 stable-1.8

Resolver: fixed use-after-free memory accesses with CNAME. When several requests were waiting for a response, then after getting a CNAME response only the last request's context had the name updated. Contexts of other requests had the wrong name. This name was used by ngx_resolve_name_done() to find the node to remove the request context from. When the name was wrong, the request could not be properly cancelled, its context was freed but stayed linked to the node's waiting list. This happened e.g. when the first request was aborted or timed out before the resolving completed. When it completed, this triggered a use-after-free memory access by calling ctx->handler of already freed request context. The bug manifests itself by "could not cancel <name> resolving" alerts in error_log. When a request was responded with a CNAME, the request context kept the pointer to the original node's rn->u.cname. If the original node expired before the resolving timed out or completed with an error, this would trigger a use-after-free memory access via ctx->name in ctx->handler(). The fix is to keep ctx->name unmodified. The name from context is no longer used by ngx_resolve_name_done(). Instead, we now keep the pointer to resolver node to which this request is linked. Keeping the original name intact also improves logging.
author Roman Arutyunyan <arut@nginx.com>
date Tue, 26 Jan 2016 16:46:59 +0300
parents 434548349838
children 7ec809b579d7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
444
42d11f017717 nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents: 370
diff changeset
1
42d11f017717 nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents: 370
diff changeset
2 # Copyright (C) Igor Sysoev
4412
d620f497c50f Copyright updated.
Maxim Konovalov <maxim@nginx.com>
parents: 703
diff changeset
3 # Copyright (C) Nginx, Inc.
444
42d11f017717 nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents: 370
diff changeset
4
370
54f76b0b8dca nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
5
4681
bb37a9cc08fb Fixed spelling of "endianness", and called it "byte ordering" in the
Ruslan Ermilov <ru@nginx.com>
parents: 4412
diff changeset
6 echo $ngx_n "checking for system byte ordering ...$ngx_c"
370
54f76b0b8dca nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
7 echo >> $NGX_ERR
4681
bb37a9cc08fb Fixed spelling of "endianness", and called it "byte ordering" in the
Ruslan Ermilov <ru@nginx.com>
parents: 4412
diff changeset
8 echo "checking for system byte ordering" >> $NGX_ERR
370
54f76b0b8dca nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
9
54f76b0b8dca nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
10
54f76b0b8dca nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
11 cat << END > $NGX_AUTOTEST.c
54f76b0b8dca nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
12
54f76b0b8dca nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
13 int main() {
54f76b0b8dca nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
14 int i = 0x11223344;
54f76b0b8dca nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
15 char *p;
54f76b0b8dca nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
16
54f76b0b8dca nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
17 p = (char *) &i;
54f76b0b8dca nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
18 if (*p == 0x44) return 0;
54f76b0b8dca nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
19 return 1;
54f76b0b8dca nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
20 }
54f76b0b8dca nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
21
54f76b0b8dca nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
22 END
54f76b0b8dca nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
23
583
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
24 ngx_test="$CC $CC_TEST_FLAGS $CC_AUX_FLAGS \
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
25 -o $NGX_AUTOTEST $NGX_AUTOTEST.c $NGX_LD_OPT $ngx_feature_libs"
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
26
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
27 eval "$ngx_test >> $NGX_AUTOCONF_ERR 2>&1"
370
54f76b0b8dca nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
28
54f76b0b8dca nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
29 if [ -x $NGX_AUTOTEST ]; then
703
694d285ec752 fix ">/dev/null 2>&1" order
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
30 if $NGX_AUTOTEST >/dev/null 2>&1; then
4681
bb37a9cc08fb Fixed spelling of "endianness", and called it "byte ordering" in the
Ruslan Ermilov <ru@nginx.com>
parents: 4412
diff changeset
31 echo " little endian"
469
2ff194b74f1e nginx-0.1.9-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 455
diff changeset
32 have=NGX_HAVE_LITTLE_ENDIAN . auto/have
370
54f76b0b8dca nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
33 else
4681
bb37a9cc08fb Fixed spelling of "endianness", and called it "byte ordering" in the
Ruslan Ermilov <ru@nginx.com>
parents: 4412
diff changeset
34 echo " big endian"
370
54f76b0b8dca nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
35 fi
54f76b0b8dca nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
36
5309
434548349838 Configure: fixed autotest cleanup commands.
Sergey Kandaurov <pluknet@nginx.com>
parents: 4681
diff changeset
37 rm -rf $NGX_AUTOTEST*
370
54f76b0b8dca nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
38
54f76b0b8dca nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
39 else
5309
434548349838 Configure: fixed autotest cleanup commands.
Sergey Kandaurov <pluknet@nginx.com>
parents: 4681
diff changeset
40 rm -rf $NGX_AUTOTEST*
370
54f76b0b8dca nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
41
54f76b0b8dca nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
42 echo
4681
bb37a9cc08fb Fixed spelling of "endianness", and called it "byte ordering" in the
Ruslan Ermilov <ru@nginx.com>
parents: 4412
diff changeset
43 echo "$0: error: cannot detect system byte ordering"
370
54f76b0b8dca nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
44 exit 1
54f76b0b8dca nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
45 fi