warning with keil build and native lwip want read case

This commit is contained in:
JacobBarthelmeh
2021-11-18 22:58:50 -07:00
parent b42a0d9712
commit 7e2fab6f4a
7 changed files with 48 additions and 20 deletions

View File

@ -2572,7 +2572,7 @@ int LwIPNativeReceive(WOLFSSL* ssl, char* buf, int sz,
{ {
struct pbuf *current, *head; struct pbuf *current, *head;
WOLFSSL_LWIP_NATIVE_STATE* nlwip; WOLFSSL_LWIP_NATIVE_STATE* nlwip;
int ret; int ret = 0;
if (nlwip == NULL || ctx == NULL) { if (nlwip == NULL || ctx == NULL) {
return WOLFSSL_CBIO_ERR_GENERAL; return WOLFSSL_CBIO_ERR_GENERAL;
@ -2580,8 +2580,8 @@ int LwIPNativeReceive(WOLFSSL* ssl, char* buf, int sz,
nlwip = (WOLFSSL_LWIP_NATIVE_STATE*)ctx; nlwip = (WOLFSSL_LWIP_NATIVE_STATE*)ctx;
current = nlwip->pbuf; current = nlwip->pbuf;
if (current == NULL) { if (current == NULL || sz > current->tot_len) {
WOLFSSL_MSG("LwIP native pbuf list is null, want read"); WOLFSSL_MSG("LwIP native pbuf list is null or not enough data, want read");
ret = WOLFSSL_CBIO_ERR_WANT_READ; ret = WOLFSSL_CBIO_ERR_WANT_READ;
} }
else { else {
@ -2600,7 +2600,6 @@ int LwIPNativeReceive(WOLFSSL* ssl, char* buf, int sz,
return WOLFSSL_CBIO_ERR_GENERAL; return WOLFSSL_CBIO_ERR_GENERAL;
} }
WOLFSSL_MSG("Reading from payload");
/* check if is a partial read from before */ /* check if is a partial read from before */
XMEMCPY(&buf[read], XMEMCPY(&buf[read],
(const char *)&(((char *)(current->payload))[nlwip->pulled]), (const char *)&(((char *)(current->payload))[nlwip->pulled]),
@ -2608,13 +2607,13 @@ int LwIPNativeReceive(WOLFSSL* ssl, char* buf, int sz,
len); len);
nlwip->pulled = nlwip->pulled + len; nlwip->pulled = nlwip->pulled + len;
if (nlwip->pulled >= current->len) { if (nlwip->pulled >= current->len) {
WOLFSSL_LEAVE("Read full pbuf, advancing. LEN was ", WOLFSSL_MSG("Native LwIP read full pbuf");
current->len);
nlwip->pbuf = current->next; nlwip->pbuf = current->next;
current = nlwip->pbuf; current = nlwip->pbuf;
nlwip->pulled = 0; nlwip->pulled = 0;
} }
read = read + len; read = read + len;
ret = read;
/* read enough break out */ /* read enough break out */
if (read >= sz) { if (read >= sz) {
@ -2622,13 +2621,11 @@ int LwIPNativeReceive(WOLFSSL* ssl, char* buf, int sz,
* ref count for next in chain and free all from begining till * ref count for next in chain and free all from begining till
* next */ * next */
if (current != NULL) { if (current != NULL) {
WOLFSSL_MSG("Case where partial read or at next");
pbuf_ref(current); pbuf_ref(current);
} }
/* ack and start free'ing from the current head of the chain */ /* ack and start free'ing from the current head of the chain */
pbuf_free(head); pbuf_free(head);
ret = read;
break; break;
} }
} }
@ -2662,6 +2659,8 @@ static err_t LwIPNativeReceiveCB(void* cb, struct tcp_pcb* pcb,
pbuf_cat(nlwip->pbuf, pbuf); /* add chain to head */ pbuf_cat(nlwip->pbuf, pbuf); /* add chain to head */
} }
} }
WOLFSSL_LEAVE("LwIPNativeReceiveCB", nlwip->pbuf->tot_len);
return ERR_OK; return ERR_OK;
} }

View File

@ -422,17 +422,18 @@ WC_STATIC WC_INLINE word32 btoi(byte b)
} }
#endif #endif
WC_STATIC WC_INLINE char HexCharToByte(char ch) WC_STATIC WC_INLINE signed char HexCharToByte(char ch)
{ {
if (ch >= '0' && ch <= '9') signed char ret = (signed char)ch;
ch -= '0'; if (ret >= '0' && ret <= '9')
else if (ch >= 'A' && ch <= 'F') ret -= '0';
ch -= 'A' - 10; else if (ret >= 'A' && ret <= 'F')
else if (ch >= 'a' && ch <= 'f') ret -= 'A' - 10;
ch -= 'a' - 10; else if (ret >= 'a' && ret <= 'f')
ret -= 'a' - 10;
else else
ch = -1; /* error case - return code must be signed */ ret = -1; /* error case - return code must be signed */
return ch; return ret;
} }
WC_STATIC WC_INLINE char ByteToHex(byte in) WC_STATIC WC_INLINE char ByteToHex(byte in)

View File

@ -12549,7 +12549,7 @@ static int _sp_read_radix_16(sp_int* a, const char* in)
a->dp[0] = 0; a->dp[0] = 0;
for (i = (int)(XSTRLEN(in) - 1); i >= 0; i--) { for (i = (int)(XSTRLEN(in) - 1); i >= 0; i--) {
int ch = (int)(signed char)HexCharToByte(in[i]); int ch = (int)HexCharToByte(in[i]);
if (ch < 0) { if (ch < 0) {
err = MP_VAL; err = MP_VAL;
break; break;

View File

@ -5482,7 +5482,7 @@ static int fp_read_radix_16(fp_int *a, const char *str)
j = 0; j = 0;
k = 0; k = 0;
for (i = (int)(XSTRLEN(str) - 1); i >= 0; i--) { for (i = (int)(XSTRLEN(str) - 1); i >= 0; i--) {
ch = (int)(signed char)HexCharToByte(str[i]); ch = (int)HexCharToByte(str[i]);
if (ch < 0) { if (ch < 0) {
return FP_VAL; return FP_VAL;
} }

View File

@ -406,7 +406,9 @@ WOLFSSL_TEST_SUBROUTINE int hmac_sha256_test(void);
WOLFSSL_TEST_SUBROUTINE int hmac_sha384_test(void); WOLFSSL_TEST_SUBROUTINE int hmac_sha384_test(void);
WOLFSSL_TEST_SUBROUTINE int hmac_sha512_test(void); WOLFSSL_TEST_SUBROUTINE int hmac_sha512_test(void);
WOLFSSL_TEST_SUBROUTINE int hmac_sha3_test(void); WOLFSSL_TEST_SUBROUTINE int hmac_sha3_test(void);
#ifdef HAVE_HKDF
/* WOLFSSL_TEST_SUBROUTINE */ static int hkdf_test(void); /* WOLFSSL_TEST_SUBROUTINE */ static int hkdf_test(void);
#endif
WOLFSSL_TEST_SUBROUTINE int sshkdf_test(void); WOLFSSL_TEST_SUBROUTINE int sshkdf_test(void);
WOLFSSL_TEST_SUBROUTINE int x963kdf_test(void); WOLFSSL_TEST_SUBROUTINE int x963kdf_test(void);
WOLFSSL_TEST_SUBROUTINE int arc4_test(void); WOLFSSL_TEST_SUBROUTINE int arc4_test(void);
@ -642,6 +644,8 @@ static int wolfssl_pb_print(const char* msg, ...)
ASSERT_RESTORED_VECTOR_REGISTERS(exit(1);); ASSERT_RESTORED_VECTOR_REGISTERS(exit(1););
} }
#else #else
#ifndef test_pass
/* redirect to printf */ /* redirect to printf */
#define test_pass(...) { \ #define test_pass(...) { \
if (STACK_SIZE_CHECKPOINT_WITH_MAX_CHECK \ if (STACK_SIZE_CHECKPOINT_WITH_MAX_CHECK \
@ -651,6 +655,8 @@ static int wolfssl_pb_print(const char* msg, ...)
PRINT_HEAP_CHECKPOINT(); \ PRINT_HEAP_CHECKPOINT(); \
ASSERT_RESTORED_VECTOR_REGISTERS(exit(1);); \ ASSERT_RESTORED_VECTOR_REGISTERS(exit(1);); \
} }
#endif
/* stub the sleep macro */ /* stub the sleep macro */
#define TEST_SLEEP() #define TEST_SLEEP()
#endif #endif
@ -674,9 +680,11 @@ int wolfcrypt_test(void* args)
heap_baselineBytes = wolfCrypt_heap_peakBytes_checkpoint(); heap_baselineBytes = wolfCrypt_heap_peakBytes_checkpoint();
#endif #endif
#ifndef NO_TEST_PRINTF
printf("------------------------------------------------------------------------------\n"); printf("------------------------------------------------------------------------------\n");
printf(" wolfSSL version %s\n", LIBWOLFSSL_VERSION_STRING); printf(" wolfSSL version %s\n", LIBWOLFSSL_VERSION_STRING);
printf("------------------------------------------------------------------------------\n"); printf("------------------------------------------------------------------------------\n");
#endif
if (args) { if (args) {
#ifdef HAVE_WOLFCRYPT_TEST_OPTIONS #ifdef HAVE_WOLFCRYPT_TEST_OPTIONS
@ -22369,7 +22377,9 @@ static int ecc_test_curve(WC_RNG* rng, int keySize)
and HAVE_ECC_KOBLITZ */ and HAVE_ECC_KOBLITZ */
} }
else { else {
#ifndef NO_TEST_PRINTF
printf("ecc_test_curve_size %d failed!: %d\n", keySize, ret); printf("ecc_test_curve_size %d failed!: %d\n", keySize, ret);
#endif
return ret; return ret;
} }
} }
@ -22377,7 +22387,9 @@ static int ecc_test_curve(WC_RNG* rng, int keySize)
#ifdef HAVE_ECC_VECTOR_TEST #ifdef HAVE_ECC_VECTOR_TEST
ret = ecc_test_vector(keySize); ret = ecc_test_vector(keySize);
if (ret < 0) { if (ret < 0) {
#ifndef NO_TEST_PRINTF
printf("ecc_test_vector %d failed!: %d\n", keySize, ret); printf("ecc_test_vector %d failed!: %d\n", keySize, ret);
#endif
return ret; return ret;
} }
#endif #endif
@ -22390,7 +22402,9 @@ static int ecc_test_curve(WC_RNG* rng, int keySize)
/* ignore error for curves not found */ /* ignore error for curves not found */
} }
else { else {
#ifndef NO_TEST_PRINTF
printf("ecc_test_key_decode %d failed!: %d\n", keySize, ret); printf("ecc_test_key_decode %d failed!: %d\n", keySize, ret);
#endif
return ret; return ret;
} }
} }
@ -22403,7 +22417,9 @@ static int ecc_test_curve(WC_RNG* rng, int keySize)
/* ignore error for curves not found */ /* ignore error for curves not found */
} }
else { else {
#ifndef NO_TEST_PRINTF
printf("ecc_test_key_gen %d failed!: %d\n", keySize, ret); printf("ecc_test_key_gen %d failed!: %d\n", keySize, ret);
#endif
return ret; return ret;
} }
} }
@ -24202,14 +24218,18 @@ WOLFSSL_TEST_SUBROUTINE int ecc_test(void)
#if defined(HAVE_ECC_SIGN) && defined(WOLFSSL_ECDSA_SET_K) #if defined(HAVE_ECC_SIGN) && defined(WOLFSSL_ECDSA_SET_K)
ret = ecc_test_sign_vectors(&rng); ret = ecc_test_sign_vectors(&rng);
if (ret != 0) { if (ret != 0) {
#ifndef NO_TEST_PRINTF
printf("ecc_test_sign_vectors failed! %d\n", ret); printf("ecc_test_sign_vectors failed! %d\n", ret);
#endif
goto done; goto done;
} }
#endif #endif
#ifdef HAVE_ECC_CDH #ifdef HAVE_ECC_CDH
ret = ecc_test_cdh_vectors(&rng); ret = ecc_test_cdh_vectors(&rng);
if (ret != 0) { if (ret != 0) {
#ifndef NO_TEST_PRINTF
printf("ecc_test_cdh_vectors failed! %d\n", ret); printf("ecc_test_cdh_vectors failed! %d\n", ret);
#endif
goto done; goto done;
} }
#endif #endif
@ -24217,7 +24237,9 @@ WOLFSSL_TEST_SUBROUTINE int ecc_test(void)
!defined(WOLFSSL_STM32_PKA) && !defined(WOLFSSL_SILABS_SE_ACCEL) !defined(WOLFSSL_STM32_PKA) && !defined(WOLFSSL_SILABS_SE_ACCEL)
ret = ecc_test_make_pub(&rng); ret = ecc_test_make_pub(&rng);
if (ret != 0) { if (ret != 0) {
#ifndef NO_TEST_PRINTF
printf("ecc_test_make_pub failed!: %d\n", ret); printf("ecc_test_make_pub failed!: %d\n", ret);
#endif
goto done; goto done;
} }
#elif defined(HAVE_ECC_KEY_IMPORT) #elif defined(HAVE_ECC_KEY_IMPORT)
@ -24226,14 +24248,18 @@ WOLFSSL_TEST_SUBROUTINE int ecc_test(void)
#ifdef WOLFSSL_CERT_GEN #ifdef WOLFSSL_CERT_GEN
ret = ecc_test_cert_gen(&rng); ret = ecc_test_cert_gen(&rng);
if (ret != 0) { if (ret != 0) {
#ifndef NO_TEST_PRINTF
printf("ecc_test_cert_gen failed!: %d\n", ret); printf("ecc_test_cert_gen failed!: %d\n", ret);
#endif
goto done; goto done;
} }
#endif #endif
#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && !defined(WOLFSSL_NO_MALLOC) #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && !defined(WOLFSSL_NO_MALLOC)
ret = ecc_test_allocator(&rng); ret = ecc_test_allocator(&rng);
if (ret != 0) { if (ret != 0) {
#ifndef NO_TEST_PRINTF
printf("ecc_test_allocator failed!: %d\n", ret); printf("ecc_test_allocator failed!: %d\n", ret);
#endif
goto done; goto done;
} }
#endif #endif

