changeset 289:d815c40c3753

UltraRogue: add a sanity check to do_fuses(). The d_id field, which indicates which fuse function to call, is now checked to make sure it is not out of range. do_daemons() already checks.
author John "Elwin" Edwards
date Fri, 24 Nov 2017 16:22:10 -0500
parents b8919055c2fc
children 2b452dbf0138
files urogue/daemon.c
diffstat 1 files changed, 10 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/urogue/daemon.c	Fri Nov 24 13:22:26 2017 -0500
+++ b/urogue/daemon.c	Fri Nov 24 16:22:10 2017 -0500
@@ -282,11 +282,18 @@
         {
             if (--wire->d_time <= 0)
             {
-                fuse_arg arg;
+                if (wire->d_id < 0 || wire->d_id >= FUSE_MAX)
+                    printf("Bad fuse id %d\n", wire->d_id);
+                else if (fuses[wire->d_id].func == NULL)
+                    printf("No action for fuse %d!\n", wire->d_id);
+                else
+                {
+                    fuse_arg arg;
 
-                arg.varg = wire->d_arg;
+                    arg.varg = wire->d_arg;
+                    fuses[wire->d_id].func(&arg);
+                }
                 wire->d_type = EMPTY;
-                fuses[wire->d_id].func(&arg);
                 demoncnt -= 1;
             }
         }