Skip to content

fix: Avoid modifying const string data in partition list parser - #8

Open
andrewwhitecdw wants to merge 1 commit into
NVIDIA:mainfrom
andrewwhitecdw:sweep/bugfix-fmpm-1c699d85
Open

fix: Avoid modifying const string data in partition list parser#8
andrewwhitecdw wants to merge 1 commit into
NVIDIA:mainfrom
andrewwhitecdw:sweep/bugfix-fmpm-1c699d85

Conversation

@andrewwhitecdw

@andrewwhitecdw andrewwhitecdw commented Jul 26, 2026

Copy link
Copy Markdown

Problem

fix: Avoid modifying const string data in partition list parser

Fix

Replace:

fmReturn_t
parsePartitionIdlistString(std::string & partitionListStr, unsigned int * partitionIds, unsigned * numPartitions)
{
    char * token = strtok((char *)partitionListStr.c_str(), ",");
    int haveSeen[FM_MAX_FABRIC_PARTITIONS] = { 0 };

    *numPartitions = 0;

    while ( token != NULL )
    {
        int partId = (int)atoi(token);

        if ( partId < 0 || partId >= FM_MAX_FABRIC_PARTITIONS )
        {
            printf("Invalid partition Id %u was given.\n", partId);
            return FM_ST_BADPARAM;
        }

        if ( !haveSeen[partId] )
        {
            haveSeen[partId] = 1;

            partitionIds[*numPartitions] = partId;
            (*numPartitions)++;
        }

        token = strtok(NULL, ",");
    }

    return FM_ST_SUCCESS;
}

with:

fmReturn_t
parsePartitionIdlistString(std::string & partitionListStr, unsigned int * partitionIds, unsigned * numPartitions)
{
    char *partitionListCstr = strdup(partitionListStr.c_str());
    if (partitionListCstr == NULL)
    {
        return FM_ST_GENERIC_ERROR;
    }

    char * token = strtok(partitionListCstr, ",");
    int haveSeen[FM_MAX_FABRIC_PARTITIONS] = { 0 };

    *numPartitions = 0;

    while ( token != NULL )
    {
        int partId = (int)atoi(token);

        if ( partId < 0 || partId >= FM_MAX_FABRIC_PARTITIONS )
        {
            printf("Invalid partition Id %u was given.\n", partId);
            free(partitionListCstr);
            return FM_ST_BADPARAM;
        }

        if ( !haveSeen[partId] )
        {
            haveSeen[partId] = 1;

            partitionIds[*numPartitions] = partId;
            (*numPartitions)++;
        }

        token = strtok(NULL, ",");
    }

    free(partitionListCstr);
    return FM_ST_SUCCESS;
}

Files changed

  • fmpm.cpp

@andrewwhitecdw
andrewwhitecdw marked this pull request as ready for review July 26, 2026 21:05
@andrewwhitecdw

Copy link
Copy Markdown
Author

Closing this sweep-generated PR: sole commit is missing a valid Signed-off-by trailer. 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