Skip to content

Commit 07b78bd

Browse files
Oren CohenMichael Schwarcz
authored andcommitted
Coverity fixes
1 parent 884d2e5 commit 07b78bd

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed

TESTS/spm/client_tests/server.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ void server_main(void *ptr)
3535
case PSA_IPC_MSG_TYPE_CALL: {
3636
memset(data, 0, sizeof(data));
3737
if (msg.in_size[0] + msg.in_size[1] + msg.in_size[2] > 1) {
38-
size_t offset = 0;
39-
offset += psa_read(msg.handle, 0, (void*)data, msg.in_size[0]);
38+
size_t offset = psa_read(msg.handle, 0, (void*)data, msg.in_size[0]);
4039
offset += psa_read(msg.handle, 1, (void*)(data + offset), msg.in_size[1]);
41-
offset += psa_read(msg.handle, 2, (void*)(data + offset), msg.in_size[2]);
40+
psa_read(msg.handle, 2, (void*)(data + offset), msg.in_size[2]);
4241
}
4342
if (msg.out_size[0] > 0) {
4443
uint8_t resp_size = data[0];

TESTS/spm/server/partition2.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,9 @@ void part2_main(void *ptr)
7373
psa_get(SF_DB_TST_MSK, &msg);
7474

7575
switch (msg.type) {
76-
77-
int32_t caller_part_id = 0;
78-
7976
case PSA_IPC_MSG_TYPE_CALL:
80-
caller_part_id = psa_identity(msg.handle);
77+
{
78+
int32_t caller_part_id = psa_identity(msg.handle);
8179
// Doorbell contract is valid only between secure partitions
8280
if (PSA_NSPE_IDENTIFIER == caller_part_id) {
8381
SPM_PANIC("Caller partition is non secure\n");
@@ -89,6 +87,7 @@ void part2_main(void *ptr)
8987
// After work is done, ring the doorbell
9088
psa_notify(caller_part_id);
9189
break;
90+
}
9291

9392
case PSA_IPC_MSG_TYPE_DISCONNECT:
9493
case PSA_IPC_MSG_TYPE_CONNECT:

TESTS/spm/server/tests.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,14 @@ PSA_TEST_SERVER(msg_size_assertion)
236236
size_t read_size = 0;
237237

238238
char *buff = malloc(sizeof(char) * 11);
239+
if (NULL == buff) {
240+
SPM_PANIC("memory allocation failure\n");
241+
}
239242
memset(buff, 0, 11);
240243

241244
test_status = proccess_connect_request();
242245
if (test_status != PSA_SUCCESS) {
246+
free(buff);
243247
return test_status;
244248
}
245249

@@ -335,10 +339,14 @@ PSA_TEST_SERVER(msg_read_truncation)
335339
uint32_t signals = 0;
336340
size_t read_size = 0;
337341
char *buff = malloc(sizeof(char) * 11);
342+
if (NULL == buff) {
343+
SPM_PANIC("memory allocation failure\n");
344+
}
338345
memset(buff, 0, 11);
339346

340347
test_status = proccess_connect_request();
341348
if (test_status != PSA_SUCCESS) {
349+
free(buff);
342350
return test_status;
343351
}
344352

@@ -378,9 +386,13 @@ PSA_TEST_SERVER(skip_zero)
378386
size_t read_size = 0;
379387
size_t skip_size = 0;
380388
char *buff = malloc(sizeof(char) * 11);
389+
if (NULL == buff) {
390+
SPM_PANIC("memory allocation failure\n");
391+
}
381392

382393
test_status = proccess_connect_request();
383394
if (test_status != PSA_SUCCESS) {
395+
free(buff);
384396
return test_status;
385397
}
386398

@@ -421,9 +433,13 @@ PSA_TEST_SERVER(skip_some)
421433
size_t read_size2 = 0;
422434
size_t skip_size = 0;
423435
char *buff = malloc(sizeof(char) * 11);
436+
if (NULL == buff) {
437+
SPM_PANIC("memory allocation failure\n");
438+
}
424439

425440
test_status = proccess_connect_request();
426441
if (test_status != PSA_SUCCESS) {
442+
free(buff);
427443
return test_status;
428444
}
429445

@@ -466,9 +482,13 @@ PSA_TEST_SERVER(skip_more_than_left)
466482
size_t read_size2 = 0;
467483
size_t skip_size = 0;
468484
char *buff = malloc(sizeof(char) * 8);
485+
if (NULL == buff) {
486+
SPM_PANIC("memory allocation failure\n");
487+
}
469488

470489
test_status = proccess_connect_request();
471490
if (test_status != PSA_SUCCESS) {
491+
free(buff);
472492
return test_status;
473493
}
474494

@@ -596,12 +616,18 @@ PSA_TEST_SERVER(cross_partition_call)
596616
psa_error_t disconnect_status = PSA_SUCCESS;
597617
psa_error_t partition_call_status = PSA_SUCCESS;
598618
uint32_t data_read = 0;
599-
char *buff = malloc(sizeof(char) * 60);
600619
uint32_t str_len = 0;
620+
char *buff = malloc(sizeof(char) * 60);
621+
622+
if (NULL == buff) {
623+
SPM_PANIC("memory allocation failure\n");
624+
}
625+
601626
memset(buff, 0, 60);
602627

603628
test_status = proccess_connect_request();
604629
if (test_status != PSA_SUCCESS) {
630+
free(buff);
605631
return test_status;
606632
}
607633

TESTS/spm/smoke/partition1.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ void part1_main(void *ptr)
4949
MBED_ASSERT(msg.out_size[0] == SERVER_RSP_BUF_SIZE);
5050
uint32_t bytes_read = 0;
5151
char *read_msg_buf = malloc(sizeof(char) * SERVER_READ_MSG_BUF_SIZE);
52+
if (NULL == read_msg_buf) {
53+
error("Failed to allocate Memory");
54+
}
5255
memset(read_msg_buf, 0, SERVER_READ_MSG_BUF_SIZE);
5356
char *read_ptr = read_msg_buf;
5457

0 commit comments

Comments
 (0)