libselinux: fix some memory issues in db_init
PATCH v2 1/1 libselinux: fix some memory issues in db_init
1. check the return of strdup to avoid a potential NULL reference.
2. make sure line_buf is freed.
Signed-off-by Jie Lu <[email protected]>
--- libselinux/src/label_db.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
libselinux/src/label_db.c +7 -1
@@ -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];
Signature · 1 line
2.27.0
Quoted 5 lines · Jie Lu
1. check the return of strdup to avoid a potential NULL reference.
2. make sureline_bufis freed.Signed-off-by Jie Lu <[email protected]>
Acked-by James Carter <[email protected]>
Quoted 44 lines
--- libselinux/src/label_db.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)libselinux/src/label_db.c +7
-2@@ -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
Quoted 9 lines · James Carter
Quoted 5 lines · Jie Lu
1. check the return of strdup to avoid a potential NULL reference.
2. make sureline_bufis freed.Signed-off-by Jie Lu <[email protected]>Acked-by James Carter <[email protected]>
Merged.
Thanks,
Jim
Quoted 45 lines
Quoted 45 lines
--- libselinux/src/label_db.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)libselinux/src/label_db.c +7
-2@@ -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