Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 359258
b: refs/heads/master
c: 47f531e
h: refs/heads/master
v: v3
  • Loading branch information
Matt Fleming committed Feb 12, 2013
1 parent 0196bd9 commit 4e256f0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 94a193fb7393a50625abd9ca21f8afea275a9f87
refs/heads/master: 47f531e8ba3bc3901a0c493f4252826c41dea1a1
49 changes: 44 additions & 5 deletions trunk/drivers/firmware/efivars.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
#include <linux/device.h>
#include <linux/slab.h>
#include <linux/pstore.h>
#include <linux/ctype.h>

#include <linux/fs.h>
#include <linux/ramfs.h>
Expand Down Expand Up @@ -900,6 +901,48 @@ static struct inode *efivarfs_get_inode(struct super_block *sb,
return inode;
}

/*
* Return true if 'str' is a valid efivarfs filename of the form,
*
* VariableName-12345678-1234-1234-1234-1234567891bc
*/
static bool efivarfs_valid_name(const char *str, int len)
{
static const char dashes[GUID_LEN] = {
[8] = 1, [13] = 1, [18] = 1, [23] = 1
};
const char *s = str + len - GUID_LEN;
int i;

/*
* We need a GUID, plus at least one letter for the variable name,
* plus the '-' separator
*/
if (len < GUID_LEN + 2)
return false;

/* GUID should be right after the first '-' */
if (s - 1 != strchr(str, '-'))
return false;

/*
* Validate that 's' is of the correct format, e.g.
*
* 12345678-1234-1234-1234-123456789abc
*/
for (i = 0; i < GUID_LEN; i++) {
if (dashes[i]) {
if (*s++ != '-')
return false;
} else {
if (!isxdigit(*s++))
return false;
}
}

return true;
}

static void efivarfs_hex_to_guid(const char *str, efi_guid_t *guid)
{
guid->b[0] = hex_to_bin(str[6]) << 4 | hex_to_bin(str[7]);
Expand Down Expand Up @@ -928,11 +971,7 @@ static int efivarfs_create(struct inode *dir, struct dentry *dentry,
struct efivar_entry *var;
int namelen, i = 0, err = 0;

/*
* We need a GUID, plus at least one letter for the variable name,
* plus the '-' separator
*/
if (dentry->d_name.len < GUID_LEN + 2)
if (!efivarfs_valid_name(dentry->d_name.name, dentry->d_name.len))
return -EINVAL;

inode = efivarfs_get_inode(dir->i_sb, dir, mode, 0);
Expand Down

0 comments on commit 4e256f0

Please sign in to comment.