summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2008-01-08 07:12:41 +0000
committerMike Frysinger <vapier@gentoo.org>2008-01-08 07:12:41 +0000
commitb4937a448bcd897c84de6abb36c39eff492a2b91 (patch)
treec753f856a245829f7fd0a06cebbf27b0763d4e27
parent2df8aa78d59ab5709e91235b7779456b86830327 (diff)
test to make sure the buffers used by the gethost*_r functions handle misaligned scratch buffers
-rw-r--r--test/inet/gethost_r-align.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/test/inet/gethost_r-align.c b/test/inet/gethost_r-align.c
new file mode 100644
index 000000000..53ce93acd
--- /dev/null
+++ b/test/inet/gethost_r-align.c
@@ -0,0 +1,50 @@
+/* Since the reentrant gethost functions take a char * buffer,
+ * we have to make sure they internally do not assume alignment.
+ * The actual return values are not relevant. If the test fails,
+ * it'll be due to an alignment exception which means the test
+ * app is killed by the kernel.
+ */
+
+#include <errno.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <arpa/inet.h>
+#include <sys/socket.h>
+
+int main(int argc, char *argv[])
+{
+ size_t i;
+ char buf[1024];
+ in_addr_t addr;
+
+ addr = inet_addr("127.0.0.1");
+
+ for (i = 0; i < sizeof(size_t) * 2; ++i) {
+ struct hostent hent, *hentres;
+ int ret, herr;
+
+ printf("Testing misalignment of %2zi bytes: ", i);
+
+ memset(&hent, 0x00, sizeof(hent));
+ ret = gethostent_r(&hent, buf + i, sizeof(buf) - i, &hentres, &herr);
+ printf("%sgethostent_r() ", (ret ? "!!!" : ""));
+
+ memset(&hent, 0x00, sizeof(hent));
+ ret = gethostbyname_r("localhost", &hent, buf + i, sizeof(buf) - i, &hentres, &herr);
+ printf("%sgethostbyname_r() ", (ret ? "!!!" : ""));
+
+ memset(&hent, 0x00, sizeof(hent));
+ ret = gethostbyname2_r("localhost", AF_INET, &hent, buf + i, sizeof(buf) - i, &hentres, &herr);
+ printf("%sgethostbyname2_r() ", (ret ? "!!!" : ""));
+
+ memset(&hent, 0x00, sizeof(hent));
+ ret = gethostbyaddr_r(&addr, sizeof(addr), AF_INET, &hent, buf + i, sizeof(buf) - i, &hentres, &herr);
+ printf("%sgethostbyaddr_r() ", (ret ? "!!!" : ""));
+
+ puts("OK!");
+ }
+
+ return 0;
+}