Skip to content

Commit e989aa3

Browse files
committed
🚑 Undefined behavior of the C language. #17
1 parent 54671c0 commit e989aa3

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

inc/ngx_http_waf_module_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ static ngx_int_t load_into_container(ngx_conf_t* cf, const char* file_name, void
519519
"ngx_waf: In line %d, [%s] is not a valid IPV6 string.", line_number, ipv6.text);
520520
return FAIL;
521521
}
522-
memcpy(inx_addr.ipv6.__in6_u.__u6_addr8, ipv6.prefix, 16);
522+
memcpy(inx_addr.ipv6.s6_addr, ipv6.prefix, 16);
523523
if (ip_trie_add((ip_trie_t*)container, &inx_addr, ipv6.suffix_num, ipv6.text) != SUCCESS) {
524524
if (ip_trie_find((ip_trie_t*)container, &inx_addr, &ip_trie_node) == SUCCESS) {
525525
ngx_conf_log_error(NGX_LOG_ERR, (cf), 0,

inc/ngx_http_waf_module_ip_trie.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ static ngx_int_t ip_trie_add(ip_trie_t* trie, inx_addr_t* inx_addr, uint32_t suf
170170
}
171171
}
172172
prev_node = cur_node;
173-
if (CHECK_BIT(inx_addr->ipv6.__in6_u.__u6_addr8[uint8_index], 7 - (bit_index % 8)) != TRUE) {
173+
if (CHECK_BIT(inx_addr->ipv6.s6_addr[uint8_index], 7 - (bit_index % 8)) != TRUE) {
174174
cur_node = cur_node->left;
175175
prev_bit = 0;
176176
} else {
@@ -191,7 +191,7 @@ static ngx_int_t ip_trie_add(ip_trie_t* trie, inx_addr_t* inx_addr, uint32_t suf
191191
}
192192
}
193193
uint8_index = bit_index / 8;
194-
if (CHECK_BIT(inx_addr->ipv6.__in6_u.__u6_addr8[uint8_index], 7 - (bit_index % 8)) != TRUE) {
194+
if (CHECK_BIT(inx_addr->ipv6.s6_addr[uint8_index], 7 - (bit_index % 8)) != TRUE) {
195195
cur_node->left = new_node;
196196
} else {
197197
cur_node->right = new_node;
@@ -232,7 +232,7 @@ static ngx_int_t ip_trie_find(ip_trie_t* trie, inx_addr_t* inx_addr, ip_trie_nod
232232
} else if (trie->ip_type == AF_INET6) {
233233
while (bit_index < 128 && cur_node != NULL && cur_node->is_ip != TRUE) {
234234
int uint8_index = bit_index / 8;
235-
if (CHECK_BIT(inx_addr->ipv6.__in6_u.__u6_addr8[uint8_index], 7 - (bit_index % 8)) != TRUE) {
235+
if (CHECK_BIT(inx_addr->ipv6.s6_addr[uint8_index], 7 - (bit_index % 8)) != TRUE) {
236236
cur_node = cur_node->left;
237237
} else {
238238
cur_node = cur_node->right;

inc/ngx_http_waf_module_util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ static ngx_int_t parse_ipv6(ngx_str_t text, ipv6_t* ipv6) {
188188
if (inet_pton(AF_INET6, prefix_text, &addr6) != 1) {
189189
return FAIL;
190190
}
191-
memcpy(prefix, &addr6.__in6_u.__u6_addr8, 16);
191+
memcpy(prefix, &addr6.s6_addr, 16);
192192

193193
uint32_t temp_suffix = 0;
194194
if (*c == '/') {

0 commit comments

Comments
 (0)