| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: ip6opt.c,v 1.14 2012/03/20 17:44:18 matt Exp $ */ | | 1 | /* $NetBSD: ip6opt.c,v 1.15 2014/02/07 02:36:06 christos Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | | 4 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -21,27 +21,27 @@ | | | @@ -21,27 +21,27 @@ |
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE | | 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE |
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
29 | * SUCH DAMAGE. | | 29 | * SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #include <sys/cdefs.h> | | 32 | #include <sys/cdefs.h> |
33 | #if defined(LIBC_SCCS) && !defined(lint) | | 33 | #if defined(LIBC_SCCS) && !defined(lint) |
34 | __RCSID("$NetBSD: ip6opt.c,v 1.14 2012/03/20 17:44:18 matt Exp $"); | | 34 | __RCSID("$NetBSD: ip6opt.c,v 1.15 2014/02/07 02:36:06 christos Exp $"); |
35 | #endif /* LIBC_SCCS and not lint */ | | 35 | #endif /* LIBC_SCCS and not lint */ |
36 | | | 36 | |
37 | #include "namespace.h" | | 37 | #include "namespace.h" |
38 | #include <sys/param.h> | | 38 | #include <sys/param.h> |
39 | #include <sys/types.h> | | 39 | #include <sys/types.h> |
40 | #include <sys/socket.h> | | 40 | #include <sys/socket.h> |
41 | | | 41 | |
42 | #include <netinet/in.h> | | 42 | #include <netinet/in.h> |
43 | #include <netinet/ip6.h> | | 43 | #include <netinet/ip6.h> |
44 | | | 44 | |
45 | #include <assert.h> | | 45 | #include <assert.h> |
46 | #include <stddef.h> | | 46 | #include <stddef.h> |
47 | #include <string.h> | | 47 | #include <string.h> |
| @@ -432,31 +432,28 @@ inet6_insert_padopt(uint8_t *p, size_t l | | | @@ -432,31 +432,28 @@ inet6_insert_padopt(uint8_t *p, size_t l |
432 | } | | 432 | } |
433 | } | | 433 | } |
434 | | | 434 | |
435 | /* | | 435 | /* |
436 | * The following functions are defined in RFC3542, which is a successor | | 436 | * The following functions are defined in RFC3542, which is a successor |
437 | * of RFC2292. | | 437 | * of RFC2292. |
438 | */ | | 438 | */ |
439 | | | 439 | |
440 | int | | 440 | int |
441 | inet6_opt_init(void *extbuf, socklen_t extlen) | | 441 | inet6_opt_init(void *extbuf, socklen_t extlen) |
442 | { | | 442 | { |
443 | struct ip6_ext *ext = (struct ip6_ext *)extbuf; | | 443 | struct ip6_ext *ext = (struct ip6_ext *)extbuf; |
444 | | | 444 | |
445 | if (extlen % 8) | | | |
446 | return (-1); | | | |
447 | | | | |
448 | if (ext) { | | 445 | if (ext) { |
449 | if (extlen == 0) | | 446 | if (extlen == 0 || (extlen % 8)) |
450 | return (-1); | | 447 | return (-1); |
451 | ext->ip6e_len = (extlen >> 3) - 1; | | 448 | ext->ip6e_len = (extlen >> 3) - 1; |
452 | } | | 449 | } |
453 | | | 450 | |
454 | return (2); /* sizeof the next and the length fields */ | | 451 | return (2); /* sizeof the next and the length fields */ |
455 | } | | 452 | } |
456 | | | 453 | |
457 | int | | 454 | int |
458 | inet6_opt_append(void *extbuf, socklen_t extlen, int offset, uint8_t type, | | 455 | inet6_opt_append(void *extbuf, socklen_t extlen, int offset, uint8_t type, |
459 | socklen_t len, uint8_t align, void **databufp) | | 456 | socklen_t len, uint8_t align, void **databufp) |
460 | { | | 457 | { |
461 | int currentlen = offset; | | 458 | int currentlen = offset; |
462 | size_t padlen = 0; | | 459 | size_t padlen = 0; |