Skip to content

Commit c846590

Browse files
committed
To fix webconfig crash while using testutility with empty multipart bin
1 parent 2cc2a87 commit c846590

2 files changed

Lines changed: 20 additions & 8 deletions

File tree

src/webcfg.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -834,11 +834,21 @@ int testUtility()
834834

835835
if(readFromFile(TEST_FILE_LOCATION, &data, &test_dataSize) == 1)
836836
{
837+
if(data != NULL && test_dataSize == 0)
838+
{
839+
WebcfgError("Test file is empty\n");
840+
return 0;
841+
}
837842
set_g_testfile(1);
838843
WebcfgInfo("Using Test file \n");
839844

840845
char * data_body = malloc(sizeof(char) * test_dataSize+1);
841-
memset(data_body, 0, sizeof(char) * test_dataSize+1);
846+
if( NULL == data_body )
847+
{
848+
WebcfgError("Memory allocation for data_body failed.\n");
849+
return 0;
850+
}
851+
memset(data_body, 0, sizeof(char) * (test_dataSize + 1));
842852
data_body = memcpy(data_body, data, test_dataSize+1);
843853
data_body[test_dataSize] = '\0';
844854
char *ptr_count = data_body;
@@ -904,10 +914,6 @@ int testUtility()
904914
{
905915
WebcfgInfo("Test webConfigData applied successfully\n");
906916
}
907-
else
908-
{
909-
WebcfgError("Failed to apply Test root webConfigData received from server\n");
910-
}
911917
}
912918
else
913919
{

src/webcfg_multipart.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ WEBCFG_STATUS parseMultipartDocument(void *config_data, char *ct , size_t data_s
589589
}
590590
else
591591
{
592-
WebcfgDebug("processMsgpackSubdoc done,docs are sent for apply\n");
592+
WebcfgInfo("processMsgpackSubdoc done,docs are sent for apply\n");
593593
}
594594
return WEBCFG_FAILURE;
595595
}
@@ -1323,13 +1323,19 @@ int readFromFile(char *filename, char **data, int *len)
13231323
ch_count = ftell(fp);
13241324
fseek(fp, 0, SEEK_SET);
13251325
*data = (char *) malloc(sizeof(char) * (ch_count + 1));
1326-
sz = fread(*data, 1, ch_count-1,fp);
1326+
if( NULL == *data )
1327+
{
1328+
WebcfgError("Memory allocation for data failed.\n");
1329+
fclose(fp);
1330+
return 0;
1331+
}
1332+
sz = fread(*data, 1, ch_count,fp);
13271333
if (!sz)
13281334
{
13291335
fclose(fp);
13301336
WebcfgError("fread failed.\n");
13311337
WEBCFG_FREE(*data);
1332-
return WEBCFG_FAILURE;
1338+
return 0;
13331339
}
13341340
*len = ch_count;
13351341
(*data)[ch_count] ='\0';

0 commit comments

Comments
 (0)