Review Board 1.7.16


clang compiler warning: fixes for tests to be compiled using clang

Review Request #4555 - Created March 29, 2015 and submitted

Diederik de Groot
13
ASTERISK-24917
Reviewers
asterisk-dev
Asterisk
clang's static analyzer will throw quite a number warnings / errors during compilation, some of which can be very helpfull in finding corner-case bugs. 

fixes for tests to be compiled using clang
executing the tests one-by-one works fine (completes to end) (skipping /main/stdtime) -> 
test show results failed:


=================== /main/message/ ====== 
FAIL   test_message_queue_handler_nom /main/message/             31036ms
[test_message.c:int handler_wait_for_message(struct ast_test *):244]: Test timed out while waiting for handler to get message

Not sure if this is actually a fail or just a timeout. WIP


=================== /main/strings/ ====== 
FAIL   escape_semicolons              /main/strings/             1ms     
[Mar 29 20:13:43] ERROR[2521]: utils.c:493 char *ast_escape_semicolons(const char *, char *, int): FRACK!, Failed assertion string != NULL && outbuf != NULL (0)
-> explainable by the change made to the source. ast_alloca(0) is not being executed -> test2 = NULL: need to resolv the open question how to handle ast_alloca(0) before making any further changes.

(With revision 5 of this code, this test now passes without a problem, had to fix both the test and the function being tested though)


=================== /main/stdtime ====== 
"test execute all" fails, caused by the /main/stdtime/ test. 
START  /main/stdtime/ - timezone_watch 
[test_time.c:enum ast_test_result_state test_timezone_watch(struct ast_test_info *, enum ast_test_command, struct ast_test *):84]: Executing deletion test...
j62747*CLI> 
CLI becomes unresponsive / no further command completion for example.
Guess this will need a little further investigation. Maybe the source changes made to main/stdtime/ where not completely correct.

Seems to be caused by inotify_daemon, at least there is where the segfault happens. WIP
<?xml version="1.0" encoding="UTF-8"?>
<testsuite errors="0" time="181.742" tests="444" n
<properties>
<property name="version" value="SV

Changes between revision 1 and 8

1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9

  1. /branches/13/tests/test_acl.c: Loading...
  2. /branches/13/tests/test_linkedlists.c: Loading...
  3. /branches/13/tests/test_stringfields.c: Loading...
  4. /branches/13/tests/test_strings.c: Loading...
/branches/13/tests/test_acl.c
Diff Revision 1 Diff Revision 8
1
/*
1
/*
2
 * Asterisk -- An open source telephony toolkit.
2
 * Asterisk -- An open source telephony toolkit.
3
 *
3
 *
4
 * Copyright (C) 2010, Digium, Inc.
4
 * Copyright (C) 2010, Digium, Inc.
5
 *
5
 *
6
 * Mark Michelson <mmichelson@digium.com>
6
 * Mark Michelson <mmichelson@digium.com>
7
 *
7
 *
8
 * See http://www.asterisk.org for more information about
8
 * See http://www.asterisk.org for more information about
9
 * the Asterisk project. Please do not directly contact
9
 * the Asterisk project. Please do not directly contact
10
 * any of the maintainers of this project for assistance;
10
 * any of the maintainers of this project for assistance;
11
 * the project provides a web site, mailing lists and IRC
11
 * the project provides a web site, mailing lists and IRC
12
 * channels for your use.
12
 * channels for your use.
13
 *
13
 *
14
 * This program is free software, distributed under the terms of
14
 * This program is free software, distributed under the terms of
15
 * the GNU General Public License Version 2. See the LICENSE file
15
 * the GNU General Public License Version 2. See the LICENSE file
16
 * at the top of the source tree.
16
 * at the top of the source tree.
17
 */
17
 */
18

    
   
18

   
19
/*!
19
/*!
20
 * \file
20
 * \file
21
 * \brief ACL unit tests
21
 * \brief ACL unit tests
22
 *
22
 *
23
 * \author Mark Michelson <mmichelson@digium.com>
23
 * \author Mark Michelson <mmichelson@digium.com>
24
 *
24
 *
25
 */
25
 */
26

    
   
26

   
27
/*** MODULEINFO
27
/*** MODULEINFO
28
	<depend>TEST_FRAMEWORK</depend>
28
	<depend>TEST_FRAMEWORK</depend>
29
	<support_level>core</support_level>
29
	<support_level>core</support_level>
30
 ***/
30
 ***/
31

    
   
31

   
32
#include "asterisk.h"
32
#include "asterisk.h"
33

    
   
33

   
34
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
34
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
35

    
   
35

   
36
#include "asterisk/test.h"
36
#include "asterisk/test.h"
37
#include "asterisk/acl.h"
37
#include "asterisk/acl.h"
38
#include "asterisk/module.h"
38
#include "asterisk/module.h"
39
#include "asterisk/netsock2.h"
39
#include "asterisk/netsock2.h"
40
#include "asterisk/config.h"
40
#include "asterisk/config.h"
41

    
   