View File

@ -1847,7 +1847,9 @@ WOLFSSL_API int wolfSSL_ASN1_TIME_print(WOLFSSL_BIO*, const WOLFSSL_ASN1_TIME*);
WOLFSSL_API char* wolfSSL_ASN1_TIME_to_string(WOLFSSL_ASN1_TIME* t, WOLFSSL_API char* wolfSSL_ASN1_TIME_to_string(WOLFSSL_ASN1_TIME* t,
char* buf, int len); char* buf, int len);
#ifndef NO_ASN_TIME
WOLFSSL_API int wolfSSL_ASN1_TIME_to_tm(const WOLFSSL_ASN1_TIME*, struct tm*); WOLFSSL_API int wolfSSL_ASN1_TIME_to_tm(const WOLFSSL_ASN1_TIME*, struct tm*);
#endif
WOLFSSL_API int wolfSSL_ASN1_INTEGER_cmp(const WOLFSSL_ASN1_INTEGER*, WOLFSSL_API int wolfSSL_ASN1_INTEGER_cmp(const WOLFSSL_ASN1_INTEGER*,
const WOLFSSL_ASN1_INTEGER*); const WOLFSSL_ASN1_INTEGER*);
WOLFSSL_API long wolfSSL_ASN1_INTEGER_get(const WOLFSSL_ASN1_INTEGER*); WOLFSSL_API long wolfSSL_ASN1_INTEGER_get(const WOLFSSL_ASN1_INTEGER*);

View File

@ -107,7 +107,7 @@ void ato24(const byte* c, word32* u24);
void ato32(const byte* c, word32* u32); void ato32(const byte* c, word32* u32);
word32 btoi(byte b); word32 btoi(byte b);
WOLFSSL_LOCAL char HexCharToByte(char ch); WOLFSSL_LOCAL signed char HexCharToByte(char ch);
WOLFSSL_LOCAL char ByteToHex(byte in); WOLFSSL_LOCAL char ByteToHex(byte in);
WOLFSSL_LOCAL int ByteToHexStr(byte in, char* out); WOLFSSL_LOCAL int ByteToHexStr(byte in, char* out);