From 6cb988fa7b81cd5f850c3f31fbae318a1df63521 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Thu, 15 Mar 2007 20:05:19 +0000 Subject: [BZ #4181] 2007-03-15 Jakub Jelinek [BZ #4181] * inet/inet6_opt.c (add_padding): Only insert padding if npad > 0. (inet6_opt_append): Don't check extlen is big enough if extbuf is NULL. (inet6_opt_finish): Likewise. * inet/Makefile (tests): Add test-inet6_opt. * inet/test-inet6_opt.c: New test. * sysdeps/unix/sysv/linux/ifaddrs.c (__netlink_request): Never reallocate the buffer, instead fail for MSG_TRUNC or for EBUSY NLMSG_ERR. Instead use a page sized buffer. * sysdeps/unix/sysv/linux/check_pf.c (make_request): Use page sized buffer. --- inet/inet6_opt.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'inet/inet6_opt.c') diff --git a/inet/inet6_opt.c b/inet/inet6_opt.c index bddb851..17d3fee 100644 --- a/inet/inet6_opt.c +++ b/inet/inet6_opt.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2006 Free Software Foundation, Inc. +/* Copyright (C) 2006, 2007 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper , 2006. @@ -51,7 +51,7 @@ add_padding (uint8_t *extbuf, int offset, int npad) { if (npad == 1) extbuf[offset] = IP6OPT_PAD1; - else + else if (npad > 0) { struct ip6_opt *pad_opt = (struct ip6_opt *) (extbuf + offset); @@ -102,21 +102,17 @@ inet6_opt_append (void *extbuf, socklen_t extlen, int offset, uint8_t type, int data_offset = offset + sizeof (struct ip6_opt); int npad = (align - data_offset % align) & (align - 1); - /* Now we can check whether the buffer is large enough. */ - if (data_offset + npad + len > extlen) - return -1; - - if (npad != 0) + if (extbuf != NULL) { - if (extbuf != NULL) - add_padding (extbuf, offset, npad); + /* Now we can check whether the buffer is large enough. */ + if (data_offset + npad + len > extlen) + return -1; + + add_padding (extbuf, offset, npad); offset += npad; - } - /* Now prepare the option itself. */ - if (extbuf != NULL) - { + /* Now prepare the option itself. */ struct ip6_opt *opt = (struct ip6_opt *) ((uint8_t *) extbuf + offset); opt->ip6o_type = type; @@ -124,6 +120,8 @@ inet6_opt_append (void *extbuf, socklen_t extlen, int offset, uint8_t type, *databufp = opt + 1; } + else + offset += npad; return offset + sizeof (struct ip6_opt) + len; } @@ -145,12 +143,14 @@ inet6_opt_finish (void *extbuf, socklen_t extlen, int offset) /* Required padding at the end. */ int npad = (8 - (offset & 7)) & 7; - /* Make sure the buffer is large enough. */ - if (offset + npad > extlen) - return -1; - if (extbuf != NULL) - add_padding (extbuf, offset, npad); + { + /* Make sure the buffer is large enough. */ + if (offset + npad > extlen) + return -1; + + add_padding (extbuf, offset, npad); + } return offset + npad; } -- cgit v1.1