summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorclaudio <claudio@openbsd.org>2006-04-25 08:22:14 +0000
committerclaudio <claudio@openbsd.org>2006-04-25 08:22:14 +0000
commit5368b4c377797d9f24c3f35d4f9eadba8978829e (patch)
tree4e49c3f8b43bba7639935c4a3828c70e42991c61
parentThe return value of lsa_num_links is an u_int16_t tnd not int. Found by lint. (diff)
downloadwireguard-openbsd-5368b4c377797d9f24c3f35d4f9eadba8978829e.tar.xz
wireguard-openbsd-5368b4c377797d9f24c3f35d4f9eadba8978829e.zip
Path the length of the packet as size_t to in_cksum(). Enforce that the
passed size is not bigger than 2^16 (limit of the used algorithm). This removes some more lint warnings and makes sense.
-rw-r--r--usr.sbin/ospfd/in_cksum.c13
-rw-r--r--usr.sbin/ospfd/ospfd.h4
2 files changed, 11 insertions, 6 deletions
diff --git a/usr.sbin/ospfd/in_cksum.c b/usr.sbin/ospfd/in_cksum.c
index 10918c725bc..cdd61baec16 100644
--- a/usr.sbin/ospfd/in_cksum.c
+++ b/usr.sbin/ospfd/in_cksum.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: in_cksum.c,v 1.3 2006/03/09 09:43:03 claudio Exp $ */
+/* $OpenBSD: in_cksum.c,v 1.4 2006/04/25 08:22:14 claudio Exp $ */
/* $NetBSD: in_cksum.c,v 1.3 1995/04/22 13:53:48 cgd Exp $ */
/*
@@ -43,6 +43,7 @@
#include <sys/types.h>
#include "ospfd.h"
+#include "log.h"
/*
* Checksum routine for Internet Protocol family headers.
@@ -51,13 +52,17 @@
* In particular, it should not be this one.
*/
u_int16_t
-in_cksum(void *p, int len)
+in_cksum(void *p, size_t l)
{
unsigned int sum = 0;
- int oddbyte = 0, v = 0;
+ int len, oddbyte = 0, v = 0;
u_char *cp = p;
- /* we assume < 2^16 bytes being summed */
+ /* ensure that < 2^16 bytes being summed */
+ if (l >= (1 << 16))
+ fatalx("in_cksum: packet to big");
+ len = (int)l;
+
while (len > 0) {
if (oddbyte) {
sum += v + *cp++;
diff --git a/usr.sbin/ospfd/ospfd.h b/usr.sbin/ospfd/ospfd.h
index d15b711a0c4..51dd18c9049 100644
--- a/usr.sbin/ospfd/ospfd.h
+++ b/usr.sbin/ospfd/ospfd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ospfd.h,v 1.56 2006/04/24 20:18:03 claudio Exp $ */
+/* $OpenBSD: ospfd.h,v 1.57 2006/04/25 08:22:14 claudio Exp $ */
/*
* Copyright (c) 2004 Esben Norby <norby@openbsd.org>
@@ -524,7 +524,7 @@ void imsg_free(struct imsg *);
void imsg_event_add(struct imsgbuf *); /* needs to be provided externally */
/* in_cksum.c */
-u_int16_t in_cksum(void *, int);
+u_int16_t in_cksum(void *, size_t);
/* iso_cksum.c */
u_int16_t iso_cksum(void *, u_int16_t, u_int16_t);