Changeset 955135
- Timestamp:
- 02/10/09 19:10:40 (3 years ago)
- Branches:
- master
- Children:
- 1cdba3
- Parents:
- b6fc3f
- git-author:
- Erik Ekman <yarrick@…> (02/10/09 19:10:40)
- git-committer:
- Erik Ekman <erik@…> (02/04/12 20:34:00)
- File:
-
- 1 edited
-
tests/read.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tests/read.c
r0836ad r955135 84 84 END_TEST 85 85 86 START_TEST(test_read_name )86 START_TEST(test_read_name_empty_loop) 87 87 { 88 88 unsigned char emptyloop[] = { 89 89 'A', 'A', 0x81, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 90 90 0xc0, 0x0c, 0x00, 0x01, 0x00, 0x01 }; 91 char buf[1024]; 92 char *data; 93 int rv; 94 95 memset(buf, 0, sizeof(buf)); 96 data = (char*) emptyloop + sizeof(HEADER); 97 buf[1023] = 'A'; 98 rv = readname((char *) emptyloop, sizeof(emptyloop), &data, buf, 1023); 99 fail_unless(buf[1023] == 'A'); 100 } 101 END_TEST 102 103 START_TEST(test_read_name_inf_loop) 104 { 91 105 unsigned char infloop[] = { 92 106 'A', 'A', 0x81, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 93 107 0x01, 'A', 0xc0, 0x0c, 0x00, 0x01, 0x00, 0x01 }; 108 char buf[1024]; 109 char *data; 110 int rv; 111 112 memset(buf, 0, sizeof(buf)); 113 data = (char*) infloop + sizeof(HEADER); 114 buf[4] = '\a'; 115 rv = readname((char*) infloop, sizeof(infloop), &data, buf, 4); 116 fail_unless(buf[4] == '\a'); 117 } 118 END_TEST 119 120 START_TEST(test_read_name_longname) 121 { 94 122 unsigned char longname[] = 95 123 "AA\x81\x80\x00\x01\x00\x00\x00\x00\x00\x00" … … 101 129 "\x3FzBCDEFGHIJKLMNOPQURSTUVXYZ0123456789abcdefghijklmnopqrstuvxyzAA" 102 130 "\x00\x00\x01\x00\x01"; 131 char buf[1024]; 132 char *data; 133 int rv; 134 135 memset(buf, 0, sizeof(buf)); 136 data = (char*) longname + sizeof(HEADER); 137 buf[256] = '\a'; 138 rv = readname((char*) longname, sizeof(longname), &data, buf, 256); 139 fail_unless(buf[256] == '\a'); 140 } 141 END_TEST 142 143 START_TEST(test_read_name_onejump) 144 { 103 145 unsigned char onejump[] = 104 146 "AA\x81\x80\x00\x01\x00\x00\x00\x00\x00\x00" 105 147 "\x02hh\xc0\x15\x00\x01\x00\x01\x05zBCDE\x00"; 106 unsigned char badjump[] = { 107 'A', 'A', 0x81, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 108 0xfe, 0xcc, 0x00, 0x01, 0x00, 0x01 }; 109 unsigned char badjump2[] = { 110 'A', 'A', 0x81, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 111 0x02, 'B', 'A', 0xfe, 0xcc, 0x00, 0x01, 0x00, 0x01 }; 112 unsigned char *jumper; 113 char buf[1024]; 114 char *data; 115 int rv; 116 117 memset(buf, 0, sizeof(buf)); 118 data = (char*) emptyloop + sizeof(HEADER); 119 buf[1023] = 'A'; 120 rv = readname((char *) emptyloop, sizeof(emptyloop), &data, buf, 1023); 121 fail_unless(buf[1023] == 'A', NULL); 122 123 memset(buf, 0, sizeof(buf)); 124 data = (char*) infloop + sizeof(HEADER); 125 buf[4] = '\a'; 126 rv = readname((char*) infloop, sizeof(infloop), &data, buf, 4); 127 fail_unless(buf[4] == '\a', NULL); 128 129 memset(buf, 0, sizeof(buf)); 130 data = (char*) longname + sizeof(HEADER); 131 buf[256] = '\a'; 132 rv = readname((char*) longname, sizeof(longname), &data, buf, 256); 133 fail_unless(buf[256] == '\a', NULL); 148 char buf[1024]; 149 char *data; 150 int rv; 134 151 135 152 memset(buf, 0, sizeof(buf)); 136 153 data = (char*) onejump + sizeof(HEADER); 137 154 rv = readname((char*) onejump, sizeof(onejump), &data, buf, 256); 138 fail_unless(rv == 9, NULL); 139 140 /* These two tests use malloc to cause segfault if jump is executed */ 155 fail_unless(rv == 9); 156 } 157 END_TEST 158 159 START_TEST(test_read_name_badjump_start) 160 { 161 unsigned char badjump[] = { 162 'A', 'A', 0x81, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 163 0xfe, 0xcc, 0x00, 0x01, 0x00, 0x01 }; 164 unsigned char *jumper; 165 char buf[1024]; 166 char *data; 167 int rv; 168 169 /* This test uses malloc to cause segfault if jump is executed */ 141 170 memset(buf, 0, sizeof(buf)); 142 171 jumper = malloc(sizeof(badjump)); … … 146 175 rv = readname((char*) jumper, sizeof(badjump), &data, buf, 256); 147 176 148 fail_unless(rv == 0 , NULL);149 fail_unless(buf[0] == 0 , NULL);177 fail_unless(rv == 0); 178 fail_unless(buf[0] == 0); 150 179 } 151 180 free(jumper); 152 181 } 182 END_TEST 183 184 START_TEST(test_read_name_badjump_second) 185 { 186 unsigned char badjump2[] = { 187 'A', 'A', 0x81, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 188 0x02, 'B', 'A', 0xfe, 0xcc, 0x00, 0x01, 0x00, 0x01 }; 189 unsigned char *jumper; 190 char buf[1024]; 191 char *data; 192 int rv; 193 194 /* This test uses malloc to cause segfault if jump is executed */ 153 195 memset(buf, 0, sizeof(buf)); 154 196 jumper = malloc(sizeof(badjump2)); … … 158 200 rv = readname((char*) jumper, sizeof(badjump2), &data, buf, 256); 159 201 160 fail_unless(rv == 4 , NULL);202 fail_unless(rv == 4); 161 203 fail_unless(strcmp("BA.", buf) == 0, 162 204 "buf is not BA: %s", buf); … … 181 223 ret = putname(&b, 256, domain); 182 224 183 fail_unless(ret == strlen(domain) + 1 , NULL);225 fail_unless(ret == strlen(domain) + 1); 184 226 fail_unless(strncmp(buf, out, ret) == 0, "Happy flow failed"); 185 227 } … … 202 244 ret = putname(&b, 256, nodot); 203 245 204 fail_unless(ret == -1 , NULL);205 fail_unless(b == buf , NULL);246 fail_unless(ret == -1); 247 fail_unless(b == buf); 206 248 } 207 249 END_TEST … … 227 269 ret = putname(&b, 256, toolong); 228 270 229 fail_unless(ret == -1 , NULL);230 fail_unless(b == buf , NULL);271 fail_unless(ret == -1); 272 fail_unless(b == buf); 231 273 } 232 274 END_TEST … … 242 284 tcase_add_test(tc, test_read_putshort); 243 285 tcase_add_test(tc, test_read_putlong); 244 tcase_add_test(tc, test_read_name); 286 tcase_add_test(tc, test_read_name_empty_loop); 287 tcase_add_test(tc, test_read_name_inf_loop); 288 tcase_add_test(tc, test_read_name_longname); 289 tcase_add_test(tc, test_read_name_onejump); 290 tcase_add_test(tc, test_read_name_badjump_start); 291 tcase_add_test(tc, test_read_name_badjump_second); 245 292 tcase_add_test(tc, test_putname); 246 293 tcase_add_test(tc, test_putname_nodot);
Note: See TracChangeset
for help on using the changeset viewer.
