aboutsummaryrefslogtreecommitdiff
path: root/inet
diff options
context:
space:
mode:
Diffstat (limited to 'inet')
-rw-r--r--inet/Makefile4
-rw-r--r--inet/inet6_rth.c5
-rw-r--r--inet/tst-inet6_rth.c36
3 files changed, 42 insertions, 3 deletions
diff --git a/inet/Makefile b/inet/Makefile
index 16b2aae..3798594 100644
--- a/inet/Makefile
+++ b/inet/Makefile
@@ -1,4 +1,4 @@
-# Copyright (C) 1991-2006, 2007 Free Software Foundation, Inc.
+# Copyright (C) 1991-2006, 2007, 2009 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
# The GNU C Library is free software; you can redistribute it and/or
@@ -53,7 +53,7 @@ aux := check_pf check_native ifreq
tests := htontest test_ifindex tst-ntoa tst-ether_aton tst-network \
tst-gethnm test-ifaddrs bug-if1 test-inet6_opt tst-ether_line \
- tst-getni1 tst-getni2
+ tst-getni1 tst-getni2 tst-inet6_rth
include ../Rules
diff --git a/inet/inet6_rth.c b/inet/inet6_rth.c
index 15f8240..e0fad33 100644
--- a/inet/inet6_rth.c
+++ b/inet/inet6_rth.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2006 Free Software Foundation, Inc.
+/* Copyright (C) 2006, 2009 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2006.
@@ -93,6 +93,9 @@ inet6_rth_add (void *bp, const struct in6_addr *addr)
struct ip6_rthdr0 *rthdr0;
case IPV6_RTHDR_TYPE_0:
rthdr0 = (struct ip6_rthdr0 *) rthdr;
+ if (rthdr0->ip6r0_len * 8 / sizeof (struct in6_addr)
+ - rthdr0->ip6r0_segleft < 1)
+ return -1;
memcpy (&rthdr0->ip6r0_addr[rthdr0->ip6r0_segleft++],
addr, sizeof (struct in6_addr));
diff --git a/inet/tst-inet6_rth.c b/inet/tst-inet6_rth.c
new file mode 100644
index 0000000..454a13f
--- /dev/null
+++ b/inet/tst-inet6_rth.c
@@ -0,0 +1,36 @@
+#include <stdio.h>
+#include <netinet/ip6.h>
+
+static int
+do_test (void)
+{
+ int res = 0;
+ char buf[1000];
+ void *p = inet6_rth_init (buf, 24, IPV6_RTHDR_TYPE_0, 0);
+ if (p == NULL)
+ {
+ puts ("first inet6_rth_init failed");
+ res = 1;
+ }
+ else if (inet6_rth_add (p, &in6addr_any) == 0)
+ {
+ puts ("first inet6_rth_add succeeded");
+ res = 1;
+ }
+
+ p = inet6_rth_init (buf, 24, IPV6_RTHDR_TYPE_0, 1);
+ if (p == NULL)
+ {
+ puts ("second inet6_rth_init failed");
+ res = 1;
+ }
+ else if (inet6_rth_add (p, &in6addr_any) != 0)
+ {
+ puts ("second inet6_rth_add failed");
+ res = 1;
+ }
+ return res;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"