1 // RUN: %clangxx %s -o %t && %run %t %p
2 
3 #include <assert.h>
4 #include <resolv.h>
5 #include <string.h>
6 
7 #include <sanitizer/msan_interface.h>
8 
9 void testWrite() {
10   char unsigned input[] = {0xff, 0xc5, 0xf7, 0xff, 0x00, 0x00, 0xff, 0x0a, 0x00,
11                            0x00, 0x00, 0x01, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00,
12                            0x10, 0x01, 0x05, 0x00, 0x01, 0x0a, 0x67, 0x6f, 0x6f,
13                            0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x00};
14   char output[1024];
15 
16   int res = dn_expand(input, input + sizeof(input), input + 23, output,
17                       sizeof(output));
18 
19   assert(res == 12);
20   assert(strcmp(output, "google\\.com") == 0);
21 }
22 
23 void testWriteZeroLength() {
24   char unsigned input[] = {
25       0xff, 0xc5, 0xf7, 0xff, 0x00, 0x00, 0xff, 0x0a, 0x00, 0x00, 0x00, 0x01,
26       0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x10, 0x01, 0x05, 0x00, 0x01, 0x00,
27   };
28   char output[1024];
29 
30   int res = dn_expand(input, input + sizeof(input), input + 23, output,
31                       sizeof(output));
32 
33   assert(res == 1);
34   assert(strcmp(output, "") == 0);
35 }
36 
37 int main(int iArgc, const char *szArgv[]) {
38   testWrite();
39   testWriteZeroLength();
40 
41   return 0;
42 }
43