From e8efb3970aef3ec9d2f2ca01a4550ed6c7cf62a1 Mon Sep 17 00:00:00 2001 From: Chaskiel M Grundman Date: Sun, 8 May 2005 06:46:14 +0000 Subject: [PATCH] linux-copyin-copyout-dont-check-errors-20050508 FIXES 18293 improved macros which do error checking --- src/afs/LINUX/osi_machdep.h | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/afs/LINUX/osi_machdep.h b/src/afs/LINUX/osi_machdep.h index 707a467ad..101d3845f 100644 --- a/src/afs/LINUX/osi_machdep.h +++ b/src/afs/LINUX/osi_machdep.h @@ -111,6 +111,8 @@ extern struct vnodeops afs_file_iops, afs_dir_iops, afs_symlink_iops; /* We often need to pretend we're in user space to get memory transfers * right for the kernel calls we use. */ +#include + #ifdef KERNEL_SPACE_DECL #undef KERNEL_SPACE_DECL #undef TO_USER_SPACE @@ -120,14 +122,16 @@ extern struct vnodeops afs_file_iops, afs_dir_iops, afs_symlink_iops; #define TO_USER_SPACE() { _fs_space_decl = get_fs(); set_fs(get_ds()); } #define TO_KERNEL_SPACE() set_fs(_fs_space_decl) -/* Backwards compatibilty macros - copyin/copyout are redone because macro - * inside parentheses is not evalutated. - */ -#define memcpy_fromfs copy_from_user -#define memcpy_tofs copy_to_user -#define copyin(F, T, C) (copy_from_user ((char*)(T), (char*)(F), (C)), 0) -#define copyinstr(F, T, C, L) (copyin(F, T, C), *(L)=strlen(T), 0) -#define copyout(F, T, C) (copy_to_user ((char*)(T), (char*)(F), (C)), 0) +#define copyin(F, T, C) (copy_from_user ((char*)(T), (char*)(F), (C)) > 0 ? EFAULT : 0) +static inline long copyinstr(char *from, char *to, int count, int *length) { + long tmp; + tmp = strncpy_from_user(to, from, count); + if (tmp < 0) + return EFAULT; + *length = tmp; + return 0; +} +#define copyout(F, T, C) (copy_to_user ((char*)(T), (char*)(F), (C)) > 0 ? EFAULT : 0) /* kernel print statements */ #define printf printk -- 2.39.5