Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb uvideo(4): Assert number of units can't overflow.



details:   https://anonhg.NetBSD.org/src/rev/c6e980e93efb
branches:  trunk
changeset: 368240:c6e980e93efb
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Fri Jul 01 01:06:31 2022 +0000

description:
uvideo(4): Assert number of units can't overflow.

Not sure if this is true, but at least we'll trap instead of silently
undercount this way.

diffstat:

 sys/dev/usb/uvideo.c |  6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diffs (34 lines):

diff -r 34aa53214e96 -r c6e980e93efb sys/dev/usb/uvideo.c
--- a/sys/dev/usb/uvideo.c      Fri Jul 01 01:06:04 2022 +0000
+++ b/sys/dev/usb/uvideo.c      Fri Jul 01 01:06:31 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvideo.c,v 1.81 2022/05/14 15:29:08 riastradh Exp $    */
+/*     $NetBSD: uvideo.c,v 1.82 2022/07/01 01:06:31 riastradh Exp $    */
 
 /*
  * Copyright (c) 2008 Patrick Mahoney
@@ -42,7 +42,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvideo.c,v 1.81 2022/05/14 15:29:08 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvideo.c,v 1.82 2022/07/01 01:06:31 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -811,6 +811,7 @@
                if (uvdesc->bDescriptorSubtype < UDESC_INPUT_TERMINAL ||
                    uvdesc->bDescriptorSubtype > UDESC_EXTENSION_UNIT)
                        continue;
+               KASSERT(nunits < 255);
                ++nunits;
        }
 
@@ -843,6 +844,7 @@
                /* TODO: free other units before returning? */
                if (sc->sc_unit[i] == NULL)
                        goto enomem;
+               KASSERT(i < 255);
                ++i;
        }
 



Home | Main Index | Thread Index | Old Index