Skip to content

Commit

Permalink
mac80211: fix failure to check kmalloc return value in key_key_read
Browse files Browse the repository at this point in the history
I noticed two small issues in mac80211/debugfs_key.c::key_key_read while
reading through the code. Patch below.

The key_key_read() function returns ssize_t and the value that's actually
returned is the return value of simple_read_from_buffer() which also
returns ssize_t, so let's hold the return value in a ssize_t local
variable rather than a int one.

Also, memory is allocated dynamically with kmalloc() which can fail, but
the return value of kmalloc() is not checked, so we may end up operating
on a null pointer further on. So check for a NULL return and bail out with
-ENOMEM in that case.

Signed-off-by: Jesper Juhl <[email protected]>
Signed-off-by: John W. Linville <[email protected]>
  • Loading branch information
jjuhl authored and linvjw committed Oct 29, 2010
1 parent 731b203 commit 520efd1
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion net/mac80211/debugfs_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,13 @@ static ssize_t key_key_read(struct file *file, char __user *userbuf,
size_t count, loff_t *ppos)
{
struct ieee80211_key *key = file->private_data;
int i, res, bufsize = 2 * key->conf.keylen + 2;
int i, bufsize = 2 * key->conf.keylen + 2;
char *buf = kmalloc(bufsize, GFP_KERNEL);
char *p = buf;
ssize_t res;

if (!buf)
return -ENOMEM;

for (i = 0; i < key->conf.keylen; i++)
p += scnprintf(p, bufsize + buf - p, "%02x", key->conf.key[i]);
Expand Down

0 comments on commit 520efd1

Please sign in to comment.