libsepol: constify tokenized input
PATCH 1/3 libsepol: constify tokenized input
The input string to be tokenized is not modified.
Signed-off-by Christian Göttsche <[email protected]>
--- libsepol/include/sepol/policydb/util.h | 2 +- libsepol/src/util.c | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-)
libsepol/include/sepol/policydb/util.h +1 -1
@@ -40,7 +40,7 @@ char *sepol_extended_perms_to_string(avtab_extended_perms_t *xperms);* The tokenize function may be used to * replace sscanf */ -extern int tokenize (char *line_buf,char delim,int num_args, ...); +extern int tokenize (const char *line_buf,char delim,int num_args, ...); #ifdef __cplusplus }
libsepol/src/util.c +5 -4
@@ -221,9 +221,9 @@ err:*/ /* Read a token from a buffer */ -static inline int tokenize_str (char delim,char **str,char **ptr,size_t *len) +static inline int tokenize_str (char delim,char **str,const char **ptr,size_t *len) { -char *tmp_buf = *ptr; +const char *tmp_buf = *ptr; *str =NULL ;while (**ptr !='\0' ) {
@@ -273,9 +273,10 @@ static inline int tokenize_str(char delim, char **str, char **ptr, size_t *len)* contain the remaining content of line_buf. If the delimiter is any whitespace * character, then all whitespace will be squashed. */ -int tokenize (char *line_buf,char delim,int num_args, ...) +int tokenize (const char *line_buf,char delim,int num_args, ...) { -char **arg, *buf_p; +char **arg; +const char *buf_p;int rc, items;size_t arg_len =0 ;va_list ap;
Signature · 1 line
2.43.0
PATCH 2/3 libsepol: avoid integer overflow in add_i_to_a()
Signed-off-by Christian Göttsche <[email protected]>
--- libsepol/src/util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libsepol/src/util.c +1 -1
@@ -44,7 +44,7 @@ int add_i_to_a(uint32_t i, uint32_t * cnt, uint32_t ** a) {uint32_t *new; -if (cnt ==NULL || a ==NULL ) +if (cnt ==NULL || *cnt ==UINT32_MAX || a ==NULL )return -1 ;/* FIX ME: This is not very elegant! We use an array that we
Signature · 1 line
2.43.0
PATCH 3/3 libsepol: extended permission formatting cleanup
In reply to Christian GöttscheDeclare the read-only permission parameter const.
Use a more readable overflow check, which is also resilient against changes of the growth factor or initial size.
Signed-off-by Christian Göttsche <[email protected]>
--- libsepol/include/sepol/policydb/util.h | 2 +- libsepol/src/kernel_to_cil.c | 5 ++--- libsepol/src/util.c | 5 ++--- 3 files changed, 5 insertions(+), 7 deletions(-)
libsepol/include/sepol/policydb/util.h +1 -1
@@ -34,7 +34,7 @@ extern int add_i_to_a(uint32_t i, uint32_t * cnt, uint32_t ** a);extern char *sepol_av_to_string (policydb_t * policydbp,uint32_t tclass,sepol_access_vector_t av); -char *sepol_extended_perms_to_string (avtab_extended_perms_t *xperms); +char *sepol_extended_perms_to_string (const avtab_extended_perms_t *xperms);/* * The tokenize function may be used to
libsepol/src/kernel_to_cil.c +2 -3
@@ -1627,7 +1627,7 @@ exit:#define next_bit_in_range (i, p) (((i) + 1 < sizeof(p)*8) && xperm_test(((i) + 1), p)) -static char *xperms_to_str (avtab_extended_perms_t *xperms) +static char *xperms_to_str (const avtab_extended_perms_t *xperms) {uint16_t value;uint16_t low_bit;
@@ -1644,8 +1644,7 @@ static char *xperms_to_str(avtab_extended_perms_t *xperms) } retry: - size *=2 ; -if (size ==0 ) +if (__builtin_mul_overflow (size,2 , &size)) goto err; p =realloc (buffer, size);if (!p)
libsepol/src/util.c +2 -3
@@ -126,7 +126,7 @@ char *sepol_av_to_string(policydb_t * policydbp, uint32_t tclass,#define next_bit_in_range (i, p) (((i) + 1 < sizeof(p)*8) && xperm_test(((i) + 1), p)) -char *sepol_extended_perms_to_string (avtab_extended_perms_t *xperms) +char *sepol_extended_perms_to_string (const avtab_extended_perms_t *xperms) {uint16_t value;uint16_t low_bit;
@@ -142,8 +142,7 @@ char *sepol_extended_perms_to_string(avtab_extended_perms_t *xperms)return NULL ; retry: - size *=2 ; -if (size ==0 ) +if (__builtin_mul_overflow (size,2 , &size)) goto err; p =realloc (buffer, size);if (!p)
Signature · 1 line
2.43.0
Quoted 4 lines · Christian Göttsche
The input string to be tokenized is not modified.
Signed-off-by Christian Göttsche <[email protected]>
For these three patches:
Acked-by James Carter <[email protected]>
Quoted 51 lines
--- libsepol/include/sepol/policydb/util.h | 2 +- libsepol/src/util.c | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-)libsepol/include/sepol/policydb/util.h +1
-1@@ -40,7 +40,7 @@ char *sepol_extended_perms_to_string(avtab_extended_perms_t *xperms);* The tokenize function may be used to * replace sscanf */ -extern int tokenize (char *line_buf,char delim,int num_args, ...); +extern int tokenize (const char *line_buf,char delim,int num_args, ...); #ifdef __cplusplus }libsepol/src/util.c +5
-5@@ -221,9 +221,9 @@ err:*/ /* Read a token from a buffer */ -static inline int tokenize_str (char delim,char **str,char **ptr,size_t *len) +static inline int tokenize_str (char delim,char **str,const char **ptr,size_t *len) { -char *tmp_buf = *ptr; +const char *tmp_buf = *ptr; *str =NULL ;while (**ptr !='\0' ) {@@ -273,9 +273,10 @@ static inline int tokenize_str(char delim, char **str, char **ptr, size_t *len)* contain the remaining content of line_buf. If the delimiter is any whitespace * character, then all whitespace will be squashed. */ -int tokenize (char *line_buf,char delim,int num_args, ...) +int tokenize (const char *line_buf,char delim,int num_args, ...) { -char **arg, *buf_p; +char **arg; +const char *buf_p;int rc, items;size_t arg_len =0 ;va_list ap; --2.43.0
Quoted 11 lines · James Carter
Quoted 4 lines · Christian Göttsche
The input string to be tokenized is not modified.
Signed-off-by Christian Göttsche <[email protected]>For these three patches:
Acked-by James Carter <[email protected]>
These three patches have been merged.
Thanks,
Jim
Quoted 51 lines
Quoted 51 lines
--- libsepol/include/sepol/policydb/util.h | 2 +- libsepol/src/util.c | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-)libsepol/include/sepol/policydb/util.h +1
-1@@ -40,7 +40,7 @@ char *sepol_extended_perms_to_string(avtab_extended_perms_t *xperms);* The tokenize function may be used to * replace sscanf */ -extern int tokenize (char *line_buf,char delim,int num_args, ...); +extern int tokenize (const char *line_buf,char delim,int num_args, ...); #ifdef __cplusplus }libsepol/src/util.c +5
-5@@ -221,9 +221,9 @@ err:*/ /* Read a token from a buffer */ -static inline int tokenize_str (char delim,char **str,char **ptr,size_t *len) +static inline int tokenize_str (char delim,char **str,const char **ptr,size_t *len) { -char *tmp_buf = *ptr; +const char *tmp_buf = *ptr; *str =NULL ;while (**ptr !='\0' ) {@@ -273,9 +273,10 @@ static inline int tokenize_str(char delim, char **str, char **ptr, size_t *len)* contain the remaining content of line_buf. If the delimiter is any whitespace * character, then all whitespace will be squashed. */ -int tokenize (char *line_buf,char delim,int num_args, ...) +int tokenize (const char *line_buf,char delim,int num_args, ...) { -char **arg, *buf_p; +char **arg; +const char *buf_p;int rc, items;size_t arg_len =0 ;va_list ap; --2.43.0