41

   
42
AST_TEST_DEFINE(invalid_acl)
42
AST_TEST_DEFINE(invalid_acl)
43
{
43
{
44
	const char * invalid_acls[] = {
44
	const char * invalid_acls[] = {
45
		/* Negative netmask */
45
		/* Negative netmask */
46
		"1.3.3.7/-1",
46
		"1.3.3.7/-1",
47
		/* Netmask too large */
47
		/* Netmask too large */
48
		"1.3.3.7/33",
48
		"1.3.3.7/33",
49
		/* Netmask waaaay too large */
49
		/* Netmask waaaay too large */
50
		"1.3.3.7/92342348927389492307420",
50
		"1.3.3.7/92342348927389492307420",
51
		/* Netmask non-numeric */
51
		/* Netmask non-numeric */
52
		"1.3.3.7/California",
52
		"1.3.3.7/California",
53
		/* Too many octets in Netmask */
53
		/* Too many octets in Netmask */
54
		"1.3.3.7/255.255.255.255.255",
54
		"1.3.3.7/255.255.255.255.255",
55
		/* Octets in IP address exceed 255 */
55
		/* Octets in IP address exceed 255 */
56
		"57.60.278.900/31",
56
		"57.60.278.900/31",
57
		/* Octets in IP address exceed 255 and are negative */
57
		/* Octets in IP address exceed 255 and are negative */
58
		"400.32.201029.-6/24",
58
		"400.32.201029.-6/24",
59
		/* Invalidly formatted IP address */
59
		/* Invalidly formatted IP address */
60
		"EGGSOFDEATH/4000",
60
		"EGGSOFDEATH/4000",
61
		/* Too many octets in IP address */
61
		/* Too many octets in IP address */
62
		"33.4.7.8.3/300030",
62
		"33.4.7.8.3/300030",
63
		/* Too many octets in Netmask */
63
		/* Too many octets in Netmask */
64
		"1.2.3.4/6.7.8.9.0",
64
		"1.2.3.4/6.7.8.9.0",
65
		/* Too many octets in IP address */
65
		/* Too many octets in IP address */
66
		"3.1.4.1.5.9/3",
66
		"3.1.4.1.5.9/3",
67
		/* IPv6 address has multiple double colons */
67
		/* IPv6 address has multiple double colons */
68
		"ff::ff::ff/3",
68
		"ff::ff::ff/3",
69
		/* IPv6 address is too long */
69
		/* IPv6 address is too long */
70
		"1234:5678:90ab:cdef:1234:5678:90ab:cdef:1234/56",
70
		"1234:5678:90ab:cdef:1234:5678:90ab:cdef:1234/56",
71
		/* IPv6 netmask is too large */
71
		/* IPv6 netmask is too large */
72
		"::ffff/129",
72
		"::ffff/129",
73
		/* IPv4-mapped IPv6 address has too few octets */
73
		/* IPv4-mapped IPv6 address has too few octets */
74
		"::ffff:255.255.255/128",
74
		"::ffff:255.255.255/128",
75
		/* Leading and trailing colons for IPv6 address */
75
		/* Leading and trailing colons for IPv6 address */
76
		":1234:/15",
76
		":1234:/15",
77
		/* IPv6 address and IPv4 netmask */
77
		/* IPv6 address and IPv4 netmask */
78
		"fe80::1234/255.255.255.0",
78
		"fe80::1234/255.255.255.0",
79
	};
79
	};
80

    
   
80

   
81
	enum ast_test_result_state res = AST_TEST_PASS;
81
	enum ast_test_result_state res = AST_TEST_PASS;
82
	struct ast_ha *ha = NULL;
82
	struct ast_ha *ha = NULL;
83
	int i;
83
	int i;
84

    
   
84

   
85
	switch (cmd) {
85
	switch (cmd) {
86
	case TEST_INIT:
86
	case TEST_INIT:
87
		info->name = "invalid_acl";
87
		info->name = "invalid_acl";
88
		info->category = "/main/acl/";
88
		info->category = "/main/acl/";
89
		info->summary = "Invalid ACL unit test";
89
		info->summary = "Invalid ACL unit test";
90
		info->description =
90
		info->description =
91
			"Ensures that garbage ACL values are not accepted";
91
			"Ensures that garbage ACL values are not accepted";
92
		return AST_TEST_NOT_RUN;
92
		return AST_TEST_NOT_RUN;
93
	case TEST_EXECUTE:
93
	case TEST_EXECUTE:
94
		break;
94
		break;
95
	}
95
	}
96

    
   
96

   
97
	for (i = 0; i < ARRAY_LEN(invalid_acls); ++i) {
97
	for (i = 0; i < ARRAY_LEN(invalid_acls); ++i) {
98
		int err = 0;
98
		int err = 0;
99
		ha = ast_append_ha("permit", invalid_acls[i], ha, &err);
99
		ha = ast_append_ha("permit", invalid_acls[i], ha, &err);
100
		if (ha || !err) {
100
		if (ha || !err) {
101
			ast_test_status_update(test, "ACL %s accepted even though it is total garbage.\n",
101
			ast_test_status_update(test, "ACL %s accepted even though it is total garbage.\n",
102
					invalid_acls[i]);
102
					invalid_acls[i]);
103
			if (ha) {
103
			if (ha) {
104
				ast_free_ha(ha);
104
				ast_free_ha(ha);
105
			}
105
			}
106
			res = AST_TEST_FAIL;
106
			res = AST_TEST_FAIL;
107
		}
107
		}
108
	}
108
	}
109

    
   
109

   
110
	return res;
110
	return res;
111
}
111
}
112

    
   
