From ab79a1f44b5fc40ce58b8d6a3809ea67a0bf6631 Mon Sep 17 00:00:00 2001 From: Amul Shah Date: Mon, 2 Jul 2012 09:47:25 -0400 Subject: [PATCH] ENH: missed two files --- sr_port/gtm_memcpy_validate_and_execute.c | 35 +++++++++++++++++++++++ sr_port/gtm_memcpy_validate_and_execute.h | 17 +++++++++++ 2 files changed, 52 insertions(+) create mode 100644 sr_port/gtm_memcpy_validate_and_execute.c create mode 100644 sr_port/gtm_memcpy_validate_and_execute.h diff --git a/sr_port/gtm_memcpy_validate_and_execute.c b/sr_port/gtm_memcpy_validate_and_execute.c new file mode 100644 index 0000000..670634a --- /dev/null +++ b/sr_port/gtm_memcpy_validate_and_execute.c @@ -0,0 +1,35 @@ +/**************************************************************** + * * + * Copyright 2012 Fidelity Information Services, Inc * + * * + * This source code contains the intellectual property * + * of its copyright holder(s), and is made available * + * under a license. If you do not know the terms of * + * the license, please stop and do not read further. * + * * + ****************************************************************/ + +#include "mdef.h" +#define BYPASS_MEMCPY_OVERRIDE /* Want to run original system memcpy() here */ +#include "gtm_string.h" + +#include "gtm_memcpy_validate_and_execute.h" + +#ifdef DEBUG /* Is only a debugging routine - nothing to see here for a production build - move along */ + +/* Identify memcpy() invocations that should be memmove() instead. If this routine assert fails, the arguments + * overlap so should be converted to memmove(). One exception to that rule which is currently bypassed is when + * source and target are equal. There are no known implementation of memcpy() that would break in such a + * condition so since at least two of these currently exist in GT.M (one in gtmcrypt.h on UNIX and one in + * mu_cre_file on VMS), this routine does not cause an assert fail in that case. + */ +void *gtm_memcpy_validate_and_execute(void *target, const void *src, size_t len) +{ + if (target == src) /* Allow special case to go through but avoid actual memcpy() call */ + return target; + assert(((char *)(target) > (char *)(src)) + ? ((char *)(target) >= ((char *)(src) + (len))) + : ((char *)(src) >= ((char *)(target) + (len)))); + return memcpy(target, src, len); +} +#endif diff --git a/sr_port/gtm_memcpy_validate_and_execute.h b/sr_port/gtm_memcpy_validate_and_execute.h new file mode 100644 index 0000000..0de2e70 --- /dev/null +++ b/sr_port/gtm_memcpy_validate_and_execute.h @@ -0,0 +1,17 @@ +/**************************************************************** + * * + * Copyright 2012 Fidelity Information Services, Inc * + * * + * This source code contains the intellectual property * + * of its copyright holder(s), and is made available * + * under a license. If you do not know the terms of * + * the license, please stop and do not read further. * + * * + ****************************************************************/ + +#ifndef GTM_MVAE_INCLUDED +#define GTM_MVAE_INCLUDED + +void *gtm_memcpy_validate_and_execute(void *target, const void *src, size_t len); + +#endif