public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 3/4] security/selinux: decrement sizeof size in strncmp
@ 2009-11-12  7:49 Julia Lawall
  2009-11-12  8:16 ` James Morris
  0 siblings, 1 reply; 26+ messages in thread
From: Julia Lawall @ 2009-11-12  7:49 UTC (permalink / raw)
  To: Stephen Smalley, James Morris, Eric Paris, linux-kernel,
	linux-security-module, kernel-janitors

From: Julia Lawall <julia@diku.dk>

As observed by Joe Perches, sizeof of a constant string includes the
trailing 0.  If what is wanted is to check the initial characters of
another string, this trailing 0 should not be taken into account.  If an
exact match is wanted, strcmp should be used instead.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
expression foo;
constant char *abc;
@@

strncmp(foo, abc, 
- sizeof(abc)
+ sizeof(abc)-1
 )
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>

---
 security/selinux/hooks.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff -u -p a/security/selinux/hooks.c b/security/selinux/hooks.c
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -448,7 +448,7 @@ static int sb_finish_set_opts(struct sup
 		sbsec->flags &= ~SE_SBLABELSUPP;
 
 	/* Special handling for sysfs. Is genfs but also has setxattr handler*/
-	if (strncmp(sb->s_type->name, "sysfs", sizeof("sysfs")) == 0)
+	if (strncmp(sb->s_type->name, "sysfs", sizeof("sysfs") - 1) == 0)
 		sbsec->flags |= SE_SBLABELSUPP;
 
 	/* Initialize the root inode. */

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2009-11-15 18:44 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-12  7:49 [PATCH 3/4] security/selinux: decrement sizeof size in strncmp Julia Lawall
2009-11-12  8:16 ` James Morris
2009-11-12 14:53   ` Serge E. Hallyn
2009-11-12 14:57     ` Julia Lawall
2009-11-12 16:21       ` Casey Schaufler
2009-11-12 18:28         ` David Wagner
2009-11-12 21:41         ` James Morris
2009-11-12 21:59           ` Julia Lawall
2009-11-12 23:56             ` David Wagner
2009-11-13  2:11           ` Casey Schaufler
2009-11-13 20:32             ` David Wagner
2009-11-13 21:23             ` Valdis.Kletnieks
2009-11-13 21:26               ` Julia Lawall
2009-11-13 23:08                 ` Valdis.Kletnieks
2009-11-14  0:41                   ` David Wagner
2009-11-14  5:08                     ` Valdis.Kletnieks
2009-11-14 15:22                   ` Julia Lawall
2009-11-13 23:06               ` David Wagner
2009-11-14  3:06               ` Casey Schaufler
2009-11-14  3:44                 ` David Wagner
2009-11-14  3:48                   ` Joe Perches
2009-11-14  5:12                     ` Casey Schaufler
2009-11-14  5:26                       ` Joe Perches
2009-11-14  7:20                         ` Casey Schaufler
2009-11-15  7:45                           ` Raja R Harinath
2009-11-15 18:44                             ` Casey Schaufler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox