@@ -257,7 +257,16 @@ void strings(void **state)
257
257
}
258
258
}
259
259
260
- static int32_t name_test_accept_rr (
260
+ struct names_test {
261
+ const char * input ;
262
+ int32_t code ;
263
+ struct {
264
+ size_t length ;
265
+ const uint8_t * octets ;
266
+ } owner ;
267
+ };
268
+
269
+ static int32_t names_callback (
261
270
zone_parser_t * parser ,
262
271
const zone_name_t * owner ,
263
272
uint16_t type ,
@@ -267,14 +276,20 @@ static int32_t name_test_accept_rr(
267
276
const uint8_t * rdata ,
268
277
void * user_data )
269
278
{
279
+ struct names_test * test = (struct names_test * )user_data ;
280
+
270
281
(void )parser ;
271
282
(void )owner ;
272
283
(void )type ;
273
284
(void )class ;
274
285
(void )ttl ;
275
286
(void )rdlength ;
276
287
(void )rdata ;
277
- (void )user_data ;
288
+
289
+ if (owner -> length != test -> owner .length )
290
+ return ZONE_SYNTAX_ERROR ;
291
+ if (memcmp (owner -> octets , test -> owner .octets , owner -> length ) != 0 )
292
+ return ZONE_SYNTAX_ERROR ;
278
293
return 0 ;
279
294
}
280
295
@@ -322,20 +337,36 @@ void names(void **state)
322
337
static const char last_label_is_null [] = "foo.." ;
323
338
static const char first_label_is_null [] = "..foo" ;
324
339
325
- static const struct {
326
- const char * input ;
327
- int32_t code ;
328
- } tests [] = {
329
- { only_rel_label_too_long , ZONE_SYNTAX_ERROR },
330
- { only_abs_label_too_long , ZONE_SYNTAX_ERROR },
331
- { first_label_too_long , ZONE_SYNTAX_ERROR },
332
- { last_rel_label_too_long , ZONE_SYNTAX_ERROR },
333
- { last_abs_label_too_long , ZONE_SYNTAX_ERROR },
334
- { rel_name_too_long , ZONE_SYNTAX_ERROR },
335
- { abs_name_too_long , ZONE_SYNTAX_ERROR },
336
- { only_null_labels , ZONE_SYNTAX_ERROR },
337
- { last_label_is_null , ZONE_SYNTAX_ERROR },
338
- { first_label_is_null , ZONE_SYNTAX_ERROR }
340
+ static const uint8_t owner_abs_0 [] = { 1 , 0 , 0 };
341
+ static const uint8_t owner_abs_spc [] = { 1 , ' ' , 0 };
342
+ static const uint8_t owner_abs_0foo [] = { 4 , 0 , 'f' , 'o' , 'o' , 0 };
343
+ static const uint8_t owner_abs_00foo [] = { 5 , 0 , 0 , 'f' , 'o' , 'o' , 0 };
344
+ static const uint8_t owner_abs_foo0 [] = { 4 , 'f' , 'o' , 'o' , 0 , 0 };
345
+ static const uint8_t owner_abs_foo00 [] = { 5 , 'f' , 'o' , 'o' , 0 , 0 , 0 };
346
+ static const uint8_t owner_abs_foodot [] = { 4 , 'f' , 'o' , 'o' , '.' , 0 };
347
+ static const uint8_t owner_rel_foodot [] = { 4 , 'f' , 'o' , 'o' , '.' , 3 , 'f' , 'o' , 'o' , 0 };
348
+
349
+ static struct names_test tests [] = {
350
+ { only_rel_label_too_long , ZONE_SYNTAX_ERROR , { 0 , NULL } },
351
+ { only_abs_label_too_long , ZONE_SYNTAX_ERROR , { 0 , NULL } },
352
+ { first_label_too_long , ZONE_SYNTAX_ERROR , { 0 , NULL } },
353
+ { last_rel_label_too_long , ZONE_SYNTAX_ERROR , { 0 , NULL } },
354
+ { last_abs_label_too_long , ZONE_SYNTAX_ERROR , { 0 , NULL } },
355
+ { rel_name_too_long , ZONE_SYNTAX_ERROR , { 0 , NULL } },
356
+ { abs_name_too_long , ZONE_SYNTAX_ERROR , { 0 , NULL } },
357
+ { only_null_labels , ZONE_SYNTAX_ERROR , { 0 , NULL } },
358
+ { last_label_is_null , ZONE_SYNTAX_ERROR , { 0 , NULL } },
359
+ { first_label_is_null , ZONE_SYNTAX_ERROR , { 0 , NULL } },
360
+ { "\\0." , ZONE_SYNTAX_ERROR , { 0 , NULL } },
361
+ { "\\00." , ZONE_SYNTAX_ERROR , { 0 , NULL } },
362
+ { "\\000." , 0 , { 3 , owner_abs_0 } },
363
+ { "\\ ." , 0 , { 3 , owner_abs_spc } },
364
+ { "\\000foo. " , 0 , { 6 , owner_abs_0foo } },
365
+ { "\\000\\000foo." , 0 , { 7 , owner_abs_00foo } },
366
+ { "foo\\000." , 0 , { 6 , owner_abs_foo0 } },
367
+ { "foo\\000\\000." , 0 , { 7 , owner_abs_foo00 } },
368
+ { "foo\\.." , 0 , { 6 , owner_abs_foodot } },
369
+ { "foo\\." , 0 , { 10 , owner_rel_foodot } }
339
370
};
340
371
341
372
static const uint8_t origin [] = { 3 , 'f' , 'o' , 'o' , 0 };
@@ -353,14 +384,14 @@ void names(void **state)
353
384
(void )snprintf (input , sizeof (input ), "%s A 192.168.0.1" , tests [i ].input );
354
385
length = strlen (input );
355
386
356
- options .accept .callback = name_test_accept_rr ;
387
+ options .accept .callback = names_callback ;
357
388
options .origin .octets = origin ;
358
389
options .origin .length = sizeof (origin );
359
390
options .default_ttl = 3600 ;
360
391
options .default_class = ZONE_IN ;
361
392
362
393
fprintf (stderr , "INPUT: '%s'\n" , input );
363
- code = zone_parse_string (& parser , & options , & buffers , input , length , NULL );
394
+ code = zone_parse_string (& parser , & options , & buffers , input , length , & tests [ i ] );
364
395
assert_int_equal (code , tests [i ].code );
365
396
}
366
397
}
0 commit comments