Skip to content

Commit 7f9702f

Browse files
authored
Merge pull request #321 from Frauschi/various_fixes
Various fixes
2 parents 80f0133 + 2306471 commit 7f9702f

19 files changed

Lines changed: 211 additions & 195 deletions

benchmark/bench_modules/wh_bench_mod_rsa.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* You should have received a copy of the GNU General Public License
1717
* along with wolfHSM. If not, see <http://www.gnu.org/licenses/>.
1818
*/
19+
#include <string.h>
1920
#include "wh_bench_mod.h"
2021
#include "wolfhsm/wh_error.h"
2122
#include "wolfhsm/wh_client.h"
@@ -384,10 +385,11 @@ int _benchRsaCrypt(whClientContext* client, whBenchOpContext* ctx, int id,
384385
goto exit;
385386
}
386387

387-
strcpy((char*)inBuf, inStr);
388+
strncpy((char*)inBuf, inStr, sizeof(inBuf)-1);
389+
inBuf[sizeof(inBuf)-1] = '\0';
388390

389391
/* Do an initial encryption to get the size of the output */
390-
encSz = ret = wc_RsaPublicEncrypt(inBuf, sizeof(inStr), outBuf,
392+
encSz = ret = wc_RsaPublicEncrypt(inBuf, strlen(inStr), outBuf,
391393
sizeof(outBuf), rsa, rng);
392394
if (ret < 0) {
393395
WH_BENCH_PRINTF("Failed to wc_RsaPublicEncrypt %d\n", ret);
@@ -408,7 +410,7 @@ int _benchRsaCrypt(whClientContext* client, whBenchOpContext* ctx, int id,
408410

409411
if (operation == RSA_PUBLIC_ENCRYPT) {
410412
benchStartRet = wh_Bench_StartOp(ctx, id);
411-
opRet = wc_RsaPublicEncrypt(inBuf, sizeof(inStr), outBuf,
413+
opRet = wc_RsaPublicEncrypt(inBuf, strlen(inStr), outBuf,
412414
sizeof(outBuf), rsa, rng);
413415
benchStopRet = wh_Bench_StopOp(ctx, id);
414416
}

benchmark/wh_bench.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@
5858
/* Buffer sizes for transport */
5959
/* Large enough to handle an RSA 4096 key */
6060
#define BUFFER_SIZE \
61-
sizeof(whTransportMemCsr) + sizeof(whCommHeader) + WOLFHSM_CFG_COMM_DATA_LEN
61+
(sizeof(whTransportMemCsr) + sizeof(whCommHeader) + \
62+
WOLFHSM_CFG_COMM_DATA_LEN)
6263
#define FLASH_RAM_SIZE (1024 * 1024) /* 1MB */
6364

6465
typedef struct BenchModule {
@@ -826,14 +827,14 @@ static void _whBenchClientServerThreadTest(whClientConfig* c_conf,
826827
rc = pthread_create(&cthread, NULL, _whBenchClientTask, &clientData);
827828
if (rc == 0) {
828829
/* Wait for client to finish, then cancel server */
829-
pthread_join(cthread, &retval);
830-
pthread_cancel(sthread);
831-
pthread_join(sthread, &retval);
830+
(void)pthread_join(cthread, &retval);
831+
(void)pthread_cancel(sthread);
832+
(void)pthread_join(sthread, &retval);
832833
}
833834
else {
834835
/* If client thread creation failed, cancel server */
835-
pthread_cancel(sthread);
836-
pthread_join(sthread, &retval);
836+
(void)pthread_cancel(sthread);
837+
(void)pthread_join(sthread, &retval);
837838
}
838839
}
839840
}

benchmark/wh_bench_ops.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -346,27 +346,27 @@ int wh_Bench_PrintResults(whBenchOpContext* ctx)
346346

347347
if (throughput < 1024.0) {
348348
/* Bytes per second */
349-
WH_BENCH_SNPRINTF(buffer, sizeof(buffer), "%.2f B/s",
350-
throughput);
349+
(void)WH_BENCH_SNPRINTF(buffer, sizeof(buffer), "%.2f B/s",
350+
throughput);
351351
}
352352
else if (throughput < 1024.0 * 1024.0) {
353353
/* Kilobytes per second */
354-
WH_BENCH_SNPRINTF(buffer, sizeof(buffer), "%.2f KB/s",
355-
throughput / 1024.0);
354+
(void)WH_BENCH_SNPRINTF(buffer, sizeof(buffer), "%.2f KB/s",
355+
throughput / 1024.0);
356356
}
357357
else {
358358
/* Megabytes per second */
359-
WH_BENCH_SNPRINTF(buffer, sizeof(buffer), "%.2f MB/s",
360-
throughput / (1024.0 * 1024.0));
359+
(void)WH_BENCH_SNPRINTF(buffer, sizeof(buffer), "%.2f MB/s",
360+
throughput / (1024.0 * 1024.0));
361361
}
362362
}
363363
else if (ctx->ops[i].throughputType == BENCH_THROUGHPUT_OPS) {
364-
WH_BENCH_SNPRINTF(buffer, sizeof(buffer), "%.2f ops/s",
365-
ctx->ops[i].throughput);
364+
(void)WH_BENCH_SNPRINTF(buffer, sizeof(buffer), "%.2f ops/s",
365+
ctx->ops[i].throughput);
366366
}
367367
else {
368368
/* No throughput */
369-
WH_BENCH_SNPRINTF(buffer, sizeof(buffer), "N/A");
369+
(void)WH_BENCH_SNPRINTF(buffer, sizeof(buffer), "N/A");
370370
}
371371
WH_BENCH_PRINTF("%-18s |\n", buffer);
372372
}

examples/demo/client/wh_demo_client_crypto.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ int wh_DemoClient_CryptoRsa(whClientContext* clientContext)
6767
WC_RNG rng[1];
6868

6969
/* set the plainText to the test string */
70-
strcpy((char*)plainText, plainString);
70+
strncpy((char*)plainText, plainString, sizeof(plainText)-1);
71+
plainText[sizeof(plainText)-1] = '\0';
7172

7273
/* initialize rng to make the rsa key */
7374
ret = wc_InitRng_ex(rng, NULL, WH_DEV_ID);
@@ -144,7 +145,8 @@ int wh_DemoClient_CryptoRsaImport(whClientContext* clientContext)
144145
WC_RNG rng[1];
145146

146147
/* set the plainText to the test string */
147-
strcpy((char*)plainText, plainString);
148+
strncpy((char*)plainText, plainString, sizeof(plainText)-1);
149+
plainText[sizeof(plainText)-1] = '\0';
148150

149151
/* initialize rng to encrypt with the rsa key */
150152
ret = wc_InitRng_ex(rng, NULL, WH_DEV_ID);
@@ -497,7 +499,8 @@ int wh_DemoClient_CryptoEcc(whClientContext* clientContext)
497499
byte signature[128];
498500

499501
/* Set the message to the test string */
500-
strcpy((char*)message, plainMessage);
502+
strncpy((char*)message, plainMessage, sizeof(message)-1);
503+
message[sizeof(message)-1] = '\0';
501504

502505
/* Initialize the rng to make the ecc keys */
503506
ret = wc_InitRng_ex(rng, NULL, WH_DEV_ID);
@@ -627,7 +630,8 @@ int wh_DemoClient_CryptoEccImport(whClientContext* clientContext)
627630
uint8_t keyBuf[256];
628631

629632
/* Set the message to the test string */
630-
strcpy((char*)message, plainMessage);
633+
strncpy((char*)message, plainMessage, sizeof(message)-1);
634+
message[sizeof(message)-1] = '\0';
631635

632636
/* Initialize the rng for signature signing */
633637
ret = wc_InitRng_ex(rng, NULL, WH_DEV_ID);

examples/posix/wh_posix_client/wh_posix_client_cfg.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ static unsigned int psk_tls12_client_cb(WOLFSSL* ssl, const char* hint,
188188
printf("PSK server identity hint: %s\n", hint);
189189
printf("PSK using identity: %s\n", exampleIdentity);
190190
strncpy(identity, exampleIdentity, id_max_len);
191+
identity[id_max_len-1] = '\0';
191192

192193
printf("Enter PSK password: ");
193194
if (fgets((char*)key, key_max_len - 1, stdin) == NULL) {

examples/posix/wh_posix_server/wh_posix_server_cfg.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ static void parseNvmInitFile(const char* filePath)
478478
fclose(file);
479479
exit(EXIT_FAILURE);
480480
}
481-
snprintf(label, sizeof(label), "%s", token);
481+
(void)snprintf(label, sizeof(label), "%s", token);
482482

483483
/* Parse the file path */
484484
token = strtok(NULL, " ");
@@ -508,9 +508,9 @@ static void processEntry(Entry* entry, int isKey, whNvmContext* nvmContext)
508508
}
509509

510510
/* Get the file size */
511-
fseek(file, 0, SEEK_END);
511+
(void)fseek(file, 0, SEEK_END);
512512
long fileSize = ftell(file);
513-
fseek(file, 0, SEEK_SET);
513+
(void)fseek(file, 0, SEEK_SET);
514514

515515
/* Allocate memory for the file data */
516516
uint8_t* buffer = (uint8_t*)malloc(fileSize);
@@ -553,7 +553,7 @@ static void processEntry(Entry* entry, int isKey, whNvmContext* nvmContext)
553553
meta.access = entry->access;
554554
meta.flags = entry->flags;
555555
meta.len = fileSize;
556-
snprintf((char*)meta.label, WH_NVM_LABEL_LEN, "%s", entry->label);
556+
(void)snprintf((char*)meta.label, WH_NVM_LABEL_LEN, "%s", entry->label);
557557

558558
int rc = wh_Nvm_AddObject(nvmContext, &meta, fileSize, buffer);
559559
if (rc != 0) {

port/posix/posix_flash_file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ enum {
4141
};
4242

4343
/** Local declarations */
44-
#define MAX_OFFSET(_context) (_context->partition_size * 2)
44+
#define MAX_OFFSET(_context) ((_context)->partition_size * 2)
4545

4646
/* Helper for pwrite like memset. Write the byte in c to filedes for size
4747
* bytes starting at offset */

0 commit comments

Comments
 (0)