You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ko...@apache.org on 2021/02/24 10:21:23 UTC

[mynewt-core] branch master updated: hw/sensor: fix possible null dereference in sensor_set_thresh() If stt is NULL return error to before dereferencing it.

This is an automated email from the ASF dual-hosted git repository.

kopyscinski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
     new a1f8dfc  hw/sensor: fix possible null dereference in sensor_set_thresh() If stt is NULL return error to before dereferencing it.
a1f8dfc is described below

commit a1f8dfcfd1b731b1eeed500ec560e2585bc794c7
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Wed Feb 24 10:27:48 2021 +0100

    hw/sensor: fix possible null dereference in sensor_set_thresh()
    If stt is NULL return error to before dereferencing it.
---
 hw/sensor/src/sensor.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/hw/sensor/src/sensor.c b/hw/sensor/src/sensor.c
index 55e2aee..b2aaf4d 100644
--- a/hw/sensor/src/sensor.c
+++ b/hw/sensor/src/sensor.c
@@ -1970,6 +1970,11 @@ sensor_set_thresh(const char *devname, struct sensor_type_traits *stt)
     struct sensor *sensor;
     int rc;
 
+    if (stt == NULL) {
+        rc = SYS_EINVAL;
+        goto err;
+    }
+
     sensor = sensor_get_type_traits_byname(devname, &stt_tmp,
                                            stt->stt_sensor_type);
     if (!sensor) {
@@ -1977,7 +1982,7 @@ sensor_set_thresh(const char *devname, struct sensor_type_traits *stt)
         goto err;
     }
 
-    if (!stt_tmp && stt) {
+    if (!stt_tmp) {
         rc = sensor_insert_type_trait(sensor, stt);
         stt_tmp = stt;
     } else if (stt_tmp) {