112

   
113
struct acl {
113
struct acl {
114
	const char *host;
114
	const char *host;
115
	const char *access;
115
	const char *access;
116
};
116
};
117

    
   
117

   
118
/* These constants are defined for the sole purpose of being shorter
118
/* These constants are defined for the sole purpose of being shorter
119
 * than their real names. It makes lines in this test quite a bit shorter
119
 * than their real names. It makes lines in this test quite a bit shorter
120
 */
120
 */
121

    
   
121

   
122
#define TACL_A AST_SENSE_ALLOW
122
#define TACL_A AST_SENSE_ALLOW
123
#define TACL_D AST_SENSE_DENY
123
#define TACL_D AST_SENSE_DENY
124

    
   
124

   
125
static int build_ha(const struct acl *acl, size_t len, struct ast_ha **ha, const char *acl_name, int *err, struct ast_test *test, enum ast_test_result_state res);
125
static int build_ha(const struct acl *acl, size_t len, struct ast_ha **ha, const char *acl_name, int *err, struct ast_test *test, enum ast_test_result_state *res) 
126
static int build_ha(const struct acl *acl, size_t len, struct ast_ha **ha, const char *acl_name, int *err, struct ast_test *test, enum ast_test_result_state res) {
126
{
127
	size_t i;
127
	size_t i;
128

    
   
128

   
129
	for (i = 0; i < len; ++i) {
129
	for (i = 0; i < len; ++i) {
130
		if (!(*ha = ast_append_ha(acl[i].access, acl[i].host, *ha, err))) {
130
		if (!(*ha = ast_append_ha(acl[i].access, acl[i].host, *ha, err))) {
131
			ast_test_status_update(test, "Failed to add rule %s with access %s to %s\n",
131
			ast_test_status_update(test, "Failed to add rule %s with access %s to %s\n",
132
					       acl[i].host, acl[i].access, acl_name);
132
					       acl[i].host, acl[i].access, acl_name);
133
			res = AST_TEST_FAIL;
133
			*res = AST_TEST_FAIL;
134
			return -1;
134
			return -1;
135
		}
135
		}
136
	}
136
	}
137

    
   
137

   
138
	return 0;
138
	return 0;
139
}
139
}
140

    
   
