Skip to content

fix: -d accepts out-of-range partition IDs without check - #13

Open
andrewwhitecdw wants to merge 1 commit into
NVIDIA:mainfrom
andrewwhitecdw:bugfix/fmpm-d-accepts-out-of-range-partition-ids
Open

fix: -d accepts out-of-range partition IDs without check#13
andrewwhitecdw wants to merge 1 commit into
NVIDIA:mainfrom
andrewwhitecdw:bugfix/fmpm-d-accepts-out-of-range-partition-ids

Conversation

@andrewwhitecdw

Copy link
Copy Markdown

This PR addresses the following issue in fmpm.cpp: -d accepts out-of-range partition IDs without check.

Changes

  • fmpm.cpp: -d accepts out-of-range partition IDs without check.

Details

--- a/fmpm.cpp
+++ b/fmpm.cpp
@@ -1,10 +1,14 @@
-        } else if (std::string(argv[i]) == "-d") {
-            operation = SHARED_FABRIC_CMD_DEACTIVATE_PARTITION;
-            if (i + 1 < argc) {
-                partitionId = std::stoul(argv[i + 1]);
-                ++i;
-            } else {
-                std::cerr << "Error: -d option requires partition ID." << std::endl;
-                return FM_ST_BADPARAM;
-            }
-        }
+        } else if (std::string(argv[i]) == "-d") {
+            operation = SHARED_FABRIC_CMD_DEACTIVATE_PARTITION;
+            if (i + 1 < argc) {
+                partitionId = std::stoul(argv[i + 1]);
+                ++i;
+            } else {
+                std::cerr << "Error: -d option requires partition ID." << std::endl;
+                return FM_ST_BADPARAM;
+            }
+            if ( partitionId >= FM_MAX_FABRIC_PARTITIONS ) {
+                std::cout << "Invalid Partition ID." << std::endl;
+                return FM_ST_BADPARAM;
+            }
+        }

Tests

Let me know if you want tests added for this fix or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant