Skip to content

Commit

Permalink
security/selinux/ss: correct size computation
Browse files Browse the repository at this point in the history
The size argument to kcalloc should be the size of desired structure,
not the pointer to it.

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

// <smpl>
@expression@
expression *x;
@@

x =
 <+...
-sizeof(x)
+sizeof(*x)
...+>// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>
Acked-by: Eric Paris <eparis@redhat.com>
Signed-off-by: James Morris <jmorris@namei.org>
  • Loading branch information
Julia Lawall authored and James Morris committed Dec 8, 2009
1 parent 6ec22f9 commit 9f59f90
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions security/selinux/ss/services.c
Original file line number Diff line number Diff line change
Expand Up @@ -2555,7 +2555,7 @@ int security_get_classes(char ***classes, int *nclasses)
read_lock(&policy_rwlock);

*nclasses = policydb.p_classes.nprim;
*classes = kcalloc(*nclasses, sizeof(*classes), GFP_ATOMIC);
*classes = kcalloc(*nclasses, sizeof(**classes), GFP_ATOMIC);
if (!*classes)
goto out;

Expand Down Expand Up @@ -2602,7 +2602,7 @@ int security_get_permissions(char *class, char ***perms, int *nperms)
}

*nperms = match->permissions.nprim;
*perms = kcalloc(*nperms, sizeof(*perms), GFP_ATOMIC);
*perms = kcalloc(*nperms, sizeof(**perms), GFP_ATOMIC);
if (!*perms)
goto out;

Expand Down

0 comments on commit 9f59f90

Please sign in to comment.