BUG: change memcpy to memmove

This commit is contained in:
Amul Shah 2012-06-29 16:34:26 -04:00
parent 4077ab87ab
commit 8ec5ab7218
10 changed files with 57 additions and 33 deletions

View File

@ -52,6 +52,10 @@ GBLREF unsigned char patch_comp_count;
GBLREF cw_set_element cw_set[];
GBLREF unsigned char *non_tp_jfb_buff_ptr;
error_def(ERR_DBRDONLY);
error_def(ERR_DSEBLKRDFAIL);
error_def(ERR_DSEFAIL);
void dse_rmrec(void)
{
block_id blk;
@ -64,10 +68,6 @@ void dse_rmrec(void)
short int size, i, rsize;
srch_blk_status blkhist;
error_def(ERR_DBRDONLY);
error_def(ERR_DSEBLKRDFAIL);
error_def(ERR_DSEFAIL);
if (gv_cur_region->read_only)
rts_error(VARLSTCNT(4) ERR_DBRDONLY, 2, DB_LEN_STR(gv_cur_region));
CHECK_AND_RESET_UPDATE_ARRAY; /* reset update_array_ptr to update_array */
@ -182,7 +182,7 @@ void dse_rmrec(void)
rsize = r_top - key_top + SIZEOF(rec_hdr) + patch_comp_count - i;
PUT_SHORT(&((rec_hdr_ptr_t)rp_base)->rsiz, rsize);
memcpy(rp_base + SIZEOF(rec_hdr), &patch_comp_key[i], patch_comp_count - i);
memcpy(rp_base + SIZEOF(rec_hdr) + patch_comp_count - i, key_top, b_top - key_top);
memmove(rp_base + SIZEOF(rec_hdr) + patch_comp_count - i, key_top, b_top - key_top);
((blk_hdr_ptr_t)lbp)->bsiz = (unsigned int)(rp_base + rsize - lbp + b_top - r_top);
BLK_INIT(bs_ptr, bs1);
BLK_SEG(bs_ptr, (uchar_ptr_t)lbp + SIZEOF(blk_hdr), ((blk_hdr_ptr_t)lbp)->bsiz - SIZEOF(blk_hdr));

View File

@ -33,7 +33,12 @@
*/
#include "mdef.h"
/* If this is a pro build (meaning PRO_BUILD is defined), avoid the memcpy() override. That code is only
* appropriate for a pure debug build.
*/
#ifdef PRO_BUILD
# define BYPASS_MEMCPY_OVERRIDE /* Instruct gtm_string.h not to override memcpy() */
#endif
/* We are the redefined versions so use real versions in this module */
#undef malloc
#undef free
@ -45,11 +50,11 @@
#include <stddef.h>
#include <errno.h>
#if !defined(VMS) && !defined(__MVS__)
#include <malloc.h>
# include <malloc.h>
#endif
#include "gtm_stdio.h"
#include "gtm_string.h"
#include "gtm_stdlib.h"
#include "gtm_string.h"
#include "eintr_wrappers.h"
#include "gtmdbglvl.h"
@ -67,8 +72,8 @@
#include "gtm_malloc.h"
#include "have_crit.h"
#ifdef UNIX
#include "gtmio.h"
#include "deferred_signal_handler.h"
# include "gtmio.h"
# include "deferred_signal_handler.h"
#endif
/* This routine is compiled twice, once as debug and once as pro and put into the same pro build. The alternative

View File

@ -1,6 +1,6 @@
/****************************************************************
* *
* Copyright 2001, 2011 Fidelity Information Services, Inc *
* Copyright 2001, 2012 Fidelity Information Services, Inc *
* *
* This source code contains the intellectual property *
* of its copyright holder(s), and is made available *
@ -15,9 +15,7 @@
#ifndef GTM_STRINGH
#define GTM_STRINGH
#ifndef __vax
# include <string.h>
#endif
#include <string.h>
#define STRERROR strerror
@ -31,4 +29,15 @@
#define STRNCMP_LIT_FULL(SOURCE, LITERAL) strncmp(SOURCE, LITERAL, SIZEOF(LITERAL)) /* BYPASSOK */
#define STRNCMP_STR(SOURCE, STRING, LEN) strncmp(SOURCE, STRING, LEN)
/* We need to catch any memcpy() that is used when the source and target strings overlap in any fashion so we can change
* them to a memmove. So in debug builds, assert fail if this is the case.
*/
#if defined(DEBUG) && !defined(BYPASS_MEMCPY_OVERRIDE)
# include "gtm_memcpy_validate_and_execute.h"
# ifdef memcpy
# undef memcpy /* Some platforms like AIX create memcpy as a #define which needs removing before re-define */
# endif
# define memcpy(TARGET, SRC, LEN) gtm_memcpy_validate_and_execute((void *)(TARGET), (const void *)(SRC), (LEN))
#endif
#endif

View File

@ -9,8 +9,10 @@
* *
****************************************************************/
#include "mdef.h"
#define BYPASS_MEMCPY_OVERRIDE /* Signals gtm_string.h to not override memcpy(). When this routine is linked into gtcm_pkdisp,
* the assert in the routine called by memcpy macro causes the world to be pulled in. Avoid.
*/
/* Note that since this routine is called prior to reading environment vars or pretty much any
* other initialization, we cannot use gtm_malloc() yet so care is taken to use the real system
* malloc.

View File

@ -315,7 +315,7 @@ void op_tstart(int implicit_flag, ...) /* value of $T when TSTART */
} else
rts_error(VARLSTCNT(1) ERR_STACKCRIT);
}
memcpy(msp, old_sp, top - (unsigned char *)old_sp);
memmove(msp, old_sp, top - (unsigned char *)old_sp); /* Shift stack w/possible overlapping ranges */
mv_st_ent = (mv_stent *)(top - shift_size);
mv_st_ent->mv_st_type = MVST_TPHOLD;
ADJUST_FRAME_POINTER(frame_pointer, shift_size);

