Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/sysmon Defend against some table-lookup-not-found er...



details:   https://anonhg.NetBSD.org/src/rev/764acf9a4c22
branches:  trunk
changeset: 832276:764acf9a4c22
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Sat May 05 00:14:28 2018 +0000

description:
Defend against some table-lookup-not-found errors.

diffstat:

 sys/dev/sysmon/sysmon_envsys.c |  10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

diffs (45 lines):

diff -r 60b314626b15 -r 764acf9a4c22 sys/dev/sysmon/sysmon_envsys.c
--- a/sys/dev/sysmon/sysmon_envsys.c    Sat May 05 00:13:01 2018 +0000
+++ b/sys/dev/sysmon/sysmon_envsys.c    Sat May 05 00:14:28 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sysmon_envsys.c,v 1.141 2017/09/11 06:02:09 pgoyette Exp $     */
+/*     $NetBSD: sysmon_envsys.c,v 1.142 2018/05/05 00:14:28 pgoyette Exp $     */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.141 2017/09/11 06:02:09 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.142 2018/05/05 00:14:28 pgoyette Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -1706,6 +1706,8 @@
         * update sensor's type.
         */
        sdt = sme_find_table_entry(SME_DESC_UNITS, edata->units);
+       if (sdt == NULL)
+               return EINVAL;
 
        DPRINTFOBJ(("%s: sensor #%d units=%d (%s)\n", __func__, edata->sensor,
            sdt->type, sdt->desc));
@@ -1784,6 +1786,8 @@
        if (edata->units == ENVSYS_DRIVE) {
                sdt = sme_find_table_entry(SME_DESC_DRIVE_STATES,
                                           edata->value_cur);
+               if (sdt == NULL)
+                       return EINVAL;
                error = sme_sensor_upstring(dict, "drive-state", sdt->desc);
                if (error)
                        return error;
@@ -1796,6 +1800,8 @@
        if (edata->units == ENVSYS_BATTERY_CAPACITY) {
                sdt = sme_find_table_entry(SME_DESC_BATTERY_CAPACITY,
                    edata->value_cur);
+               if (sdt == NULL)
+                       return EINVAL;
                error = sme_sensor_upstring(dict, "battery-capacity",
                                            sdt->desc);
                if (error)



Home | Main Index | Thread Index | Old Index