libsepol: Fix index off-by-one errors for categories
PATCH 1/1 libsepol: Fix index off-by-one errors for categories
The category bitmap for a MLS level or range start at 0 as does the p_cat_val_to_name array, so just the bit position should be used without subtracting one from it.
--- libsepol/src/mls.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
libsepol/src/mls.c +6 -8
@@ -138,14 +138,14 @@ int mls_compute_context_len(const policydb_t * policydb,if (range >1 ) len +=strlen (policydb-> - p_cat_val_to_name[i -1 ]) + + p_cat_val_to_name[i]) +1 ; range =0 ; } }/* Handle case where last category is the end of range */ if (range >1 ) - len +=strlen (policydb->p_cat_val_to_name[i -1 ]) +1 ; + len +=strlen (policydb->p_cat_val_to_name[i]) +1 ;if (l ==0 ) { if (mls_level_eq(&context->range.level[0],
@@ -216,11 +216,9 @@ void mls_sid_to_context(const policydb_t * policydb, *scontextp++ =',' ;strcpy (scontextp, - policydb->p_cat_val_to_name[i - -1 ]); + policydb->p_cat_val_to_name[i]); scontextp += -strlen (policydb-> - p_cat_val_to_name[i -1 ]); +strlen (policydb->p_cat_val_to_name[i]); } range =0 ; }
@@ -232,8 +230,8 @@ void mls_sid_to_context(const policydb_t * policydb,else *scontextp++ =',' ; -strcpy (scontextp, policydb->p_cat_val_to_name[i -1 ]); - scontextp +=strlen (policydb->p_cat_val_to_name[i -1 ]); +strcpy (scontextp, policydb->p_cat_val_to_name[i]); + scontextp +=strlen (policydb->p_cat_val_to_name[i]); }if (l ==0 ) {
Signature · 1 line
2.54.0
Stephen Smalley
maintainerQuoted 15 lines · James Carter
The category bitmap for a MLS level or range start at 0 as does the
p_cat_val_to_namearray, so just the bit position should be used without subtracting one from it.Signed-off-by James Carter <[email protected]>--- libsepol/src/mls.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)libsepol/src/mls.c +0
-0
libsepol/src/mls.c int mls_compute_context_len(const policydb_t * policydb, · line 141
Quoted 5 lines
libsepol/src/mls.c +1
-1@@ -138,14 +138,14 @@ int mls_compute_context_len(const policydb_t * policydb,if (range >1 ) len +=strlen (policydb-> - p_cat_val_to_name[i - 1]) + + p_cat_val_to_name[i]) +
FTR, this and possibly the later uses of i - 1 are intentional to reflect the last set category in the range.
May want to compare with the kernel code and synchronize them as appropriate.
Quoted 40 lines
libsepol/src/mls.c +5
-81 ; range =0 ; } }/* Handle case where last category is the end of range */ if (range >1 ) - len +=strlen (policydb->p_cat_val_to_name[i -1 ]) +1 ; + len +=strlen (policydb->p_cat_val_to_name[i]) +1 ;if (l ==0 ) { if (mls_level_eq(&context->range.level[0],@@ -216,11 +216,9 @@ void mls_sid_to_context(const policydb_t * policydb, *scontextp++ =',' ;strcpy (scontextp, - policydb->p_cat_val_to_name[i - -1 ]); + policydb->p_cat_val_to_name[i]); scontextp += -strlen (policydb-> - p_cat_val_to_name[i -1 ]); +strlen (policydb->p_cat_val_to_name[i]); } range =0 ; }@@ -232,8 +230,8 @@ void mls_sid_to_context(const policydb_t * policydb,else *scontextp++ =',' ; -strcpy (scontextp, policydb->p_cat_val_to_name[i -1 ]); - scontextp +=strlen (policydb->p_cat_val_to_name[i -1 ]); +strcpy (scontextp, policydb->p_cat_val_to_name[i]); + scontextp +=strlen (policydb->p_cat_val_to_name[i]); }if (l ==0 ) { --2.54.0
Quoted 6 lines · James Carter
The category bitmap for a MLS level or range start at 0 as does the
p_cat_val_to_namearray, so just the bit position should be used without subtracting one from it.Signed-off-by James Carter <[email protected]>
Ignore this patch. I was confused. This code is collapsing category sets and actually wants to refer to the previous category, so it is correct.
Jim
Quoted 53 lines
--- libsepol/src/mls.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)libsepol/src/mls.c +6
-9@@ -138,14 +138,14 @@ int mls_compute_context_len(const policydb_t * policydb,if (range >1 ) len +=strlen (policydb-> - p_cat_val_to_name[i -1 ]) + + p_cat_val_to_name[i]) +1 ; range =0 ; } }/* Handle case where last category is the end of range */ if (range >1 ) - len +=strlen (policydb->p_cat_val_to_name[i -1 ]) +1 ; + len +=strlen (policydb->p_cat_val_to_name[i]) +1 ;if (l ==0 ) { if (mls_level_eq(&context->range.level[0],@@ -216,11 +216,9 @@ void mls_sid_to_context(const policydb_t * policydb, *scontextp++ =',' ;strcpy (scontextp, - policydb->p_cat_val_to_name[i - -1 ]); + policydb->p_cat_val_to_name[i]); scontextp += -strlen (policydb-> - p_cat_val_to_name[i -1 ]); +strlen (policydb->p_cat_val_to_name[i]); } range =0 ; }@@ -232,8 +230,8 @@ void mls_sid_to_context(const policydb_t * policydb,else *scontextp++ =',' ; -strcpy (scontextp, policydb->p_cat_val_to_name[i -1 ]); - scontextp +=strlen (policydb->p_cat_val_to_name[i -1 ]); +strcpy (scontextp, policydb->p_cat_val_to_name[i]); + scontextp +=strlen (policydb->p_cat_val_to_name[i]); }if (l ==0 ) { --2.54.0