Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 23473
b: refs/heads/master
c: 96840aa
h: refs/heads/master
i:
  23471: 634de7f
v: v3
  • Loading branch information
Davi Arnaut authored and Linus Torvalds committed Mar 24, 2006
1 parent 9ee0276 commit 29a367a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 6687a97d4041f996f725902d2990e5de6ef5cbe5
refs/heads/master: 96840aa00a031069a136ec4c55d0bdd09ac6d3a7
2 changes: 2 additions & 0 deletions trunk/include/linux/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ extern char * strsep(char **,const char *);
extern __kernel_size_t strspn(const char *,const char *);
extern __kernel_size_t strcspn(const char *,const char *);

extern char *strndup_user(const char __user *, long);

/*
* Include machine specific inline routines
*/
Expand Down
37 changes: 37 additions & 0 deletions trunk/mm/util.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/module.h>
#include <linux/err.h>
#include <asm/uaccess.h>

/**
* kzalloc - allocate memory. The memory is set to zero.
Expand Down Expand Up @@ -37,3 +39,38 @@ char *kstrdup(const char *s, gfp_t gfp)
return buf;
}
EXPORT_SYMBOL(kstrdup);

/*
* strndup_user - duplicate an existing string from user space
*
* @s: The string to duplicate
* @n: Maximum number of bytes to copy, including the trailing NUL.
*/
char *strndup_user(const char __user *s, long n)
{
char *p;
long length;

length = strnlen_user(s, n);

if (!length)
return ERR_PTR(-EFAULT);

if (length > n)
return ERR_PTR(-EINVAL);

p = kmalloc(length, GFP_KERNEL);

if (!p)
return ERR_PTR(-ENOMEM);

if (copy_from_user(p, s, length)) {
kfree(p);
return ERR_PTR(-EFAULT);
}

p[length - 1] = '\0';

return p;
}
EXPORT_SYMBOL(strndup_user);

0 comments on commit 29a367a

Please sign in to comment.