From d643f9eb7daeafe25ff81dcd2d4f239803823940 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Thu, 4 Sep 2014 20:51:24 +0200 Subject: [PATCH] separate dn_expand regression tests for empty name and pointer to 0 --- src/regression/dn_expand-empty.c | 13 ++----------- src/regression/dn_expand-ptr-0.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 src/regression/dn_expand-ptr-0.c diff --git a/src/regression/dn_expand-empty.c b/src/regression/dn_expand-empty.c index b7287d8..8ff2670 100644 --- a/src/regression/dn_expand-empty.c +++ b/src/regression/dn_expand-empty.c @@ -5,8 +5,8 @@ int main(void) { - unsigned char packet[3] = ""; - char name[] = "x"; + unsigned char packet[] = ""; + char name[] = "XX"; int r; /* empty name in packet */ @@ -16,14 +16,5 @@ int main(void) if (name[0]) t_error("dn_expand(\"\", name, 1) failed: got \"%s\" name, wanted \"\"\n", name); - /* empty name with offset pointer in packet */ - memcpy(packet, "\xc0\2", 3); - name[0] = 'x'; - r = dn_expand(packet, packet+3, packet, name, 1); - if (r!=2) - t_error("dn_expand(\"\\xc0\\2\", name, 1) returned %d, wanted 1\n", r); - if (name[0]) - t_error("dn_expand(\"\\xc0\\2\", name, 1) failed: got \"%s\" name, wanted \"\"\n", name); - return t_status; } diff --git a/src/regression/dn_expand-ptr-0.c b/src/regression/dn_expand-ptr-0.c new file mode 100644 index 0000000..beca2d3 --- /dev/null +++ b/src/regression/dn_expand-ptr-0.c @@ -0,0 +1,30 @@ +// dn_expand should handle offset pointer to 0 byte +#define _BSD_SOURCE +#include +#include +#include "test.h" + +int main(void) +{ + unsigned char packet[] = {2,'p','q',0xc0,5,0}; + char name[] = "XXXX"; + int r; + + /* non-empty name with pointer to 0 */ + r = dn_expand(packet, packet+6, packet, name, 3); + if (r!=5) + t_error("dn_expand(\"\\2pq\\xc0\\5\", name, 3) returned %d, wanted 5\n", r); + if (strcmp(name, "pq")) + t_error("dn_expand(\"\\2pq\\xc0\\5\", name, 3) failed: got \"%s\" name, wanted \"pq\"\n", name); + + /* empty name with pointer to 0 */ + memcpy(packet, "\xc0\2", 3); + memcpy(name, "XXXX", 5); + r = dn_expand(packet, packet+3, packet, name, 1); + if (r!=2) + t_error("dn_expand(\"\\xc0\\2\", name, 1) returned %d, wanted 2\n", r); + if (name[0]) + t_error("dn_expand(\"\\xc0\\2\", name, 1) failed: got \"%s\" name, wanted \"\"\n", name); + + return t_status; +} -- 2.11.4.GIT