Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libbluetooth handle overflowed values correctly,



details:   https://anonhg.NetBSD.org/src/rev/e79b5cf0906b
branches:  trunk
changeset: 763795:e79b5cf0906b
user:      plunky <plunky%NetBSD.org@localhost>
date:      Mon Apr 04 16:19:25 2011 +0000

description:
handle overflowed values correctly,
also put a compile time guard to warn if INTMAX won't fit in INT64
(all our ports currently have INTMAX = INT64)

diffstat:

 lib/libbluetooth/sdp_get.c |  20 +++++++++-----------
 1 files changed, 9 insertions(+), 11 deletions(-)

diffs (68 lines):

diff -r 680d03a60e08 -r e79b5cf0906b lib/libbluetooth/sdp_get.c
--- a/lib/libbluetooth/sdp_get.c        Mon Apr 04 15:42:42 2011 +0000
+++ b/lib/libbluetooth/sdp_get.c        Mon Apr 04 16:19:25 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sdp_get.c,v 1.1 2009/05/12 10:05:06 plunky Exp $       */
+/*     $NetBSD: sdp_get.c,v 1.2 2011/04/04 16:19:25 plunky Exp $       */
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -30,11 +30,15 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: sdp_get.c,v 1.1 2009/05/12 10:05:06 plunky Exp $");
+__RCSID("$NetBSD: sdp_get.c,v 1.2 2011/04/04 16:19:25 plunky Exp $");
 
 #include <sdp.h>
 #include <limits.h>
 
+#if INTMAX_MAX < INT64_MAX
+#warning INTMAX type is not large enough to hold INT64 values
+#endif
+
 /******************************************************************************
  *     sdp_get_xxxx(data, value)
  *
@@ -188,9 +192,6 @@
                        return false;
 
                v = be64dec(p);
-               if (v > UINTMAX_MAX)
-                       return false;
-
                p += 8;
                break;
 
@@ -200,7 +201,7 @@
 
                x = be64dec(p);
                v = be64dec(p + 8);
-               if (x != 0 || v > UINTMAX_MAX)
+               if (x != 0)
                        return false;
 
                p += 16;
@@ -254,9 +255,6 @@
                        return false;
 
                v = (int64_t)be64dec(p);
-               if (v > INTMAX_MAX || v < INTMAX_MIN)
-                       return false;
-
                p += 8;
                break;
 
@@ -267,10 +265,10 @@
                x = (int64_t)be64dec(p);
                v = (int64_t)be64dec(p + 8);
                if (x == 0) {
-                       if (v > INTMAX_MAX)
+                       if (v < 0)
                                return false;
                } else if (x == -1) {
-                       if (v < INTMAX_MIN)
+                       if (v >= 0)
                                return false;
                } else {
                        return false;



Home | Main Index | Thread Index | Old Index