Mercurial > hg > nginx
annotate src/core/ngx_crc32.h @ 5418:6961d52ebc49 stable-1.4
Core: fix misallocation at ngx_crypt_apr1 (ticket #412).
Found by using auth_basic.t from mdounin nginx-tests under valgrind.
==10470== Invalid write of size 1
==10470== at 0x43603D: ngx_crypt_to64 (ngx_crypt.c:168)
==10470== by 0x43648E: ngx_crypt (ngx_crypt.c:153)
==10470== by 0x489D8B: ngx_http_auth_basic_crypt_handler (ngx_http_auth_basic_module.c:297)
==10470== by 0x48A24A: ngx_http_auth_basic_handler (ngx_http_auth_basic_module.c:240)
==10470== by 0x44EAB9: ngx_http_core_access_phase (ngx_http_core_module.c:1121)
==10470== by 0x44A822: ngx_http_core_run_phases (ngx_http_core_module.c:895)
==10470== by 0x44A932: ngx_http_handler (ngx_http_core_module.c:878)
==10470== by 0x455EEF: ngx_http_process_request (ngx_http_request.c:1852)
==10470== by 0x456527: ngx_http_process_request_headers (ngx_http_request.c:1283)
==10470== by 0x456A91: ngx_http_process_request_line (ngx_http_request.c:964)
==10470== by 0x457097: ngx_http_wait_request_handler (ngx_http_request.c:486)
==10470== by 0x4411EE: ngx_epoll_process_events (ngx_epoll_module.c:691)
==10470== Address 0x5866fab is 0 bytes after a block of size 27 alloc'd
==10470== at 0x4A074CD: malloc (vg_replace_malloc.c:236)
==10470== by 0x43B251: ngx_alloc (ngx_alloc.c:22)
==10470== by 0x421B0D: ngx_malloc (ngx_palloc.c:119)
==10470== by 0x421B65: ngx_pnalloc (ngx_palloc.c:147)
==10470== by 0x436368: ngx_crypt (ngx_crypt.c:140)
==10470== by 0x489D8B: ngx_http_auth_basic_crypt_handler (ngx_http_auth_basic_module.c:297)
==10470== by 0x48A24A: ngx_http_auth_basic_handler (ngx_http_auth_basic_module.c:240)
==10470== by 0x44EAB9: ngx_http_core_access_phase (ngx_http_core_module.c:1121)
==10470== by 0x44A822: ngx_http_core_run_phases (ngx_http_core_module.c:895)
==10470== by 0x44A932: ngx_http_handler (ngx_http_core_module.c:878)
==10470== by 0x455EEF: ngx_http_process_request (ngx_http_request.c:1852)
==10470== by 0x456527: ngx_http_process_request_headers (ngx_http_request.c:1283)
==10470==
author | Markus Linnala <Markus.Linnala@cybercom.com> |
---|---|
date | Fri, 20 Sep 2013 17:57:21 +0300 |
parents | d620f497c50f |
children |
rev | line source |
---|---|
790 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4412 | 4 * Copyright (C) Nginx, Inc. |
790 | 5 */ |
6 | |
7 | |
8 #ifndef _NGX_CRC32_H_INCLUDED_ | |
9 #define _NGX_CRC32_H_INCLUDED_ | |
10 | |
11 | |
12 #include <ngx_config.h> | |
13 #include <ngx_core.h> | |
14 | |
15 | |
793
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
16 extern uint32_t *ngx_crc32_table_short; |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
17 extern uint32_t ngx_crc32_table256[]; |
790 | 18 |
19 | |
20 static ngx_inline uint32_t | |
793
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
21 ngx_crc32_short(u_char *p, size_t len) |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
22 { |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
23 u_char c; |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
24 uint32_t crc; |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
25 |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
26 crc = 0xffffffff; |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
27 |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
28 while (len--) { |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
29 c = *p++; |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
30 crc = ngx_crc32_table_short[(crc ^ (c & 0xf)) & 0xf] ^ (crc >> 4); |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
31 crc = ngx_crc32_table_short[(crc ^ (c >> 4)) & 0xf] ^ (crc >> 4); |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
32 } |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
33 |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
34 return crc ^ 0xffffffff; |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
35 } |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
36 |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
37 |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
38 static ngx_inline uint32_t |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
39 ngx_crc32_long(u_char *p, size_t len) |
790 | 40 { |
41 uint32_t crc; | |
42 | |
43 crc = 0xffffffff; | |
44 | |
45 while (len--) { | |
793
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
46 crc = ngx_crc32_table256[(crc ^ *p++) & 0xff] ^ (crc >> 8); |
790 | 47 } |
48 | |
49 return crc ^ 0xffffffff; | |
50 } | |
51 | |
52 | |
1694
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
53 #define ngx_crc32_init(crc) \ |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
54 crc = 0xffffffff |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
55 |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
56 |
1697 | 57 static ngx_inline void |
1694
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
58 ngx_crc32_update(uint32_t *crc, u_char *p, size_t len) |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
59 { |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
60 uint32_t c; |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
61 |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
62 c = *crc; |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
63 |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
64 while (len--) { |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
65 c = ngx_crc32_table256[(c ^ *p++) & 0xff] ^ (c >> 8); |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
66 } |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
67 |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
68 *crc = c; |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
69 } |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
70 |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
71 |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
72 #define ngx_crc32_final(crc) \ |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
73 crc ^= 0xffffffff |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
74 |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
75 |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
76 ngx_int_t ngx_crc32_table_init(void); |
793
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
77 |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
78 |
790 | 79 #endif /* _NGX_CRC32_H_INCLUDED_ */ |