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

calling s2n_cleanup with no s2n_init corrupts thread-local storage #4226

Closed
arielb1 opened this issue Sep 27, 2023 · 0 comments · Fixed by #4225
Closed

calling s2n_cleanup with no s2n_init corrupts thread-local storage #4226

arielb1 opened this issue Sep 27, 2023 · 0 comments · Fixed by #4225

Comments

@arielb1
Copy link
Contributor

arielb1 commented Sep 27, 2023

Problem:

This is a regression caused by the fix in #4024

This program fails as the my_key TLS key is corrupted (overwritten with NULL).

#include <pthread.h>

#include "s2n_test.h"

static int my_global;

static void my_destructor(void *arg) {}

/* Checks that calling s2n_cleanup without s2n_init does not corrupt
 * thread-local storage. */

int main(int argc, char **argv)
{
    BEGIN_TEST_NO_INIT();

    pthread_key_t my_key;

    /* Init the pthread key */
    EXPECT_SUCCESS(pthread_key_create(&my_key, my_destructor));

    /* Set it a value */
    EXPECT_SUCCESS(pthread_setspecific(my_key, &my_global));

    /* Call s2n_cleanup with no init */
    EXPECT_SUCCESS(s2n_cleanup());

    /* Check that the key is not corrupted */
    int *new_value = (int*) pthread_getspecific(my_key);
    EXPECT_EQUAL(new_value, &my_global);

    /* Delete the key */
    EXPECT_SUCCESS(pthread_key_delete(my_key));

    END_TEST_NO_INIT();
}

Solution:

This should work, or at least crash in a safe way without corruption.

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 a pull request may close this issue.

1 participant