140

   
141
AST_TEST_DEFINE(acl)
141
AST_TEST_DEFINE(acl)
142
{
142
{
143
	struct acl permitallv4 = { "0.0.0.0/0", "permit" };
143
	struct acl permitallv4 = { "0.0.0.0/0", "permit" };
144
	struct acl denyallv4 = { "0.0.0.0/0", "deny" };
144
	struct acl denyallv4 = { "0.0.0.0/0", "deny" };
145
	struct acl permitallv6 = { "::/0", "permit" };
145
	struct acl permitallv6 = { "::/0", "permit" };
146
	struct acl denyallv6 = { "::/0", "deny" };
146
	struct acl denyallv6 = { "::/0", "deny" };
147

    
   
147

   
148
	struct acl acl1[] = {
148
	struct acl acl1[] = {
149
		{ "0.0.0.0/0.0.0.0", "deny" },
149
		{ "0.0.0.0/0.0.0.0", "deny" },
150
		{ "10.0.0.0/255.0.0.0", "permit" },
150
		{ "10.0.0.0/255.0.0.0", "permit" },
151
		{ "192.168.0.0/255.255.255.0", "permit" },
151
		{ "192.168.0.0/255.255.255.0", "permit" },
152
	};
152
	};
153

    
   
153

   
154
	struct acl acl2[] = {
154
	struct acl acl2[] = {
155
		{ "10.0.0.0/8", "deny" },
155
		{ "10.0.0.0/8", "deny" },
156
		{ "10.0.0.0/8", "permit" },
156
		{ "10.0.0.0/8", "permit" },
157
		{ "10.0.0.0/16", "deny" },
157
		{ "10.0.0.0/16", "deny" },
158
		{ "10.0.0.0/24", "permit" },
158
		{ "10.0.0.0/24", "permit" },
159
	};
159
	};
160

    
   
160

   
161
	struct acl acl3[] = {
161
	struct acl acl3[] = {
162
		{ "::/0", "deny" },
162
		{ "::/0", "deny" },
163
		{ "fe80::/64", "permit" },
163
		{ "fe80::/64", "permit" },
164
	};
164
	};
165

    
   
165

   
166
	struct acl acl4[] = {
166
	struct acl acl4[] = {
167
		{ "::/0", "deny" },
167
		{ "::/0", "deny" },
168
		{ "fe80::/64", "permit" },
168
		{ "fe80::/64", "permit" },
169
		{ "fe80::ffff:0:0:0/80", "deny" },
169
		{ "fe80::ffff:0:0:0/80", "deny" },
170
		{ "fe80::ffff:0:ffff:0/112", "permit" },
170
		{ "fe80::ffff:0:ffff:0/112", "permit" },
171
	};
171
	};
172

    
   
172

   
173
	struct acl acl5[] = {
173
	struct acl acl5[] = {
174
		{ "0.0.0.0/0.0.0.0", "deny" },
174
		{ "0.0.0.0/0.0.0.0", "deny" },
175
		{ "10.0.0.0/255.0.0.0,192.168.0.0/255.255.255.0", "permit" },
175
		{ "10.0.0.0/255.0.0.0,192.168.0.0/255.255.255.0", "permit" },
176
	};
176
	};
177

    
   
177

   
178
	struct acl acl6[] = {
178
	struct acl acl6[] = {
179
		{ "10.0.0.0/8", "deny" },
179
		{ "10.0.0.0/8", "deny" },
180
		{ "10.0.0.0/8", "permit" },
180
		{ "10.0.0.0/8", "permit" },
181
		{ "10.0.0.0/16,!10.0.0.0/24", "deny" },
181
		{ "10.0.0.0/16,!10.0.0.0/24", "deny" },
182
	};
182
	};
183

    
   
183

   
184
	struct acl acl7[] = {
184
	struct acl acl7[] = {
185
		{ "::/0,!fe80::/64", "deny" },
185
		{ "::/0,!fe80::/64", "deny" },
186
		{ "fe80::ffff:0:0:0/80", "deny" },
186
		{ "fe80::ffff:0:0:0/80", "deny" },
187
		{ "fe80::ffff:0:ffff:0/112", "permit" },
187
		{ "fe80::ffff:0:ffff:0/112", "permit" },
188
	};
188
	};
189

    
   
189

   
190
	struct {
190
	struct {
191
		const char *test_address;
191
		const char *test_address;
192
		int v4_permitall_result;
192
		int v4_permitall_result;
193
		int v4_denyall_result;
193
		int v4_denyall_result;
194
		int v6_permitall_result;
194
		int v6_permitall_result;
195
		int v6_denyall_result;
195
		int v6_denyall_result;
196
		int acl1_result;
196
		int acl1_result;
197
		int acl2_result;
197
		int acl2_result;
198
		int acl3_result;
198
		int acl3_result;
199
		int acl4_result;
199
		int acl4_result;
200
		int acl5_result;
200
		int acl5_result;
201
		int acl6_result;
201
		int acl6_result;
202
		int acl7_result;
202
		int acl7_result;
203
	} acl_tests[] = {
203
	} acl_tests[] = {
204
		{ "10.1.1.5",                  TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A },
204
		{ "10.1.1.5",                  TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A },
205
		{ "192.168.0.5",               TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A },
205
		{ "192.168.0.5",               TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A },
206
		{ "192.168.1.5",               TACL_A, TACL_D, TACL_A, TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_D, TACL_A, TACL_A },
206
		{ "192.168.1.5",               TACL_A, TACL_D, TACL_A, TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_D, TACL_A, TACL_A },
207
		{ "10.0.0.1",                  TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A },
207
		{ "10.0.0.1",                  TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A },
208
		{ "10.0.10.10",                TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_D, TACL_A },
208
		{ "10.0.10.10",                TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_D, TACL_A },
209
		{ "172.16.0.1",                TACL_A, TACL_D, TACL_A, TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_D, TACL_A, TACL_A },
209
		{ "172.16.0.1",                TACL_A, TACL_D, TACL_A, TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_D, TACL_A, TACL_A },
210
		{ "fe80::1234",                TACL_A, TACL_A, TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A },
210
		{ "fe80::1234",                TACL_A, TACL_A, TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A },
211
		{ "fe80::ffff:1213:dead:beef", TACL_A, TACL_A, TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_D, TACL_A, TACL_A, TACL_D },
211
		{ "fe80::ffff:1213:dead:beef", TACL_A, TACL_A, TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_D, TACL_A, TACL_A, TACL_D },
212
		{ "fe80::ffff:0:ffff:ABCD",    TACL_A, TACL_A, TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A },
212
		{ "fe80::ffff:0:ffff:ABCD",    TACL_A, TACL_A, TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A },
213
	};
213
	};
214

    
   
214

   
215
	struct ast_ha *permit_hav4 = NULL;
215
	struct ast_ha *permit_hav4 = NULL;
216
	struct ast_ha *deny_hav4 = NULL;
216
	struct ast_ha *deny_hav4 = NULL;
217
	struct ast_ha *permit_hav6 = NULL;
217
	struct ast_ha *permit_hav6 = NULL;
218
	struct ast_ha *deny_hav6 = NULL;
218
	struct ast_ha *deny_hav6 = NULL;
219
	struct ast_ha *ha1 = NULL;
219
	struct ast_ha *ha1 = NULL;
220
	struct ast_ha *ha2 = NULL;
220
	struct ast_ha *ha2 = NULL;
221
	struct ast_ha *ha3 = NULL;
221
	struct ast_ha *ha3 = NULL;
222
	struct ast_ha *ha4 = NULL;
222
	struct ast_ha *ha4 = NULL;
223
	struct ast_ha *ha5 = NULL;
223
	struct ast_ha *ha5 = NULL;
224
	struct ast_ha *ha6 = NULL;
224
	struct ast_ha *ha6 = NULL;
225
	struct ast_ha *ha7 = NULL;
225
	struct ast_ha *ha7 = NULL;
226
	enum ast_test_result_state res = AST_TEST_PASS;
226
	enum ast_test_result_state res = AST_TEST_PASS;
227
	int err = 0;
227
	int err = 0;
228
	int i;
228
	int i;
229

    
   
229

   
230

    
   
230

   
231
	switch (cmd) {
231
	switch (cmd) {
232
	case TEST_INIT:
232
	case TEST_INIT:
233
		info->name = "acl";
233
		info->name = "acl";
234
		info->category = "/main/acl/";
234
		info->category = "/main/acl/";
235
		info->summary = "ACL unit test";
235
		info->summary = "ACL unit test";
236
		info->description =
236
		info->description =
237
			"Tests that hosts are properly permitted or denied";
237
			"Tests that hosts are properly permitted or denied";
238
		return AST_TEST_NOT_RUN;
238
		return AST_TEST_NOT_RUN;
239
	case TEST_EXECUTE:
239
	case TEST_EXECUTE:
240
		break;
240
		break;
241
	}
241
	}
242

    
   
242

   
243
	if (!(permit_hav4 = ast_append_ha(permitallv4.access, permitallv4.host, permit_hav4, &err))) {
243
	if (!(permit_hav4 = ast_append_ha(permitallv4.access, permitallv4.host, permit_hav4, &err))) {
244
		ast_test_status_update(test, "Failed to create permit_all ACL\n");
244
		ast_test_status_update(test, "Failed to create permit_all ACL\n");
245
		res = AST_TEST_FAIL;
245
		res = AST_TEST_FAIL;
246
		goto acl_cleanup;
246
		goto acl_cleanup;
247
	}
247
	}
248

    
   
248

   
249
	if (!(deny_hav4 = ast_append_ha(denyallv4.access, denyallv4.host, deny_hav4, &err))) {
249
	if (!(deny_hav4 = ast_append_ha(denyallv4.access, denyallv4.host, deny_hav4, &err))) {
250
		ast_test_status_update(test, "Failed to create deny_all ACL\n");
250
		ast_test_status_update(test, "Failed to create deny_all ACL\n");
251
		res = AST_TEST_FAIL;
251
		res = AST_TEST_FAIL;
252
		goto acl_cleanup;
252
		goto acl_cleanup;
253
	}
253
	}
254

    
   
254

   
255
	if (!(permit_hav6 = ast_append_ha(permitallv6.access, permitallv6.host, permit_hav6, &err))) {
255
	if (!(permit_hav6 = ast_append_ha(permitallv6.access, permitallv6.host, permit_hav6, &err))) {
256
		ast_test_status_update(test, "Failed to create permit_all ACL\n");
256
		ast_test_status_update(test, "Failed to create permit_all ACL\n");
257
		res = AST_TEST_FAIL;
257
		res = AST_TEST_FAIL;
258
		goto acl_cleanup;
258
		goto acl_cleanup;
259
	}
259
	}
260

    
   
260

   
261
	if (!(deny_hav6 = ast_append_ha(denyallv6.access, denyallv6.host, deny_hav6, &err))) {
261
	if (!(deny_hav6 = ast_append_ha(denyallv6.access, denyallv6.host, deny_hav6, &err))) {
262
		ast_test_status_update(test, "Failed to create deny_all ACL\n");
262
		ast_test_status_update(test, "Failed to create deny_all ACL\n");
263
		res = AST_TEST_FAIL;
263
		res = AST_TEST_FAIL;
264
		goto acl_cleanup;
264
		goto acl_cleanup;
265
	}
265
	}
266

    
   
266

   
267
	if (build_ha(acl1, ARRAY_LEN(acl1), &ha1, "ha1", &err, test, res) != 0) {
267
	if (build_ha(acl1, ARRAY_LEN(acl1), &ha1, "ha1", &err, test, &res) != 0) {
268
		goto acl_cleanup;
268
		goto acl_cleanup;
269
	}
269
	}
270

    
   
270

   
271
	if (build_ha(acl2, ARRAY_LEN(acl2), &ha2, "ha2", &err, test, res) != 0) {
271
	if (build_ha(acl2, ARRAY_LEN(acl2), &ha2, "ha2", &err, test, &res) != 0) {
272
		goto acl_cleanup;
272
		goto acl_cleanup;
273
	}
273
	}
274

    
   
274

   
275
	if (build_ha(acl3, ARRAY_LEN(acl3), &ha3, "ha3", &err, test, res) != 0) {
275
	if (build_ha(acl3, ARRAY_LEN(acl3), &ha3, "ha3", &err, test, &res) != 0) {
276
		goto acl_cleanup;
276
		goto acl_cleanup;
277
	}
277
	}
278

    
   
278

   
279
	if (build_ha(acl4, ARRAY_LEN(acl4), &ha4, "ha4", &err, test, res) != 0) {
279
	if (build_ha(acl4, ARRAY_LEN(acl4), &ha4, "ha4", &err, test, &res) != 0) {
280
		goto acl_cleanup;
280
		goto acl_cleanup;
281
	}
281
	}
282

    
   
282

   
283
	if (build_ha(acl5, ARRAY_LEN(acl5), &ha5, "ha5", &err, test, res) != 0) {
283
	if (build_ha(acl5, ARRAY_LEN(acl5), &ha5, "ha5", &err, test, &res) != 0) {
284
		goto acl_cleanup;
284
		goto acl_cleanup;
285
	}
285
	}
286

    
   
286

   
287
	if (build_ha(acl6, ARRAY_LEN(acl6), &ha6, "ha6", &err, test, res) != 0) {
287
	if (build_ha(acl6, ARRAY_LEN(acl6), &ha6, "ha6", &err, test, &res) != 0) {
288
		goto acl_cleanup;
288
		goto acl_cleanup;
289
	}
289
	}
290

    
   
290

   
291
	if (build_ha(acl7, ARRAY_LEN(acl7), &ha7, "ha7", &err, test, res) != 0) {
291
	if (build_ha(acl7, ARRAY_LEN(acl7), &ha7, "ha7", &err, test, &res) != 0) {
292
		goto acl_cleanup;
292
		goto acl_cleanup;
293
	}
293
	}
294

    
   
294

   
295
	for (i = 0; i < ARRAY_LEN(acl_tests); ++i) {
295
	for (i = 0; i < ARRAY_LEN(acl_tests); ++i) {
296
		struct ast_sockaddr addr;
296
		struct ast_sockaddr addr;
297
		int permit_resv4;
297
		int permit_resv4;
298
		int permit_resv6;
298
		int permit_resv6;
299
		int deny_resv4;
299
		int deny_resv4;
300
		int deny_resv6;
300
		int deny_resv6;
301
		int acl1_res;
301
		int acl1_res;
302
		int acl2_res;
302
		int acl2_res;
303
		int acl3_res;
303
		int acl3_res;
304
		int acl4_res;
304
		int acl4_res;
305
		int acl5_res;
305
		int acl5_res;
306
		int acl6_res;
306
		int acl6_res;
307
		int acl7_res;
307
		int acl7_res;
308

    
   
308

   
309
		ast_sockaddr_parse(&addr, acl_tests[i].test_address, PARSE_PORT_FORBID);
309
		ast_sockaddr_parse(&addr, acl_tests[i].test_address, PARSE_PORT_FORBID);
310

    
   
310

   
311
		permit_resv4 = ast_apply_ha(permit_hav4, &addr);
311
		permit_resv4 = ast_apply_ha(permit_hav4, &addr);
312
		deny_resv4 = ast_apply_ha(deny_hav4, &addr);
312
		deny_resv4 = ast_apply_ha(deny_hav4, &addr);
313
		permit_resv6 = ast_apply_ha(permit_hav6, &addr);
313
		permit_resv6 = ast_apply_ha(permit_hav6, &addr);
314
		deny_resv6 = ast_apply_ha(deny_hav6, &addr);
314
		deny_resv6 = ast_apply_ha(deny_hav6, &addr);
315
		acl1_res = ast_apply_ha(ha1, &addr);
315
		acl1_res = ast_apply_ha(ha1, &addr);
316
		acl2_res = ast_apply_ha(ha2, &addr);
316
		acl2_res = ast_apply_ha(ha2, &addr);
317
		acl3_res = ast_apply_ha(ha3, &addr);
317
		acl3_res = ast_apply_ha(ha3, &addr);
318
		acl4_res = ast_apply_ha(ha4, &addr);
318
		acl4_res = ast_apply_ha(ha4, &addr);
319
		acl5_res = ast_apply_ha(ha5, &addr);
319
		acl5_res = ast_apply_ha(ha5, &addr);
320
		acl6_res = ast_apply_ha(ha6, &addr);
320
		acl6_res = ast_apply_ha(ha6, &addr);
321
		acl7_res = ast_apply_ha(ha7, &addr);
321
		acl7_res = ast_apply_ha(ha7, &addr);
322

    
   
322

   
323
		if (permit_resv4 != acl_tests[i].v4_permitall_result) {
323
		if (permit_resv4 != acl_tests[i].v4_permitall_result) {
324
			ast_test_status_update(test, "Access not as expected to %s on permitallv4. Expected %d but "
324
			ast_test_status_update(test, "Access not as expected to %s on permitallv4. Expected %d but "
325
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].v4_permitall_result, permit_resv4);
325
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].v4_permitall_result, permit_resv4);
326
			res = AST_TEST_FAIL;
326
			res = AST_TEST_FAIL;
327
			goto acl_cleanup;
327
			goto acl_cleanup;
328
		}
328
		}
329

    
   
329

   
330
		if (deny_resv4 != acl_tests[i].v4_denyall_result) {
330
		if (deny_resv4 != acl_tests[i].v4_denyall_result) {
331
			ast_test_status_update(test, "Access not as expected to %s on denyallv4. Expected %d but "
331
			ast_test_status_update(test, "Access not as expected to %s on denyallv4. Expected %d but "
332
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].v4_denyall_result, deny_resv4);
332
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].v4_denyall_result, deny_resv4);
333
			res = AST_TEST_FAIL;
333
			res = AST_TEST_FAIL;
334
			goto acl_cleanup;
334
			goto acl_cleanup;
335
		}
335
		}
336

    
   
336

   
337
		if (permit_resv6 != acl_tests[i].v6_permitall_result) {
337
		if (permit_resv6 != acl_tests[i].v6_permitall_result) {
338
			ast_test_status_update(test, "Access not as expected to %s on permitallv6. Expected %d but "
338
			ast_test_status_update(test, "Access not as expected to %s on permitallv6. Expected %d but "
339
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].v6_permitall_result, permit_resv6);
339
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].v6_permitall_result, permit_resv6);
340
			res = AST_TEST_FAIL;
340
			res = AST_TEST_FAIL;
341
			goto acl_cleanup;
341
			goto acl_cleanup;
342
		}
342
		}
343

    
   
343

   
344
		if (deny_resv6 != acl_tests[i].v6_denyall_result) {
344
		if (deny_resv6 != acl_tests[i].v6_denyall_result) {
345
			ast_test_status_update(test, "Access not as expected to %s on denyallv6. Expected %d but "
345
			ast_test_status_update(test, "Access not as expected to %s on denyallv6. Expected %d but "
346
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].v6_denyall_result, deny_resv6);
346
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].v6_denyall_result, deny_resv6);
347
			res = AST_TEST_FAIL;
347
			res = AST_TEST_FAIL;
348
			goto acl_cleanup;
