secilc: add check for malloc in secilc

Check the return value of malloc() to avoid null pointer reference.

Signed-off-by: Huaxin Lu <luhuaxin1@huawei.com>
Acked-by: James Carter <jwcart2@gmail.com>
This commit is contained in:
Huaxin Lu 2023-07-13 14:35:04 +08:00 committed by James Carter
parent 8730e0762e
commit 04613f6875
3 changed files with 18 additions and 0 deletions

View File

@ -152,6 +152,12 @@ int main(int argc, char *argv[])
file_size = filedata.st_size;
buffer = malloc(file_size);
if (!buffer) {
fprintf(stderr, "Out of memory\n");
rc = SEPOL_ERR;
goto exit;
}
rc = fread(buffer, file_size, 1, file);
if (rc != 1) {
fprintf(stderr, "Failure reading file: %s\n", argv[i]);

View File

@ -158,6 +158,12 @@ int main(int argc, char *argv[])
file_size = filedata.st_size;
buffer = malloc(file_size);
if (!buffer) {
fprintf(stderr, "Out of memory\n");
rc = SEPOL_ERR;
goto exit;
}
rc = fread(buffer, file_size, 1, file);
if (rc != 1) {
fprintf(stderr, "Failure reading file: %s\n", argv[i]);

View File

@ -286,6 +286,12 @@ int main(int argc, char *argv[])
}
buffer = malloc(file_size);
if (!buffer) {
fprintf(stderr, "Out of memory\n");
rc = SEPOL_ERR;
goto exit;
}
rc = fread(buffer, file_size, 1, file);
if (rc != 1) {
fprintf(stderr, "Failure reading file: %s\n", argv[i]);