Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UCS: ucs_config_parser_set_value on incorrect value leads segmentation fault (double free) #5980

Closed
hoopoepg opened this issue Dec 3, 2020 · 0 comments · Fixed by #5987
Closed
Assignees
Labels

Comments

@hoopoepg
Copy link
Contributor

hoopoepg commented Dec 3, 2020

Describe the bug

ucs_config_parser_set_value on incorrect value leads segmentation fault (double free)

Steps to Reproduce

reproducer below

Additional information (depending on the issue)

reproduced on master

reproducer:

#include <ucs/config/parser.h>
#include <assert.h>

typedef enum {
    TEST_TYPE_1,
    TEST_TYPE_2,
    TEST_TYPE_ALL,
    TEST_TYPE_LAST,
} test_type_t;

const char *test_type_names[] = {
    [TEST_TYPE_1] = "type_1",
    [TEST_TYPE_2] = "type_2",
    [TEST_TYPE_ALL] = "all",
    [TEST_TYPE_LAST] = NULL
};

typedef struct test_config {
    struct {
        test_type_t *types;
        unsigned     count;
    } field;
} test_config_t;

UCS_CONFIG_DEFINE_ARRAY(test_types, sizeof(test_type_t),
                        UCS_CONFIG_TYPE_ENUM(test_type_names));
static ucs_config_field_t table[] = {
    {"TEST", "all", "Comma separated list types",
     ucs_offsetof(test_config_t, field), UCS_CONFIG_TYPE_ARRAY(test_types)},
    {NULL}
};

int main(int argc, char *argv[])
{
    ucs_status_t status;

    test_config_t *cfg = malloc(sizeof(*cfg));
    ucs_config_parser_fill_opts(cfg, table, "prefix", NULL, 0);
    status = ucs_config_parser_set_value(cfg, table, "TEST", "type_1,type_2");
    assert(UCS_OK == status);
    status = ucs_config_parser_set_value(cfg, table, "TEST", "type_3");
    assert(UCS_OK != status);
    ucs_config_parser_release_opts(cfg, table); /* here is double free issue */
    free(cfg);
    return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant