summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorEric Faurot <eric@cvs.openbsd.org>2013-04-08 20:03:16 +0000
committerEric Faurot <eric@cvs.openbsd.org>2013-04-08 20:03:16 +0000
commit97212060ed0ff41cd21f2aff00102853480acf55 (patch)
tree54d56c9ef513bfbd475dff2891a584bcc1433361 /lib
parent50db18c72b639646633f9c610aea785786deda4e (diff)
Do not fail if the user buffer is too short to hold the packet: fill it up
to the given size and return the packet length. issue spotted by weerd@
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/asr/res_query.c20
-rw-r--r--lib/libc/asr/res_send.c11
2 files changed, 26 insertions, 5 deletions
diff --git a/lib/libc/asr/res_query.c b/lib/libc/asr/res_query.c
index b0c1cf159c8..7351c8750a5 100644
--- a/lib/libc/asr/res_query.c
+++ b/lib/libc/asr/res_query.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: res_query.c,v 1.1 2012/09/08 11:08:21 eric Exp $ */
+/* $OpenBSD: res_query.c,v 1.2 2013/04/08 20:03:15 eric Exp $ */
/*
* Copyright (c) 2012 Eric Faurot <eric@openbsd.org>
*
@@ -29,6 +29,7 @@ res_query(const char *name, int class, int type, u_char *ans, int anslen)
{
struct async *as;
struct async_res ar;
+ size_t len;
if (ans == NULL || anslen <= 0) {
h_errno = NO_RECOVERY;
@@ -36,7 +37,7 @@ res_query(const char *name, int class, int type, u_char *ans, int anslen)
return (-1);
}
- as = res_query_async(name, class, type, ans, anslen, NULL);
+ as = res_query_async(name, class, type, NULL, 0, NULL);
if (as == NULL) {
if (errno == EINVAL)
h_errno = NO_RECOVERY;
@@ -54,6 +55,12 @@ res_query(const char *name, int class, int type, u_char *ans, int anslen)
if (ar.ar_h_errno != NETDB_SUCCESS)
return (-1);
+ len = anslen;
+ if (ar.ar_datalen < len)
+ len = ar.ar_datalen;
+ memmove(ans, ar.ar_data, len);
+ free(ar.ar_data);
+
return (ar.ar_datalen);
}
@@ -62,6 +69,7 @@ res_search(const char *name, int class, int type, u_char *ans, int anslen)
{
struct async *as;
struct async_res ar;
+ size_t len;
if (ans == NULL || anslen <= 0) {
h_errno = NO_RECOVERY;
@@ -69,7 +77,7 @@ res_search(const char *name, int class, int type, u_char *ans, int anslen)
return (-1);
}
- as = res_search_async(name, class, type, ans, anslen, NULL);
+ as = res_search_async(name, class, type, NULL, 0, NULL);
if (as == NULL) {
if (errno == EINVAL)
h_errno = NO_RECOVERY;
@@ -87,5 +95,11 @@ res_search(const char *name, int class, int type, u_char *ans, int anslen)
if (ar.ar_h_errno != NETDB_SUCCESS)
return (-1);
+ len = anslen;
+ if (ar.ar_datalen < len)
+ len = ar.ar_datalen;
+ memmove(ans, ar.ar_data, len);
+ free(ar.ar_data);
+
return (ar.ar_datalen);
}
diff --git a/lib/libc/asr/res_send.c b/lib/libc/asr/res_send.c
index 77d1a69c1ed..d1379c6a67b 100644
--- a/lib/libc/asr/res_send.c
+++ b/lib/libc/asr/res_send.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: res_send.c,v 1.1 2012/09/08 11:08:21 eric Exp $ */
+/* $OpenBSD: res_send.c,v 1.2 2013/04/08 20:03:15 eric Exp $ */
/*
* Copyright (c) 2012 Eric Faurot <eric@openbsd.org>
*
@@ -29,13 +29,14 @@ res_send(const u_char *buf, int buflen, u_char *ans, int anslen)
{
struct async *as;
struct async_res ar;
+ size_t len;
if (ans == NULL || anslen <= 0) {
errno = EINVAL;
return (-1);
}
- as = res_send_async(buf, buflen, ans, anslen, NULL);
+ as = res_send_async(buf, buflen, NULL, 0, NULL);
if (as == NULL)
return (-1); /* errno set */
@@ -46,5 +47,11 @@ res_send(const u_char *buf, int buflen, u_char *ans, int anslen)
return (-1);
}
+ len = anslen;
+ if (ar.ar_datalen < len)
+ len = ar.ar_datalen;
+ memmove(ans, ar.ar_data, len);
+ free(ar.ar_data);
+
return (ar.ar_datalen);
}