mirror of
https://github.com/SELinuxProject/selinux
synced 2025-04-11 04:01:46 +00:00
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:
parent
8730e0762e
commit
04613f6875
@ -152,6 +152,12 @@ int main(int argc, char *argv[])
|
|||||||
file_size = filedata.st_size;
|
file_size = filedata.st_size;
|
||||||
|
|
||||||
buffer = malloc(file_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);
|
rc = fread(buffer, file_size, 1, file);
|
||||||
if (rc != 1) {
|
if (rc != 1) {
|
||||||
fprintf(stderr, "Failure reading file: %s\n", argv[i]);
|
fprintf(stderr, "Failure reading file: %s\n", argv[i]);
|
||||||
|
@ -158,6 +158,12 @@ int main(int argc, char *argv[])
|
|||||||
file_size = filedata.st_size;
|
file_size = filedata.st_size;
|
||||||
|
|
||||||
buffer = malloc(file_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);
|
rc = fread(buffer, file_size, 1, file);
|
||||||
if (rc != 1) {
|
if (rc != 1) {
|
||||||
fprintf(stderr, "Failure reading file: %s\n", argv[i]);
|
fprintf(stderr, "Failure reading file: %s\n", argv[i]);
|
||||||
|
@ -286,6 +286,12 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
buffer = malloc(file_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);
|
rc = fread(buffer, file_size, 1, file);
|
||||||
if (rc != 1) {
|
if (rc != 1) {
|
||||||
fprintf(stderr, "Failure reading file: %s\n", argv[i]);
|
fprintf(stderr, "Failure reading file: %s\n", argv[i]);
|
||||||
|
Loading…
Reference in New Issue
Block a user