libsepol: Add overflow checks when linking file and netfilter contexts
PATCH 1/1 libsepol: Add overflow checks when linking file and netfilter contexts
Use __builtin_add_overflow() when calculating the total length of all the file and netfilter contexts.
--- libsepol/src/module.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
libsepol/src/module.c +4 -2
@@ -249,7 +249,8 @@ static int link_file_contexts(sepol_module_package_t *base, fc_len = base->file_contexts_len;for (i =0 ; i < num_modules; i++) { - fc_len += modules[i]->file_contexts_len; +if (__builtin_add_overflow (fc_len, modules[i]->file_contexts_len, &fc_len)) +return -1 ; }if ((s = (char *)realloc (base->file_contexts, fc_len)) ==NULL ) {
@@ -281,7 +282,8 @@ static int link_netfilter_contexts(sepol_module_package_t *base, base_nc_len = base->netfilter_contexts_len;for (i =0 ; i < num_modules; i++) { - base_nc_len += modules[i]->netfilter_contexts_len; +if (__builtin_add_overflow (base_nc_len, modules[i]->netfilter_contexts_len, &base_nc_len)) +return -1 ; } if ((base_context = (char *)realloc(base->netfilter_contexts,
Signature · 1 line
2.55.0
PATCH 1/1 libsepol: Use size_t for counting bytes in module.c
Use size_t for variables used to count bytes in the functions read_helper() and write_helper().
--- libsepol/src/module.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
libsepol/src/module.c +2 -2
@@ -345,7 +345,7 @@ int sepol_link_packages(sepol_handle_t *handle, sepol_module_package_t *base,#define _read_helper_bufsize BUFSIZstatic int read_helper (char *buf,struct policy_file *file,uint32_t bytes) { -uint32_t offset, nel, read_len; +size_t offset, nel, read_len;int rc; offset =0 ;
@@ -842,7 +842,7 @@ cleanup:static int write_helper (char *data,size_t len,struct policy_file *file) { -int idx =0 ; +size_t idx =0 ;size_t len2;while (len) {
Signature · 1 line
2.55.0
Re: [PATCH] libsepol: Use size_t for counting bytes in module.c
Quoted 5 lines · James Carter
Use
size_tfor variables used to count bytes in the functionsread_helper()andwrite_helper().Signed-off-by James Carter <[email protected]>
Quoted 29 lines
--- libsepol/src/module.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)libsepol/src/module.c +2
-3@@ -345,7 +345,7 @@ int sepol_link_packages(sepol_handle_t *handle, sepol_module_package_t *base,#define _read_helper_bufsize BUFSIZstatic int read_helper (char *buf,struct policy_file *file,uint32_t bytes) { -uint32_t offset, nel, read_len; +size_t offset, nel, read_len;int rc; offset =0 ;@@ -842,7 +842,7 @@ cleanup:static int write_helper (char *data,size_t len,struct policy_file *file) { -int idx =0 ; +size_t idx =0 ;size_t len2;while (len) { --2.55.0
Stephen Smalley
maintainerRe: [PATCH] libsepol: Use size_t for counting bytes in module.c
Quoted 9 lines · Stephen Smalley
Quoted 5 lines · James Carter
Use
size_tfor variables used to count bytes in the functionsread_helper()andwrite_helper().Signed-off-by James Carter <[email protected]>Acked-by Stephen Smalley <[email protected]>
Merged up through this one.
Quoted 30 lines
Quoted 30 lines
--- libsepol/src/module.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)libsepol/src/module.c +2
-3@@ -345,7 +345,7 @@ int sepol_link_packages(sepol_handle_t *handle, sepol_module_package_t *base,#define _read_helper_bufsize BUFSIZstatic int read_helper (char *buf,struct policy_file *file,uint32_t bytes) { -uint32_t offset, nel, read_len; +size_t offset, nel, read_len;int rc; offset =0 ;@@ -842,7 +842,7 @@ cleanup:static int write_helper (char *data,size_t len,struct policy_file *file) { -int idx =0 ; +size_t idx =0 ;size_t len2;while (len) { --2.55.0
Quoted 5 lines · James Carter
Use
__builtin_add_overflow()when calculating the total length of all the file and netfilter contexts.Signed-off-by James Carter <[email protected]>
Quoted 31 lines
--- libsepol/src/module.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)libsepol/src/module.c +4
-3@@ -249,7 +249,8 @@ static int link_file_contexts(sepol_module_package_t *base, fc_len = base->file_contexts_len;for (i =0 ; i < num_modules; i++) { - fc_len += modules[i]->file_contexts_len; +if (__builtin_add_overflow (fc_len, modules[i]->file_contexts_len, &fc_len)) +return -1 ; }if ((s = (char *)realloc (base->file_contexts, fc_len)) ==NULL ) {@@ -281,7 +282,8 @@ static int link_netfilter_contexts(sepol_module_package_t *base, base_nc_len = base->netfilter_contexts_len;for (i =0 ; i < num_modules; i++) { - base_nc_len += modules[i]->netfilter_contexts_len; +if (__builtin_add_overflow (base_nc_len, modules[i]->netfilter_contexts_len, &base_nc_len)) +return -1 ; } if ((base_context = (char *)realloc(base->netfilter_contexts, --2.55.0