Skip to contentSkip to conversation

selinux: remove useless assignments

PATCH In review Ondrej Mosnacek 3 participants 4 messages Mar 25, 2019 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selinux: remove useless assignments

The code incorrectly assigned directly to the variables instead of the values they point to. Since the values are already set to NULL/0 at the beginning of the function, we can simply remove these useless assignments.

Fixes fede148324c3 ("selinux: log invalid contexts in AVCs")
---
 security/selinux/ss/services.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
security/selinux/ss/services.c +3 -6
index ec62918521b1..b18a8d7c1b5e 100644
@@ -1318,14 +1318,11 @@ static int security_sid_to_context_core(struct selinux_state *state,
 		rc = -EINVAL;
 		goto out_unlock;
 	}
-	if (only_invalid && !context->len) {
-		scontext = NULL;
-		scontext_len = 0;
-		rc = 0;
-	} else {
+	if (only_invalid && !context->len)
+		rc = 0; /* *scontext/*scontext_len are already set to NULL/0 */
+	else
 		rc = context_struct_to_string(policydb, context, scontext,
 					      scontext_len);
-	}
 out_unlock:
 	read_unlock(&state->ss->policy_rwlock);
 out:
Signature · 1 line
2.20.1
maintainer
#1 lore raw
Quoted 17 lines · Ondrej Mosnacek

The code incorrectly assigned directly to the variables instead of the values they point to. Since the values are already set to NULL/0 at the beginning of the function, we can simply remove these useless assignments.

Fixes fede148324c3 ("selinux: log invalid contexts in AVCs")
---
 security/selinux/ss/services.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
security/selinux/ss/services.c +0 -0
index ec62918521b1..b18a8d7c1b5e 100644

security/selinux/ss/services.c static int security_sid_to_context_core(struct selinux_state *state, · line 1322

Quoted 10 lines
security/selinux/ss/services.c +2 -5
@@ -1318,14 +1318,11 @@ static int security_sid_to_context_core(struct selinux_state *state,
                rc = -EINVAL;
                goto out_unlock;
        }
-       if (only_invalid && !context->len) {
-               scontext = NULL;
-               scontext_len = 0;
-               rc = 0;
-       } else {
+       if (only_invalid && !context->len)
+               rc = 0; /* *scontext/*scontext_len are already set to NULL/0 */

The compiler doesn't like that you've used "/*" inside a comment. I'm surprised you didn't see this when compiling the code ... you did compile this before sending it to the list, right?

Anyway, the patch looks fine to me otherwise so I removed the comment (it was a arguably verbose anyway) and merged into selinux/next.

Quoted 7 lines
security/selinux/ss/services.c +1 -1
+       else
                rc = context_struct_to_string(policydb, context, scontext,
                                              scontext_len);
-       }
 out_unlock:
        read_unlock(&state->ss->policy_rwlock);
 out:
Signature · 2 lines
paul moore
www.paul-moore.com
#2 lore raw
Quoted 24 lines · Paul Moore
Quoted 23 lines · Ondrej Mosnacek

The code incorrectly assigned directly to the variables instead of the values they point to. Since the values are already set to NULL/0 at the beginning of the function, we can simply remove these useless assignments.

Fixes fede148324c3 ("selinux: log invalid contexts in AVCs")
---
 security/selinux/ss/services.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
security/selinux/ss/services.c +0 -3
index ec62918521b1..b18a8d7c1b5e 100644
@@ -1318,14 +1318,11 @@ static int security_sid_to_context_core(struct selinux_state *state,
                rc = -EINVAL;
                goto out_unlock;
        }
-       if (only_invalid && !context->len) {
-               scontext = NULL;
-               scontext_len = 0;
Quoted 8 lines

security/selinux/ss/services.c static int security_sid_to_context_core(struct selinux_state *state, · line 1322

Quoted 4 lines
security/selinux/ss/services.c +2 -2
-               rc = 0;
-       } else {
+       if (only_invalid && !context->len)
+               rc = 0; /* *scontext/*scontext_len are already set to NULL/0 */

The compiler doesn't like that you've used "/*" inside a comment. I'm surprised you didn't see this when compiling the code ... you did compile this before sending it to the list, right?

Hm, could be that I had to rebuild (almost) the whole tree for some reason (git checkout across branches, probably) and the warning got lost in the sea of build output (no -Werror here, so the build did not fail).

Quoted 3 lines

Anyway, the patch looks fine to me otherwise so I removed the comment (it was a arguably verbose anyway) and merged into selinux/next.

Fine by me, thanks!

Quoted 9 lines

security/selinux/ss/services.c static int security_sid_to_context_core(struct selinux_state *state, · line 1328

Quoted 8 lines
security/selinux/ss/services.c +1 -1
+       else
                rc = context_struct_to_string(policydb, context, scontext,
                                              scontext_len);
-       }
 out_unlock:
        read_unlock(&state->ss->policy_rwlock);
 out:
Quoted 3 lines

--
paul moore
www.paul-moore.com

--
Ondrej Mosnacek <omosnace at redhat dot com>
Software Engineer, Security Technologies
Red Hat, Inc.

#3 lore raw
In reply to Ondrej Mosnacek
Quoted 17 lines · Ondrej Mosnacek

The code incorrectly assigned directly to the variables instead of the values they point to. Since the values are already set to NULL/0 at the beginning of the function, we can simply remove these useless assignments.

Fixes fede148324c3 ("selinux: log invalid contexts in AVCs")
---
  security/selinux/ss/services.c | 9 +++------
  1 file changed, 3 insertions(+), 6 deletions(-)
security/selinux/ss/services.c +0 -0
index ec62918521b1..b18a8d7c1b5e 100644

security/selinux/ss/services.c static int security_sid_to_context_core(struct selinux_state *state, · line 1322

Quoted 10 lines
security/selinux/ss/services.c +2 -5
@@ -1318,14 +1318,11 @@ static int security_sid_to_context_core(struct selinux_state *state,
  		rc = -EINVAL;
  		goto out_unlock;
  	}
-	if (only_invalid && !context->len) {
-		scontext = NULL;
-		scontext_len = 0;
-		rc = 0;
-	} else {
+	if (only_invalid && !context->len)
+		rc = 0; /* *scontext/*scontext_len are already set to NULL/0 */

I know that modern compilers won't be fooled, but please don't nest comments.

Quoted 7 lines
security/selinux/ss/services.c +1 -1
+	else
  		rc = context_struct_to_string(policydb, context, scontext,
  					      scontext_len);
-	}
  out_unlock:
  	read_unlock(&state->ss->policy_rwlock);
  out: