libselinux/utils: drop reachable assert in sefcontext_compile
PATCH v2 1/1 libselinux/utils: drop reachable assert in sefcontext_compile
From: Christian Göttsche <[email protected]>
The two asserts following qsort(3) where useful during development to ensure the comparison function and the corresponding pointer handling were correct. They however do not take into account an empty file context definition file containing no definitions and thus stab->nel being NULL. Drop the two asserts.
Also return early to not depend on whether calloc(3) called with a size of zero returns NULL or a special value.
---
v2: fix condition from not zero to equal to zero
--- libselinux/utils/sefcontext_compile.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
libselinux/utils/sefcontext_compile.c +3 -2
@@ -188,6 +188,9 @@ static int write_sidtab(FILE *bin_file, const struct sidtab *stab)if (len !=1 )return -1 ; +if (stab->nel ==0 ) +return 0 ; +/* sort entries by id */ sids =calloc (stab->nel,sizeof (*sids));if (!sids)
@@ -203,8 +206,6 @@ static int write_sidtab(FILE *bin_file, const struct sidtab *stab) }assert (index == stab->nel);qsort (sids, stab->nel,sizeof (struct security_id ), security_id_compare); -assert (sids[0 ].id ==1 ); -assert (sids[stab->nel -1 ].id == stab->nel);/* write raw contexts sorted by id */ for (uint32_t i =0 ; i < stab->nel; i++) {
Signature · 1 line
2.45.2
Quoted 8 lines · Christian Göttsche
From: Christian Göttsche <[email protected]>
The two asserts following qsort(3) where useful during development to ensure the comparison function and the corresponding pointer handling were correct. They however do not take into account an empty file context definition file containing no definitions and thus
stab->nelbeing NULL. Drop the two asserts.
Quoted 7 lines
Also return early to not depend on whether calloc(3) called with a size of zero returns NULL or a special value.
Reported-by Petr Lautrbach <[email protected]>Fixes 92306daf ("libselinux: rework selabel_file(5) database")Signed-off-by Christian Göttsche <[email protected]>
Works for me. Thanks!
Quoted 32 lines
---
v2: fix condition from not zero to equal to zeroSigned-off-by Christian Göttsche <[email protected]>--- libselinux/utils/sefcontext_compile.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)libselinux/utils/sefcontext_compile.c +3
-2@@ -188,6 +188,9 @@ static int write_sidtab(FILE *bin_file, const struct sidtab *stab)if (len !=1 )return -1 ; +if (stab->nel ==0 ) +return 0 ; +/* sort entries by id */ sids =calloc (stab->nel,sizeof (*sids));if (!sids)@@ -203,8 +206,6 @@ static int write_sidtab(FILE *bin_file, const struct sidtab *stab) }assert (index == stab->nel);qsort (sids, stab->nel,sizeof (struct security_id ), security_id_compare); -assert (sids[0 ].id ==1 ); -assert (sids[stab->nel -1 ].id == stab->nel);/* write raw contexts sorted by id */ for (uint32_t i =0 ; i < stab->nel; i++) {Signature · 1 line
2.45.2
James Carter
Acked-byQuoted 14 lines · Petr Lautrbach
Quoted 11 lines · Christian Göttsche
From: Christian Göttsche <[email protected]>
The two asserts following qsort(3) where useful during development to ensure the comparison function and the corresponding pointer handling were correct. They however do not take into account an empty file context definition file containing no definitions and thus
stab->nelbeing NULL. Drop the two asserts.Also return early to not depend on whether calloc(3) called with a size of zero returns NULL or a special value.
Quoted 9 lines
Quoted 4 lines
Reported-by Petr Lautrbach <[email protected]>Fixes 92306daf ("libselinux: rework selabel_file(5) database")Signed-off-by Christian Göttsche <[email protected]>Works for me. Thanks!
Tested-by Petr Lautrbach <[email protected]>
Quoted 34 lines
Quoted 32 lines
---
v2: fix condition from not zero to equal to zeroSigned-off-by Christian Göttsche <[email protected]>--- libselinux/utils/sefcontext_compile.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)libselinux/utils/sefcontext_compile.c +3
-3@@ -188,6 +188,9 @@ static int write_sidtab(FILE *bin_file, const struct sidtab *stab)if (len !=1 )return -1 ; +if (stab->nel ==0 ) +return 0 ; +/* sort entries by id */ sids =calloc (stab->nel,sizeof (*sids));if (!sids)@@ -203,8 +206,6 @@ static int write_sidtab(FILE *bin_file, const struct sidtab *stab) }assert (index == stab->nel);qsort (sids, stab->nel,sizeof (struct security_id ), security_id_compare); -assert (sids[0 ].id ==1 ); -assert (sids[stab->nel -1 ].id == stab->nel);/* write raw contexts sorted by id */ for (uint32_t i =0 ; i < stab->nel; i++) { --2.45.2
Quoted 21 lines · James Carter
Quoted 19 lines · Petr Lautrbach
Quoted 15 lines · Christian Göttsche
From: Christian Göttsche <[email protected]>
The two asserts following qsort(3) where useful during development to ensure the comparison function and the corresponding pointer handling were correct. They however do not take into account an empty file context definition file containing no definitions and thus
stab->nelbeing NULL. Drop the two asserts.Also return early to not depend on whether calloc(3) called with a size of zero returns NULL or a special value.
Reported-by Petr Lautrbach <[email protected]>Fixes 92306daf ("libselinux: rework selabel_file(5) database")Signed-off-by Christian Göttsche <[email protected]>
Quoted 7 lines
Quoted 4 lines
Works for me. Thanks!
Tested-by Petr Lautrbach <[email protected]>Acked-by James Carter <[email protected]>
Merged.
Thanks,
Jim
Quoted 34 lines
Quoted 34 lines
Quoted 32 lines
---
v2: fix condition from not zero to equal to zeroSigned-off-by Christian Göttsche <[email protected]>--- libselinux/utils/sefcontext_compile.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)libselinux/utils/sefcontext_compile.c +3
-3@@ -188,6 +188,9 @@ static int write_sidtab(FILE *bin_file, const struct sidtab *stab)if (len !=1 )return -1 ; +if (stab->nel ==0 ) +return 0 ; +/* sort entries by id */ sids =calloc (stab->nel,sizeof (*sids));if (!sids)@@ -203,8 +206,6 @@ static int write_sidtab(FILE *bin_file, const struct sidtab *stab) }assert (index == stab->nel);qsort (sids, stab->nel,sizeof (struct security_id ), security_id_compare); -assert (sids[0 ].id ==1 ); -assert (sids[stab->nel -1 ].id == stab->nel);/* write raw contexts sorted by id */ for (uint32_t i =0 ; i < stab->nel; i++) { --2.45.2