348
			goto acl_cleanup;
349
		}
349
		}
350

    
   
350

   
351
		if (acl1_res != acl_tests[i].acl1_result) {
351
		if (acl1_res != acl_tests[i].acl1_result) {
352
			ast_test_status_update(test, "Access not as expected to %s on acl1. Expected %d but "
352
			ast_test_status_update(test, "Access not as expected to %s on acl1. Expected %d but "
353
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].acl1_result, acl1_res);
353
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].acl1_result, acl1_res);
354
			res = AST_TEST_FAIL;
354
			res = AST_TEST_FAIL;
355
			goto acl_cleanup;
355
			goto acl_cleanup;
356
		}
356
		}
357

    
   
357

   
358
		if (acl2_res != acl_tests[i].acl2_result) {
358
		if (acl2_res != acl_tests[i].acl2_result) {
359
			ast_test_status_update(test, "Access not as expected to %s on acl2. Expected %d but "
359
			ast_test_status_update(test, "Access not as expected to %s on acl2. Expected %d but "
360
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].acl2_result, acl2_res);
360
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].acl2_result, acl2_res);
361
			res = AST_TEST_FAIL;
361
			res = AST_TEST_FAIL;
362
			goto acl_cleanup;
362
			goto acl_cleanup;
363
		}
363
		}