View File

@ -1,6 +1,6 @@
/****************************************************************
* *
* Copyright 2001, 2011 Fidelity Information Services, Inc *
* Copyright 2001, 2012 Fidelity Information Services, Inc *
* *
* This source code contains the intellectual property *
* of its copyright holder(s), and is made available *
@ -26,6 +26,9 @@ GBLREF mv_stent *mv_chain;
GBLREF unsigned char *stackbase, *stacktop, *msp, *stackwarn;
GBLREF stack_frame *frame_pointer;
error_def(ERR_STACKOFLOW);
error_def(ERR_STACKCRIT);
int4 symbinit(void)
{
unsigned char *msp_save;
@ -35,8 +38,6 @@ int4 symbinit(void)
int4 shift_size, ls_size, temp_size;
int size;
unsigned char *old_sp, *top, *l_syms;
error_def(ERR_STACKOFLOW);
error_def(ERR_STACKCRIT);
if (frame_pointer->type & SFT_COUNT)
{
@ -91,7 +92,7 @@ int4 symbinit(void)
} else
rts_error(VARLSTCNT(1) ERR_STACKCRIT);
}
memcpy(msp, old_sp, top - (unsigned char *)old_sp);
memmove(msp, old_sp, top - (unsigned char *)old_sp); /* Shift stack w/possible overlapping range */
if (shift_size > MVST_STAB_SIZE)
fp_prev->l_symtab = (ht_ent_mname **)(top - shift_size);
l_syms = (unsigned char *)fp_prev->l_symtab;

View File

