diff --git a/bin/common.c b/bin/common.c index 6e709a743ad..35295753394 100644 --- a/bin/common.c +++ b/bin/common.c @@ -263,8 +263,13 @@ static int s2n_setup_external_psk(struct s2n_psk **psk, char *params) GUARD_EXIT_NULL(psk); GUARD_EXIT_NULL(params); + /* duplicate params as strtok will modify the input string */ + char *params_dup = malloc(strlen(params) + 1); + GUARD_EXIT_NULL(params_dup); + strcpy(params_dup, params); + size_t token_idx = 0; - for (char *token = strtok(params, ","); token != NULL; token = strtok(NULL, ","), token_idx++) { + for (char *token = strtok(params_dup, ","); token != NULL; token = strtok(NULL, ","), token_idx++) { switch (token_idx) { case 0: GUARD_EXIT(s2n_psk_set_identity(*psk, (const uint8_t *) token, strlen(token)), @@ -288,6 +293,7 @@ static int s2n_setup_external_psk(struct s2n_psk **psk, char *params) } } + free(params_dup); return S2N_SUCCESS; } diff --git a/bin/echo.c b/bin/echo.c index 24438d2cdce..4b7cc1db969 100644 --- a/bin/echo.c +++ b/bin/echo.c @@ -213,7 +213,7 @@ int print_connection_info(struct s2n_connection *conn) uint8_t *identity = (uint8_t *) malloc(identity_length); GUARD_EXIT_NULL(identity); GUARD_EXIT(s2n_connection_get_negotiated_psk_identity(conn, identity, identity_length), "Error getting negotiated psk identity from the connection\n"); - printf("Negotiated PSK identity: %s\n", identity); + printf("Negotiated PSK identity: %.*s\n", identity_length, identity); free(identity); }