364

    
   
364

   
365
		if (acl3_res != acl_tests[i].acl3_result) {
365
		if (acl3_res != acl_tests[i].acl3_result) {
366
			ast_test_status_update(test, "Access not as expected to %s on acl3. Expected %d but "
366
			ast_test_status_update(test, "Access not as expected to %s on acl3. Expected %d but "
367
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].acl3_result, acl3_res);
367
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].acl3_result, acl3_res);
368
			res = AST_TEST_FAIL;
368
			res = AST_TEST_FAIL;
369
			goto acl_cleanup;
369
			goto acl_cleanup;
370
		}
370
		}
371

    
   
371

   
372
		if (acl4_res != acl_tests[i].acl4_result) {
372
		if (acl4_res != acl_tests[i].acl4_result) {
373
			ast_test_status_update(test, "Access not as expected to %s on acl4. Expected %d but "
373
			ast_test_status_update(test, "Access not as expected to %s on acl4. Expected %d but "
374
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].acl4_result, acl4_res);
374
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].acl4_result, acl4_res);
375
			res = AST_TEST_FAIL;
375
			res = AST_TEST_FAIL;
376
			goto acl_cleanup;
376
			goto acl_cleanup;
377
		}
377
		}
378

    
   
378

   
379
		if (acl5_res != acl_tests[i].acl5_result) {
379
		if (acl5_res != acl_tests[i].acl5_result) {
380
			ast_test_status_update(test, "Access not as expected to %s on acl5. Expected %d but "
380
			ast_test_status_update(test, "Access not as expected to %s on acl5. Expected %d but "
381
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].acl5_result, acl5_res);
381
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].acl5_result, acl5_res);
382
			res = AST_TEST_FAIL;
382
			res = AST_TEST_FAIL;
383
			goto acl_cleanup;