@ -1,6 +1,6 @@
/****************************************************************
* *
* Copyright 2001, 2009 Fidelity Information Services, Inc *
* Copyright 2001, 2012 Fidelity Information Services, Inc *
* *
* This source code contains the intellectual property *
* of its copyright holder(s), and is made available *
@ -32,6 +32,11 @@ GBLREF gv_key *gv_altkey;
GBLREF spdesc stringpool;
GBLREF bool undef_inhibit;
error_def(ERR_BADSRVRNETMSG);
error_def(ERR_UNIMPLOP);
error_def(ERR_TEXT);
error_def(ERR_GVIS);
void gvcmz_doop(unsigned char query_code, unsigned char reply_code, mval *v)
{
unsigned char *ptr;
@ -41,11 +46,6 @@ void gvcmz_doop(unsigned char query_code, unsigned char reply_code, mval *v)
unsigned char buff[MAX_ZWR_KEY_SZ], *end;
unsigned short srv_buff_size;
error_def(ERR_BADSRVRNETMSG);
error_def(ERR_UNIMPLOP);
error_def(ERR_TEXT);
error_def(ERR_GVIS);
lnk = gv_cur_region->dyn.addr->cm_blk;
if (!((link_info *)lnk->usr)->server_supports_long_names && (PRE_V5_MAX_MIDENT_LEN < strlen((char *)gv_currkey->base)))
{
@ -218,7 +218,7 @@ void gvcmz_doop(unsigned char query_code, unsigned char reply_code, mval *v)
v->mvtype = MV_STR;
v->str.len = len;
v->str.addr = (char *)stringpool.free; /* we don't need the reply msg anymore, can overwrite reply */
memcpy(v->str.addr, ptr, len); /* so that we don't leave a gaping hole in the stringpool */
memmove(v->str.addr, ptr, len); /* so that we don't leave a gaping hole in the stringpool */
stringpool.free += len;
return;
}

View File

@ -1,6 +1,6 @@
/****************************************************************
* *
* Copyright 2001, 2010 Fidelity Information Services, Inc *
* Copyright 2001, 2012 Fidelity Information Services, Inc *
* *
* This source code contains the intellectual property *
* of its copyright holder(s), and is made available *
@ -10,6 +10,10 @@
****************************************************************/
#include "mdef.h"
#define BYPASS_MEMCPY_OVERRIDE /* Signals gtm_string.h to not override memcpy(). This causes linking problems when libmumps.a
* is not available.
*/
#include "main_pragma.h"
#undef UNIX /* Causes non-GTM-runtime routines (libgtmshr) to be used since libgtmshr is not yet available */
@ -20,7 +24,6 @@
#include "gtm_stdlib.h"
#include "gtm_limits.h"
#include <dlfcn.h>
#ifdef __osf__
/* On OSF/1 (Digital Unix), pointers are 64 bits wide; the only exception to this is C programs for which one may
* specify compiler and link editor options in order to use (and allocate) 32-bit pointers. However, since C is

View File

@ -10,7 +10,10 @@
****************************************************************/
#include "mdef.h"
/* We want system malloc, not gtm_malloc (which comes from mdef.h --> mdefsp.h). Since gtmsecshr_wrapper runs as root,
#define BYPASS_MEMCPY_OVERRIDE /* Signals gtm_string.h to not override memcpy(). This causes linking problems when libmumps.a
* is not available.
*/
#/* We want system malloc, not gtm_malloc (which comes from mdef.h --> mdefsp.h). Since gtmsecshr_wrapper runs as root,
* using the system malloc will increase security over using gtm_malloc. Additionally, by not using gtm_malloc, we
* are reducing code bloat.
*/
@ -26,7 +29,6 @@
#include <malloc.h>
#endif
#include <errno.h>
#define ROOTUID 0
#define ROOTGID 0

View File

@ -1,6 +1,6 @@
/****************************************************************
* *
* Copyright 2001, 2011 Fidelity Information Services, Inc *
* Copyright 2001, 2012 Fidelity Information Services, Inc *
* *
* This source code contains the intellectual property *
* of its copyright holder(s), and is made available *
@ -10,7 +10,9 @@
****************************************************************/
#include "mdef.h"
#define BYPASS_MEMCPY_OVERRIDE /* Signals gtm_string.h to not override memcpy(). The assert in the called routine ends
* up pulling in the world in various executables so bypass for this routine.
*/
#include "gtm_string.h"
#undef UNIX /* Cause non-GTM-runtime routines to be used since this is a standalone module */
#include "gtm_stdio.h"