From c2b6bfd3a85ee40d4f7980f3848e43c5b3e8fc2c Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Date: Mon, 24 Apr 2023 12:19:15 +0200 Subject: [PATCH] Set the size of the channel property arrays Arrays which don't initialize the last elements of the enumeration are shorter and will cause a buffer overflow when read in a loop. --- src/emu/cpu.c | 6 +++--- src/emu/kernel/setup.c | 2 +- src/emu/nanos6/setup.c | 2 +- src/emu/nodes/setup.c | 2 +- src/emu/nosv/setup.c | 2 +- src/emu/ovni/setup.c | 2 +- src/emu/thread.c | 8 ++++---- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/emu/cpu.c b/src/emu/cpu.c index 78d06c7..addc9a5 100644 --- a/src/emu/cpu.c +++ b/src/emu/cpu.c @@ -18,7 +18,7 @@ #include "value.h" static const char chan_fmt[] = "cpu%ld.%s"; -static const char *chan_name[] = { +static const char *chan_name[CPU_CHAN_MAX] = { [CPU_CHAN_NRUN] = "nrunning", [CPU_CHAN_PID] = "pid_running", [CPU_CHAN_TID] = "tid_running", @@ -26,7 +26,7 @@ static const char *chan_name[] = { [CPU_CHAN_THACT] = "th_active", }; -static int chan_type[] = { +static int chan_type[CPU_CHAN_MAX] = { [CPU_CHAN_PID] = PRV_CPU_PID, [CPU_CHAN_TID] = PRV_CPU_TID, [CPU_CHAN_NRUN] = PRV_CPU_NRUN, @@ -34,7 +34,7 @@ static int chan_type[] = { [CPU_CHAN_THACT] = -1, }; -static long prv_flags[] = { +static long prv_flags[CPU_CHAN_MAX] = { [CPU_CHAN_NRUN] = PRV_ZERO, }; diff --git a/src/emu/kernel/setup.c b/src/emu/kernel/setup.c index 2a70286..b25c9a5 100644 --- a/src/emu/kernel/setup.c +++ b/src/emu/kernel/setup.c @@ -40,7 +40,7 @@ static const int chan_stack[CH_MAX] = { /* ----------------- pvt ------------------ */ -static const int pvt_type[] = { +static const int pvt_type[CH_MAX] = { [CH_CS] = PRV_KERNEL_CS, }; diff --git a/src/emu/nanos6/setup.c b/src/emu/nanos6/setup.c index e4dc73f..1e3fe9c 100644 --- a/src/emu/nanos6/setup.c +++ b/src/emu/nanos6/setup.c @@ -65,7 +65,7 @@ static const int chan_dup[CH_MAX] = { /* ----------------- pvt ------------------ */ -static const int pvt_type[] = { +static const int pvt_type[CH_MAX] = { [CH_TASKID] = PRV_NANOS6_TASKID, [CH_TYPE] = PRV_NANOS6_TYPE, [CH_SUBSYSTEM] = PRV_NANOS6_SUBSYSTEM, diff --git a/src/emu/nodes/setup.c b/src/emu/nodes/setup.c index a0989bf..f4018df 100644 --- a/src/emu/nodes/setup.c +++ b/src/emu/nodes/setup.c @@ -46,7 +46,7 @@ static const int chan_stack[CH_MAX] = { /* ----------------- pvt ------------------ */ -static const int pvt_type[] = { +static const int pvt_type[CH_MAX] = { [CH_SUBSYSTEM] = PRV_NODES_SUBSYSTEM, }; diff --git a/src/emu/nosv/setup.c b/src/emu/nosv/setup.c index 2e1f245..7485e80 100644 --- a/src/emu/nosv/setup.c +++ b/src/emu/nosv/setup.c @@ -61,7 +61,7 @@ static const int chan_dup[CH_MAX] = { /* ----------------- pvt ------------------ */ -static const int pvt_type[] = { +static const int pvt_type[CH_MAX] = { [CH_TASKID] = PRV_NOSV_TASKID, [CH_TYPE] = PRV_NOSV_TYPE, [CH_APPID] = PRV_NOSV_APPID, diff --git a/src/emu/ovni/setup.c b/src/emu/ovni/setup.c index 331b4e9..ada76c8 100644 --- a/src/emu/ovni/setup.c +++ b/src/emu/ovni/setup.c @@ -40,7 +40,7 @@ static const int chan_stack[CH_MAX] = { 0 }; /* ----------------- pvt ------------------ */ -static const int pvt_type[] = { +static const int pvt_type[CH_MAX] = { [CH_FLUSH] = PRV_OVNI_FLUSH, }; diff --git a/src/emu/thread.c b/src/emu/thread.c index 9cebb92..0536a2d 100644 --- a/src/emu/thread.c +++ b/src/emu/thread.c @@ -19,19 +19,19 @@ struct proc; static const char chan_fmt[] = "thread%lu.%s"; -static const char *chan_name[] = { +static const char *chan_name[TH_CHAN_MAX] = { [TH_CHAN_CPU] = "cpu_gindex", [TH_CHAN_TID] = "tid_active", [TH_CHAN_STATE] = "state", }; -static const int chan_type[] = { +static const int chan_type[TH_CHAN_MAX] = { [TH_CHAN_CPU] = PRV_THREAD_CPU, [TH_CHAN_TID] = PRV_THREAD_TID, [TH_CHAN_STATE] = PRV_THREAD_STATE, }; -static const long prv_flags[] = { +static const long prv_flags[TH_CHAN_MAX] = { /* Add one to the zero-based cpu gindex */ [TH_CHAN_CPU] = PRV_NEXT, @@ -40,7 +40,7 @@ static const long prv_flags[] = { [TH_CHAN_STATE] = PRV_SKIPDUP, }; -static const char *pvt_name[] = { +static const char *pvt_name[TH_CHAN_MAX] = { [TH_CHAN_CPU] = "Thread: CPU affinity", [TH_CHAN_TID] = "Thread: TID of the ACTIVE thread", [TH_CHAN_STATE] = "Thread: thread state",