Message ID | 20221121122947.2079109-1-lujie54@huawei.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 001af27a6d32 |
Headers | show |
Series | libselinux: fix some memory issues in db_init | expand |
On Mon, Nov 21, 2022 at 10:15 AM Jie Lu <lujie54@huawei.com> wrote: > > In db_init() > add the interpretation of the return value of strdup() > fix line_buf memory leak if process_line() < 0 > --- You need to add a signed-off-by line. Everything else looks fine. Thanks, Jim > libselinux/src/label_db.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/libselinux/src/label_db.c b/libselinux/src/label_db.c > index 94c05c6d..bd73201c 100644 > --- a/libselinux/src/label_db.c > +++ b/libselinux/src/label_db.c > @@ -293,6 +293,11 @@ db_init(const struct selinux_opt *opts, unsigned nopts, > return NULL; > } > rec->spec_file = strdup(path); > + if (!rec->spec_file) { > + free(catalog); > + fclose(filp); > + return NULL; > + } > > /* > * Parse for each lines > @@ -322,18 +327,19 @@ db_init(const struct selinux_opt *opts, unsigned nopts, > if (process_line(path, line_buf, ++line_num, catalog) < 0) > goto out_error; > } > - free(line_buf); > > if (digest_add_specfile(rec->digest, filp, NULL, sb.st_size, path) < 0) > goto out_error; > > digest_gen_hash(rec->digest); > > + free(line_buf); > fclose(filp); > > return catalog; > > out_error: > + free(line_buf); > for (i = 0; i < catalog->nspec; i++) { > spec_t *spec = &catalog->specs[i]; > > -- > 2.27.0 >
diff --git a/libselinux/src/label_db.c b/libselinux/src/label_db.c index 94c05c6d..bd73201c 100644 --- a/libselinux/src/label_db.c +++ b/libselinux/src/label_db.c @@ -293,6 +293,11 @@ db_init(const struct selinux_opt *opts, unsigned nopts, return NULL; } rec->spec_file = strdup(path); + if (!rec->spec_file) { + free(catalog); + fclose(filp); + return NULL; + } /* * Parse for each lines @@ -322,18 +327,19 @@ db_init(const struct selinux_opt *opts, unsigned nopts, if (process_line(path, line_buf, ++line_num, catalog) < 0) goto out_error; } - free(line_buf); if (digest_add_specfile(rec->digest, filp, NULL, sb.st_size, path) < 0) goto out_error; digest_gen_hash(rec->digest); + free(line_buf); fclose(filp); return catalog; out_error: + free(line_buf); for (i = 0; i < catalog->nspec; i++) { spec_t *spec = &catalog->specs[i];