lkml.org 
[lkml]   [2006]   [Feb]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] Keys: Deal properly with strnlen_user()
David Howells <dhowells@redhat.com> wrote:
>
> +#define key_get_type_from_user(type, _type, error) \
> +do { \
> + ret = strncpy_from_user(type, _type, sizeof(type)); \
> + if (ret < 0) \
> + goto error; \
> + \
> + if (ret == 0 || ret > sizeof(type) - 1) { \
> + ret = -EINVAL; \
> + goto error; \
> + } \
> + \
> + ret = -EPERM; \
> + if (type[0] == '.') \
> + goto error; \
> + \
> + type[31] = '\0'; \
> +} while(0)
> +
> +#define key_get_description_from_user(desc, _desc, dlen, error, error2) \
> +do { \
> + ret = -EFAULT; \
> + dlen = strnlen_user(_desc, PAGE_SIZE); \
> + if (dlen <= 0) \
> + goto error; \
> + \
> + ret = -EINVAL; \
> + if (dlen > PAGE_SIZE) \
> + goto error; \
> + \
> + ret = -ENOMEM; \
> + desc = kmalloc(dlen, GFP_KERNEL); \
> + if (!desc) \
> + goto error; \
> + \
> + ret = -EFAULT; \
> + if (copy_from_user(desc, _desc, dlen - 1) != 0) \
> + goto error2; \
> + \
> + desc[dlen - 1] = '\0'; \
> +} while(0)

ug. Well it's your code ;)

It should really parameterise `ret' too.

Are you sure you want to do this? From my reading, doing it with plain old
subroutines would work?
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2006-02-18 11:24    [W:0.037 / U:0.136 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site