Skip to content

fix: Handle invalid or out-of-range partition ID arguments safely - #10

Open
andrewwhitecdw wants to merge 1 commit into
NVIDIA:mainfrom
andrewwhitecdw:bugfix/fmpm-0806d8d9
Open

fix: Handle invalid or out-of-range partition ID arguments safely#10
andrewwhitecdw wants to merge 1 commit into
NVIDIA:mainfrom
andrewwhitecdw:bugfix/fmpm-0806d8d9

Conversation

@andrewwhitecdw

@andrewwhitecdw andrewwhitecdw commented Jul 26, 2026

Copy link
Copy Markdown

Problem

fix: Handle invalid or out-of-range partition ID arguments safely

Fix

Replace:

        } else if (std::string(argv[i]) == "-a") {
            operation = SHARED_FABRIC_CMD_ACTIVATE_PARTITION;
            if (i + 1 < argc) {
                partitionId = std::stoul(argv[i + 1]);
                ++i;
            } else {
                std::cerr << "Error: -a option requires partition ID." << std::endl;
                return 1;
            }
            if ( partitionId >= FM_MAX_FABRIC_PARTITIONS ) {
                std::cout << "Invalid 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;
            }
        }

with:

        } else if (std::string(argv[i]) == "-a") {
            operation = SHARED_FABRIC_CMD_ACTIVATE_PARTITION;
            if (i + 1 < argc) {
                unsigned long pid;
                try {
                    pid = std::stoul(argv[i + 1]);
                } catch (const std::exception& e) {
                    std::cerr << "Error: -a option requires a valid partition ID." << std::endl;
                    return 1;
                }
                if ( pid >= FM_MAX_FABRIC_PARTITIONS ) {
                    std::cout << "Invalid Partition ID." << std::endl;
                    return FM_ST_BADPARAM;
                }
                partitionId = (unsigned int)pid;
                ++i;
            } else {
                std::cerr << "Error: -a option requires partition ID." << std::endl;
                return 1;
            }
        } else if (std::string(argv[i]) == "-d") {
            operation = SHARED_FABRIC_CMD_DEACTIVATE_PARTITION;
            if (i + 1 < argc) {
                unsigned long pid;
                try {
                    pid = std::stoul(argv[i + 1]);
                } catch (const std::exception& e) {
                    std::cerr << "Error: -d option requires a valid partition ID." << std::endl;
                    return 1;
                }
                if ( pid >= FM_MAX_FABRIC_PARTITIONS ) {
                    std::cout << "Invalid Partition ID." << std::endl;
                    return FM_ST_BADPARAM;
                }
                partitionId = (unsigned int)pid;
                ++i;
            } else {
                std::cerr << "Error: -d option requires partition ID." << std::endl;
                return 1;
            }
        }

Files changed

  • fmpm.cpp

@andrewwhitecdw
andrewwhitecdw marked this pull request as ready for review July 27, 2026 01:40
@andrewwhitecdw

Copy link
Copy Markdown
Author

Closing this sweep-generated PR: PR has 2 commits; sweep requires exactly one commit per PR. It does not meet the sweep requirements (single signed-off commit).

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