aboutsummaryrefslogtreecommitdiff
path: root/inet/inet6_opt.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2007-03-15 20:05:19 +0000
committerUlrich Drepper <drepper@redhat.com>2007-03-15 20:05:19 +0000
commit6cb988fa7b81cd5f850c3f31fbae318a1df63521 (patch)
tree26930174d009a8c58f2ed1b5f3e9f9ff089e09c6 /inet/inet6_opt.c
parent02c906999c8500a43005e47f5810883b3a5189d8 (diff)
downloadglibc-6cb988fa7b81cd5f850c3f31fbae318a1df63521.zip
glibc-6cb988fa7b81cd5f850c3f31fbae318a1df63521.tar.gz
glibc-6cb988fa7b81cd5f850c3f31fbae318a1df63521.tar.bz2
[BZ #4181]
2007-03-15 Jakub Jelinek <jakub@redhat.com> [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.
Diffstat (limited to 'inet/inet6_opt.c')
-rw-r--r--inet/inet6_opt.c36
1 files changed, 18 insertions, 18 deletions
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 <drepper@redhat.com>, 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;
}