On Wed, Jul 19, 2023 at 2:47 PM James Carter <jwcart2@xxxxxxxxx> wrote: > > On Thu, Jul 13, 2023 at 5:12 AM Huaxin Lu <luhuaxin1@xxxxxxxxxx> wrote: > > > > Check the return value of malloc() to avoid null pointer reference. > > > > Signed-off-by: Huaxin Lu <luhuaxin1@xxxxxxxxxx> > > Acked-by: James Carter <jwcart2@xxxxxxxxx> > Merged. Thanks, Jim > > --- > > secilc/secil2conf.c | 6 ++++++ > > secilc/secil2tree.c | 6 ++++++ > > secilc/secilc.c | 6 ++++++ > > 3 files changed, 18 insertions(+) > > > > diff --git a/secilc/secil2conf.c b/secilc/secil2conf.c > > index c49522e..bf050f3 100644 > > --- a/secilc/secil2conf.c > > +++ b/secilc/secil2conf.c > > @@ -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]); > > diff --git a/secilc/secil2tree.c b/secilc/secil2tree.c > > index e5cdf6b..d04566d 100644 > > --- a/secilc/secil2tree.c > > +++ b/secilc/secil2tree.c > > @@ -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]); > > diff --git a/secilc/secilc.c b/secilc/secilc.c > > index 80d3583..f3102ca 100644 > > --- a/secilc/secilc.c > > +++ b/secilc/secilc.c > > @@ -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]); > > -- > > 2.33.0 > >