• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // dn_expand should handle offset pointer to 0 byte
2 #define _DEFAULT_SOURCE 1
3 #define _BSD_SOURCE 1
4 #include <resolv.h>
5 #include <string.h>
6 #include "test.h"
7 
main(void)8 int main(void)
9 {
10 	unsigned char packet[] = {2,'p','q',0xc0,5,0};
11 	char name[] = "XXXX";
12 	int r;
13 
14 	/* non-empty name with pointer to 0 */
15 	r = dn_expand(packet, packet+6, packet, name, 3);
16 	if (r!=5)
17 		t_error("dn_expand(\"\\2pq\\xc0\\5\", name, 3) returned %d, wanted 5\n", r);
18 	if (strcmp(name, "pq"))
19 		t_error("dn_expand(\"\\2pq\\xc0\\5\", name, 3) failed: got \"%s\" name, wanted \"pq\"\n", name);
20 
21 	/* empty name with pointer to 0 */
22 	memcpy(packet, "\xc0\2", 3);
23 	memcpy(name, "XXXX", 5);
24 	r = dn_expand(packet, packet+3, packet, name, 1);
25 	if (r!=2)
26 		t_error("dn_expand(\"\\xc0\\2\", name, 1) returned %d, wanted 2\n", r);
27 	if (name[0])
28 		t_error("dn_expand(\"\\xc0\\2\", name, 1) failed: got \"%s\" name, wanted \"\"\n", name);
29 
30 	return t_status;
31 }
32