Skip to content

Commit

Permalink
removed strtok_r
Browse files Browse the repository at this point in the history
  • Loading branch information
feventura committed Mar 4, 2024
1 parent a9fcc1c commit 361c5f0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 29 deletions.
29 changes: 14 additions & 15 deletions oqsprov/oqsprov.c
Original file line number Diff line number Diff line change
Expand Up @@ -1130,22 +1130,21 @@ static const OSSL_ALGORITHM oqsprovider_decoder[] = {
// get the last number on the composite OID
int get_composite_idx(int idx)
{
char *first_token;
char *token;
char *s;
int i;
s = OPENSSL_strdup(oqs_oid_alg_list[idx * 2]);
first_token = strtok_r(s, ".", &s);
for (i = 0; i <= 7; i++) { // 7 dots in composite OID
token = strtok_r(NULL, ".", &s);
}
if (token != NULL) {
i = atoi(token);
} else {
i = -1;
char *token, *s;
int i, len, count = 0;

s = oqs_oid_alg_list[idx * 2];
len = strlen(oqs_oid_alg_list[idx * 2]);

for (i = 0; i < len; i++) {
if (s[i] == '.') {
count += 1;
}
if (count == 8) { // 8 dots in composite OID
return atoi(s + i + 1);
}
}
OPENSSL_free(first_token);
return i;
return 0;
}

static const OSSL_PARAM *oqsprovider_gettable_params(void *provctx)
Expand Down
36 changes: 22 additions & 14 deletions oqsprov/oqsprov_keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,23 +244,31 @@ char *get_oqsname(int nid)

char *get_cmpname(int nid, int index)
{
int i, j;
char *name;
char *first_token;
char *token;
char *s;
int i, len;
char *name, *s;
if ((i = get_oqsalg_idx(nid)) == -1)
return NULL;
s = OPENSSL_strdup(nid_names[i].tlsname);
first_token = strtok_r(s, "_", &s);
if (index == 0) {
name = OPENSSL_strdup(first_token);
} else {
for (j = 0; j < index; j++)
token = strtok_r(s, "_", &s);
name = OPENSSL_strdup(token);
s = nid_names[i].tlsname;
len = strlen(nid_names[i].tlsname);
for (i = 0; i < len; i++) {
if (s[i] == '_') {
break;
}
}
switch (index) {
case 0:
name = OPENSSL_malloc(i);
memcpy(name, s, i);
break;
case 1:
i += 1;
name = OPENSSL_malloc(len - i);
memcpy(name, s + i, len - i);
break;
default:
name = NULL;
}
OPENSSL_free(first_token);

return name;
}

Expand Down

0 comments on commit 361c5f0

Please sign in to comment.