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

memmem is only being used in testing so move it there #7996

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions tests/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -94147,10 +94147,10 @@ static int test_dtls13_basic_connection_id(void)
size_t i;

/* We check if the side included the CID in their output */
#define CLIENT_CID() XMEMMEM(test_ctx.s_buff, test_ctx.s_len, \
client_cid, sizeof(client_cid))
#define SERVER_CID() XMEMMEM(test_ctx.c_buff, test_ctx.c_len, \
server_cid, sizeof(server_cid))
#define CLIENT_CID() mymemmem(test_ctx.s_buff, test_ctx.s_len, \
client_cid, sizeof(client_cid))
#define SERVER_CID() mymemmem(test_ctx.c_buff, test_ctx.c_len, \
server_cid, sizeof(server_cid))

printf("\n");
for (i = 0; i < XELEM_CNT(params) && EXPECT_SUCCESS(); i++) {
Expand Down
19 changes: 0 additions & 19 deletions wolfcrypt/src/wc_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -3397,25 +3397,6 @@ char* mystrnstr(const char* s1, const char* s2, unsigned int n)
}
#endif

void *mymemmem(const void *haystack, size_t haystacklen,
const void *needle, size_t needlelen)
{
size_t i, j;
const char* h = (const char*)haystack;
const char* n = (const char*)needle;
if (needlelen > haystacklen)
return NULL;
for (i = 0; i <= haystacklen - needlelen; i++) {
for (j = 0; j < needlelen; j++) {
if (h[i + j] != n[j])
break;
}
if (j == needlelen)
return (void*)(h + i);
}
return NULL;
}


/* custom memory wrappers */
#ifdef WOLFSSL_NUCLEUS_1_2
Expand Down
19 changes: 19 additions & 0 deletions wolfssl/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -4853,4 +4853,23 @@ void DEBUG_WRITE_DER(const byte* der, int derSz, const char* fileName);

#define DTLS_CID_BUFFER_SIZE 256

static WC_MAYBE_UNUSED void *mymemmem(const void *haystack, size_t haystacklen,
const void *needle, size_t needlelen)
{
size_t i, j;
const char* h = (const char*)haystack;
const char* n = (const char*)needle;
if (needlelen > haystacklen)
return NULL;
for (i = 0; i <= haystacklen - needlelen; i++) {
for (j = 0; j < needlelen; j++) {
if (h[i + j] != n[j])
break;
}
if (j == needlelen)
return (void*)(h + i);
}
return NULL;
}

#endif /* wolfSSL_TEST_H */
1 change: 0 additions & 1 deletion wolfssl/wolfcrypt/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,6 @@ typedef struct w64wrapper {
#define XMEMSET(b,c,l) memset((b),(c),(l))
#define XMEMCMP(s1,s2,n) memcmp((s1),(s2),(n))
#define XMEMMOVE(d,s,l) memmove((d),(s),(l))
#define XMEMMEM(h,hl,n,nl) mymemmem((h),(hl),(n),(nl))

#define XSTRLEN(s1) strlen((s1))
#define XSTRNCPY(s1,s2,n) strncpy((s1),(s2),(n))
Expand Down
2 changes: 0 additions & 2 deletions wolfssl/wolfcrypt/wc_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -1214,8 +1214,6 @@ WOLFSSL_ABI WOLFSSL_API int wolfCrypt_Cleanup(void);
#ifndef WOLFSSL_LEANPSK
char* mystrnstr(const char* s1, const char* s2, unsigned int n);
#endif
WOLFSSL_API void *mymemmem(const void *haystack, size_t haystacklen,
const void *needle, size_t needlelen);

#ifndef FILE_BUFFER_SIZE
/* default static file buffer size for input, will use dynamic buffer if
Expand Down
Loading