libselinux: restorecon: add_exclude: validate directory before deref
PATCH 1/1 libselinux: restorecon: add_exclude: validate directory before deref
Currently, the call to strcmp() with directory as an argument results in directory being dereferenced before it is checked to be non-NULL. Hence, move the validation of directory before the call to strcmp().
Signed-off-by Rahul Sandhu <[email protected]>
--- libselinux/src/selinux_restorecon.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
libselinux/src/selinux_restorecon.c +6 -6
@@ -204,12 +204,6 @@ static int add_exclude(const char *directory, bool who)size_t len =0 ;int i; -/* Check if already present. */ -for (i =0 ; i < exclude_count; i++) { -if (strcmp (directory, exclude_lst[i].directory) ==0 ) -return 0 ; - } -if (directory ==NULL || directory[0 ] !='/' ) { selinux_log(SELINUX_ERROR, "Full path required for exclude: %s.\n",
@@ -218,6 +212,12 @@ static int add_exclude(const char *directory, bool who)return -1 ; } +/* Check if already present. */ +for (i =0 ; i < exclude_count; i++) { +if (strcmp (directory, exclude_lst[i].directory) ==0 ) +return 0 ; + } +if (exclude_count >=INT_MAX -1 ) {selinux_log (SELINUX_ERROR ,"Too many directory excludes: %d.\n" , exclude_count); errno =EOVERFLOW ;
Signature · 1 line
2.54.0
Quoted 6 lines · Rahul Sandhu
Currently, the call to
strcmp()with directory as an argument results in directory being dereferenced before it is checked to be non-NULL. Hence, move the validation of directory before the call tostrcmp().Signed-off-by Rahul Sandhu <[email protected]>
Acked-by Stephen Smalley <[email protected]>
Quoted 38 lines
--- libselinux/src/selinux_restorecon.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)libselinux/src/selinux_restorecon.c +6
-7@@ -204,12 +204,6 @@ static int add_exclude(const char *directory, bool who)size_t len =0 ;int i; -/* Check if already present. */ -for (i =0 ; i < exclude_count; i++) { -if (strcmp (directory, exclude_lst[i].directory) ==0 ) -return 0 ; - } -if (directory ==NULL || directory[0 ] !='/' ) { selinux_log(SELINUX_ERROR, "Full path required for exclude: %s.\n",@@ -218,6 +212,12 @@ static int add_exclude(const char *directory, bool who)return -1 ; } +/* Check if already present. */ +for (i =0 ; i < exclude_count; i++) { +if (strcmp (directory, exclude_lst[i].directory) ==0 ) +return 0 ; + } +if (exclude_count >=INT_MAX -1 ) {selinux_log (SELINUX_ERROR ,"Too many directory excludes: %d.\n" , exclude_count); errno =EOVERFLOW ; --2.54.0
Quoted 11 lines · Stephen Smalley
Quoted 6 lines · Rahul Sandhu
Currently, the call to
strcmp()with directory as an argument results in directory being dereferenced before it is checked to be non-NULL. Hence, move the validation of directory before the call tostrcmp().Signed-off-by Rahul Sandhu <[email protected]>Acked-by Stephen Smalley <[email protected]>
Merged.
Thanks,
Jim
Quoted 39 lines
Quoted 38 lines
--- libselinux/src/selinux_restorecon.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)libselinux/src/selinux_restorecon.c +6
-7@@ -204,12 +204,6 @@ static int add_exclude(const char *directory, bool who)size_t len =0 ;int i; -/* Check if already present. */ -for (i =0 ; i < exclude_count; i++) { -if (strcmp (directory, exclude_lst[i].directory) ==0 ) -return 0 ; - } -if (directory ==NULL || directory[0 ] !='/' ) { selinux_log(SELINUX_ERROR, "Full path required for exclude: %s.\n",@@ -218,6 +212,12 @@ static int add_exclude(const char *directory, bool who)return -1 ; } +/* Check if already present. */ +for (i =0 ; i < exclude_count; i++) { +if (strcmp (directory, exclude_lst[i].directory) ==0 ) +return 0 ; + } +if (exclude_count >=INT_MAX -1 ) {selinux_log (SELINUX_ERROR ,"Too many directory excludes: %d.\n" , exclude_count); errno =EOVERFLOW ; --2.54.0