]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - inet/inet6_rth.c
Prefer https to http for gnu.org and fsf.org URLs
[thirdparty/glibc.git] / inet / inet6_rth.c
index 15f824090945df2ba23d2d4bf7e7593fc2e32d99..c6b1efe38dfa66bd60c6177f290093d449d07d25 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2006 Free Software Foundation, Inc.
+/* Copyright (C) 2006-2019 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@redhat.com>, 2006.
 
@@ -13,9 +13,8 @@
    Lesser General Public License for more details.
 
    You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
 
 #include <string.h>
 #include <netinet/in.h>
@@ -93,6 +92,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));
@@ -127,7 +129,7 @@ inet6_rth_reverse (const void *in, void *out)
       /* Copy header, not the addresses.  The memory regions can overlap.  */
       memmove (out_rthdr0, in_rthdr0, sizeof (struct ip6_rthdr0));
 
-      int total = in_rthdr0->ip6r0_segleft * 8 / sizeof (struct in6_addr);
+      int total = in_rthdr0->ip6r0_len * 8 / sizeof (struct in6_addr);
       for (int i = 0; i < total / 2; ++i)
        {
          /* Remember, IN_RTHDR0 and OUT_RTHDR0 might overlap.  */
@@ -138,6 +140,8 @@ inet6_rth_reverse (const void *in, void *out)
       if (total % 2 != 0 && in != out)
        out_rthdr0->ip6r0_addr[total / 2] = in_rthdr0->ip6r0_addr[total / 2];
 
+      out_rthdr0->ip6r0_segleft = total;
+
       return 0;
     }