Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/powerd powerd: Stop crashing if entries are not fou...



details:   https://anonhg.NetBSD.org/src/rev/7abfa9b7d4cf
branches:  trunk
changeset: 1015073:7abfa9b7d4cf
user:      roy <roy%NetBSD.org@localhost>
date:      Mon Oct 12 16:54:43 2020 +0000

description:
powerd: Stop crashing if entries are not found in the dictionary

If the first three are not found, log a diagnostic and do nothing.
If the latter two are not found, set them to NULL rather than garbage.

diffstat:

 usr.sbin/powerd/powerd.c |  29 ++++++++++++++++++++++-------
 1 files changed, 22 insertions(+), 7 deletions(-)

diffs (49 lines):

diff -r 6676295cf6b2 -r 7abfa9b7d4cf usr.sbin/powerd/powerd.c
--- a/usr.sbin/powerd/powerd.c  Mon Oct 12 16:27:23 2020 +0000
+++ b/usr.sbin/powerd/powerd.c  Mon Oct 12 16:54:43 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: powerd.c,v 1.19 2020/06/07 05:54:00 thorpej Exp $      */
+/*     $NetBSD: powerd.c,v 1.20 2020/10/12 16:54:43 roy Exp $  */
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -325,18 +325,33 @@
                            __func__, error);
                return;
        }
-       
+
        if (debug) {
                buf = prop_dictionary_externalize(dict);
                printf("%s", buf);
                free(buf);
        }
 
-       prop_dictionary_get_string(dict, "powerd-script-name", &argv[0]);
-       prop_dictionary_get_string(dict, "driver-name", &argv[1]);
-       prop_dictionary_get_string(dict, "powerd-event-name", &argv[2]);
-       prop_dictionary_get_string(dict, "sensor-name", &argv[3]);
-       prop_dictionary_get_string(dict, "state-description", &argv[4]);
+       /* First three arguments are not optional. */
+       if (!prop_dictionary_get_string(dict, "powerd-script-name", &argv[0])) {
+               powerd_log(LOG_ERR, "dict does not have powerd-script-name");
+               return;
+       }
+       if (!prop_dictionary_get_string(dict, "driver-name", &argv[1])) {
+               powerd_log(LOG_ERR, "dict does not have driver-name");
+               return;
+       }
+       if (!prop_dictionary_get_string(dict, "powerd-event-name", &argv[2])) {
+               powerd_log(LOG_ERR, "dict does not have powerd-event-name");
+               return;
+       }
+
+       /* These arguments are optional. */
+       if (!prop_dictionary_get_string(dict, "sensor-name", &argv[3]))
+               argv[3] = NULL;
+       if (!prop_dictionary_get_string(dict, "state-description", &argv[4]))
+               argv[4] = NULL;
+
        argv[5] = NULL;
 
        run_script(argv);



Home | Main Index | Thread Index | Old Index