Skip to content

Commit

Permalink
jwt_strdup: No more users of this, remove
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Collins <[email protected]>
  • Loading branch information
benmcollins committed Feb 13, 2025
1 parent 70b92e3 commit c19aef6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 23 deletions.
15 changes: 0 additions & 15 deletions libjwt/jwt-memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,6 @@ void __jwt_freemem(void *ptr)
free(ptr);
}

char *jwt_strdup(const char *str)
{
size_t len;
char *result;

len = strlen(str);
result = (char *)jwt_malloc(len + 1);
if (!result)
return NULL; // LCOV_EXCL_LINE

memcpy(result, str, len);
result[len] = '\0';
return result;
}

/* A time-safe strcmp function */
int jwt_strcmp(const char *str1, const char *str2)
{
Expand Down
6 changes: 0 additions & 6 deletions libjwt/jwt-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,6 @@ void *jwt_base64uri_decode(const char *src, int *ret_len);
JWT_NO_EXPORT
int jwt_strcmp(const char *str1, const char *str2);

JWT_NO_EXPORT
char *jwt_strdup(const char *str);

JWT_NO_EXPORT
void jwt_scrub_key(jwt_t *jwt);

JWT_NO_EXPORT
jwt_t *jwt_verify_sig(jwt_t *jwt, const char *head, unsigned int head_len,
const char *sig);
Expand Down
7 changes: 5 additions & 2 deletions libjwt/jwt-verify.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,19 @@ int jwt_parse(jwt_t *jwt, const char *token, unsigned int *len)
{
char_auto *head = NULL;
char *payload, *sig;
int head_len = strlen(token) + 1;

head = jwt_strdup(token);

head = jwt_malloc(head_len);
if (!head) {
// LCOV_EXCL_START
jwt_write_error(jwt, "Error allocating memory");
return 1;
// LCOV_EXCL_STOP
}

/* head_len includes nil */
memcpy(head, token, head_len);

/* Find the components. */
for (payload = head; payload[0] != '.'; payload++) {
if (payload[0] == '\0') {
Expand Down

0 comments on commit c19aef6

Please sign in to comment.