From c7e82d4863992c2f3bbb6f5a31fa8e5fd0e1643f Mon Sep 17 00:00:00 2001 From: sin Date: Wed, 8 Apr 2015 15:25:47 +0100 Subject: [PATCH] Add read checks for bcopy() --- include/strings.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/include/strings.h b/include/strings.h index 2a16c60..4e0c194 100644 --- a/include/strings.h +++ b/include/strings.h @@ -16,13 +16,14 @@ extern "C" { #undef bzero __typeof__(bcopy) __bcopy_orig __asm__(__USER_LABEL_PREFIX__ "bcopy"); extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__)) -void bcopy(const void *src, void *dest, size_t n) +void bcopy(const void *src, void *dst, size_t n) { - size_t bos = __builtin_object_size(dest, 0); + size_t bos_dst = __builtin_object_size(dst, 0); + size_t bos_src = __builtin_object_size(src, 0); - if (n > bos) + if (n > bos_dst || n > bos_src) __builtin_trap(); - return __bcopy_orig(src, dest, n); + return __bcopy_orig(src, dst, n); } __typeof__(bzero) __bzero_orig __asm__(__USER_LABEL_PREFIX__ "bzero");