summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Scott <nathans@redhat.com>2022-04-30 13:50:25 +1000
committerNathan Scott <nathans@redhat.com>2022-04-30 13:50:25 +1000
commitcb61865bb93999e02852438d53c06def3d8d623b (patch)
treee43a53133c0b45bdb183d9f98ec2c04842a84418
parentae518e20b7730cb13f9348e06f902c3dd6893de5 (diff)
Add array bounds checking for the Process_fields array (covscan)
Coverity scan reports there may be a code path that would cause an overrun in the (relatively new) ScreenSettings code where it evaluates default sort direction. Add bounds check and default to descending instead of a potentially invalid array access.
-rw-r--r--Settings.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/Settings.c b/Settings.c
index 006be97f..a825b56a 100644
--- a/Settings.c
+++ b/Settings.c
@@ -271,12 +271,18 @@ static void ScreenSettings_readFields(ScreenSettings* ss, Hashtable* columns, co
ScreenSettings* Settings_newScreen(Settings* this, const ScreenDefaults* defaults) {
int sortKey = defaults->sortKey ? toFieldIndex(this->dynamicColumns, defaults->sortKey) : PID;
+ int sortDesc;
+ if (sortKey >= 0 && sortKey < LAST_PROCESSFIELD)
+ sortDesc = Process_fields[sortKey].defaultSortDesc;
+ else
+ sortDesc = 1;
+
ScreenSettings* ss = xMalloc(sizeof(ScreenSettings));
*ss = (ScreenSettings) {
.name = xStrdup(defaults->name),
.fields = xCalloc(LAST_PROCESSFIELD, sizeof(ProcessField)),
.flags = 0,
- .direction = (Process_fields[sortKey].defaultSortDesc) ? -1 : 1,
+ .direction = sortDesc ? -1 : 1,
.treeDirection = 1,
.sortKey = sortKey,
.treeSortKey = PID,

© 2014-2024 Faster IT GmbH | imprint | privacy policy