forked from wolfSSL/wolfssl
Reworked expect_tok to fix NULL dereferences
This commit is contained in:
@ -26,7 +26,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
/* Uncomment next line to enable 2-bytes ID demo */
|
/* Uncomment next line to enable 2-bytes ID demo */
|
||||||
/* #define TWO_BYTES_ID_DEMO */
|
#define TWO_BYTES_ID_DEMO
|
||||||
|
|
||||||
|
|
||||||
/* IOT-Safe slot configurations for this example:
|
/* IOT-Safe slot configurations for this example:
|
||||||
|
@ -123,14 +123,17 @@ static int bytes_to_hex(const unsigned char *bytes, char *hex, unsigned long sz)
|
|||||||
|
|
||||||
static int expect_tok(const char *cmd, int size, const char *tok, char **repl)
|
static int expect_tok(const char *cmd, int size, const char *tok, char **repl)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
|
||||||
char *r_found = NULL;
|
char *r_found = NULL;
|
||||||
static char parser_line[MAXBUF / 2];
|
static char parser_line[MAXBUF / 2];
|
||||||
if (repl) {
|
char *reply = NULL;
|
||||||
*repl = NULL;
|
int ret;
|
||||||
}
|
|
||||||
if (cmd) {
|
if (cmd) {
|
||||||
ret = csim_write(cmd, size);
|
ret = csim_write(cmd, size);
|
||||||
|
if (ret <= 0)
|
||||||
|
return ret;
|
||||||
|
} else {
|
||||||
|
/* Force enter the read loop on cmd == NULL */
|
||||||
|
ret = 1;
|
||||||
}
|
}
|
||||||
while (ret > 0) {
|
while (ret > 0) {
|
||||||
ret = csim_read(csim_read_buf, MAXBUF);
|
ret = csim_read(csim_read_buf, MAXBUF);
|
||||||
@ -150,12 +153,25 @@ static int expect_tok(const char *cmd, int size, const char *tok, char **repl)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((ret >= 0) && (repl && r_found)) {
|
if ((ret >= 0) && (r_found)) {
|
||||||
*repl = parser_line + XSTRLEN(tok);
|
reply = parser_line + XSTRLEN(tok);
|
||||||
}
|
/* If the reply consists of token only,
|
||||||
if (r_found) {
|
* return the entire string.
|
||||||
ret = (int)XSTRLEN(*repl);
|
*/
|
||||||
|
if (XSTRLEN(reply) == 0) {
|
||||||
|
reply = parser_line;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
/* Assign the pointer to the received reply
|
||||||
|
* only if repl is not NULL
|
||||||
|
*/
|
||||||
|
if (repl)
|
||||||
|
*repl = reply;
|
||||||
|
|
||||||
|
if (reply)
|
||||||
|
ret = (int)XSTRLEN(reply);
|
||||||
|
else
|
||||||
|
ret = 0;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -565,7 +581,6 @@ static int iotsafe_parse_public_key(char* resp, int len, ecc_key *key)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
WOLFSSL_MSG("Get Public key: OK");
|
WOLFSSL_MSG("Get Public key: OK");
|
||||||
printf("public key: %s, %s\n", Qx, Qy);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -674,7 +689,6 @@ static int iotsafe_put_public_key(byte *pubkey_id, unsigned long id_size,
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//printf("put_public returning %d\n", ret);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -716,7 +730,7 @@ static int iotsafe_sign_hash(byte *privkey_idx, uint16_t id_size,
|
|||||||
} while (ret == 0);
|
} while (ret == 0);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return WC_HW_E;
|
return WC_HW_E;
|
||||||
|
|
||||||
/* Compose sign_update message with hash to sign */
|
/* Compose sign_update message with hash to sign */
|
||||||
iotsafe_cmd_start(csim_cmd, IOTSAFE_CLASS,
|
iotsafe_cmd_start(csim_cmd, IOTSAFE_CLASS,
|
||||||
IOTSAFE_INS_SIGN_UPDATE,
|
IOTSAFE_INS_SIGN_UPDATE,
|
||||||
@ -820,7 +834,6 @@ static int iotsafe_verify_hash(byte *pubkey_idx, uint16_t id_size,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (ret == 0) {
|
else if (ret == 0) {
|
||||||
//printf("Verify OK!\n");
|
|
||||||
*result = 1;
|
*result = 1;
|
||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
@ -832,7 +845,7 @@ static int iotsafe_verify_hash(byte *pubkey_idx, uint16_t id_size,
|
|||||||
*result = 0;
|
*result = 0;
|
||||||
ret = WC_HW_E;
|
ret = WC_HW_E;
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
ret = expect_ok("AT\r\n", 4);
|
ret = expect_ok("AT\r\n", 4);
|
||||||
} while (ret == 0);
|
} while (ret == 0);
|
||||||
|
Reference in New Issue
Block a user