383
			goto acl_cleanup;
384
		}
384
		}
385

    
   
385

   
386
		if (acl6_res != acl_tests[i].acl6_result) {
386
		if (acl6_res != acl_tests[i].acl6_result) {
387
			ast_test_status_update(test, "Access not as expected to %s on acl6. Expected %d but "
387
			ast_test_status_update(test, "Access not as expected to %s on acl6. Expected %d but "
388
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].acl6_result, acl6_res);
388
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].acl6_result, acl6_res);
389
			res = AST_TEST_FAIL;
389
			res = AST_TEST_FAIL;
390
			goto acl_cleanup;
390
			goto acl_cleanup;
391
		}
391
		}
392

    
   
392

   
393
		if (acl7_res != acl_tests[i].acl7_result) {
393
		if (acl7_res != acl_tests[i].acl7_result) {
394
			ast_test_status_update(test, "Access not as expected to %s on acl7. Expected %d but "
394
			ast_test_status_update(test, "Access not as expected to %s on acl7. Expected %d but "
395
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].acl7_result, acl7_res);
395
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].acl7_result, acl7_res);
396
			res = AST_TEST_FAIL;
396
			res = AST_TEST_FAIL;
397
			goto acl_cleanup;
397
			goto acl_cleanup;
398
		}
398
		}
399
	}
399
	}
400

    
   
400

   
401
acl_cleanup:
401
acl_cleanup:
402
	if (permit_hav4) {
402
	if (permit_hav4) {
403
		ast_free_ha(permit_hav4);
403
		ast_free_ha(permit_hav4);
404
	}
404
	}
405
	if (deny_hav4) {
405
	if (deny_hav4) {
406
		ast_free_ha(deny_hav4);
406
		ast_free_ha(deny_hav4);
407
	}
407
	}
408
	if (permit_hav6) {
408
	if (permit_hav6) {
409
		ast_free_ha(permit_hav6);
409
		ast_free_ha(permit_hav6);
410
	}
410
	}
411
	if (deny_hav6) {
411
	if (deny_hav6) {
412
		ast_free_ha(deny_hav6);
412
		ast_free_ha(deny_hav6);
413
	}
413
	}
414
	if (ha1) {
414
	if (ha1) {
415
		ast_free_ha(ha1);
415
		ast_free_ha(ha1);
416
	}
416
	}
417
	if (ha2) {
417
	if (ha2) {
418
		ast_free_ha(ha2);
418
		ast_free_ha(ha2);
419
	}
419
	}
420
	if (ha3) {
420
	if (ha3) {
421
		ast_free_ha(ha3);
421
		ast_free_ha(ha3);
422
	}
422
	}
423
	if (ha4) {
423
	if (ha4) {
424
		ast_free_ha(ha4);
424
		ast_free_ha(ha4);
425
	}
425
	}
426
	if (ha5) {
426
	if (ha5) {
427
		ast_free_ha(ha5);
427
		ast_free_ha(ha5);
428
	}
428
	}
429
	if (ha6) {
429
	if (ha6) {
430
		ast_free_ha(ha6);
430
		ast_free_ha(ha6);
431
	}
431
	}
432
	if (ha7) {
432
	if (ha7) {
433
		ast_free_ha(ha7);
433
		ast_free_ha(ha7);
434
	}
434
	}
435
	return res;
435
	return res;
436
}
436
}
437

    
   
437

   
438
static int unload_module(void)
438
static int unload_module(void)
439
{
439
{
440
	AST_TEST_UNREGISTER(invalid_acl);
440
	AST_TEST_UNREGISTER(invalid_acl);
441
	AST_TEST_UNREGISTER(acl);
441
	AST_TEST_UNREGISTER(acl);
442
	return 0;
442
	return 0;
443
}
443
}
444

    
   
444

   
445
static int load_module(void)
445
static int load_module(void)
446
{
446
{
447
	AST_TEST_REGISTER(invalid_acl);
447
	AST_TEST_REGISTER(invalid_acl);
448
	AST_TEST_REGISTER(acl);
448
	AST_TEST_REGISTER(acl);
449
	return AST_MODULE_LOAD_SUCCESS;
449
	return AST_MODULE_LOAD_SUCCESS;
450
}
450
}
451

    
   
451

   
452
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "ACL test module");
452
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "ACL test module");
/branches/13/tests/test_linkedlists.c
Diff Revision 1 Diff Revision 8 - File Reverted
 
/branches/13/tests/test_stringfields.c
Diff Revision 1 Diff Revision 8
 
/branches/13/tests/test_strings.c
Diff Revision 1 Diff Revision 8
 
  1. /branches/13/tests/test_acl.c: Loading...
  2. /branches/13/tests/test_linkedlists.c: Loading...
  3. /branches/13/tests/test_stringfields.c: Loading...
  4. /branches/13/tests/test_strings.c: Loading...

https://reviewboard.asterisk.org/ runs on a server provided by Digium, Inc. and uses bandwidth donated to the open source Asterisk community by API Digital Communications in Huntsville, AL USA.
Please report problems with this site to asteriskteam@digium.com.