annotate src/core/ngx_crc32.h @ 9274:46ecad404a29 default tip

Mail: reset imap tag to empty after authentication attempt. We need to reset the imap tag to empty after an authentication attempt completes, otherwise if the next line parsed is incomplete with no tag (e.g. empty line) then we use the "tag" from the previous buffer which is now definitely wrong and has been partially overwritten with the most recently read data (e.g. CRLF). An example before this patch: S: * OK IMAP4 ready C: foobar login a b S: foobar NO Incorrect username or password. C: S: S: obar BAD invalid command Then with this patch: S: * OK IMAP4 ready C: foobar login a b S: foobar NO Incorrect username or password. C: S: * BAD invalid command
author Rob Mueller <robm@fastmailteam.com>
date Wed, 15 May 2024 10:06:00 +0300
parents d620f497c50f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
790
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2 /*
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3 * Copyright (C) Igor Sysoev
4412
d620f497c50f Copyright updated.
Maxim Konovalov <maxim@nginx.com>
parents: 1697
diff changeset
4 * Copyright (C) Nginx, Inc.
790
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
5 */
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
6
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
7
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
8 #ifndef _NGX_CRC32_H_INCLUDED_
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
9 #define _NGX_CRC32_H_INCLUDED_
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
10
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
11
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
12 #include <ngx_config.h>
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
13 #include <ngx_core.h>
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
14
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
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
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
18
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
19
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
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
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
40 {
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
41 uint32_t crc;
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
42
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
43 crc = 0xffffffff;
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
44
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
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
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
47 }
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
48
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
49 return crc ^ 0xffffffff;
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
50 }
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
51
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
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
d6afb8723155 fix r1695
Igor Sysoev <igor@sysoev.ru>
parents: 1694
diff changeset
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
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
79 #endif /* _NGX_CRC32_H_INCLUDED_ */