Skip to content

Commit

Permalink
MDEV-11752 Unsafe strmov - function definition in include/m_string.h
Browse files Browse the repository at this point in the history
assert that strmov() cannot be used on overlapping strings.
(because strpcpy cannot)
  • Loading branch information
vuvova committed Mar 10, 2017
1 parent e0a03ca commit 5d40ed8
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dbug/dbug.c
Original file line number Diff line number Diff line change
Expand Up @@ -1883,7 +1883,7 @@ static void DBUGOpenFile(CODE_STATE *cs,
cs->stack->name[len]=0;
}
else
strmov(cs->stack->name,name);
strmov(cs->stack->name,name);
name=cs->stack->name;
if (strcmp(name, "-") == 0)
{
Expand Down
2 changes: 2 additions & 0 deletions include/m_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@ extern void *(*my_str_malloc)(size_t);
extern void *(*my_str_realloc)(void *, size_t);
extern void (*my_str_free)(void *);

#ifdef DBUG_OFF
#if defined(HAVE_STPCPY) && MY_GNUC_PREREQ(3, 4) && !defined(__INTEL_COMPILER)
#define strmov(A,B) __builtin_stpcpy((A),(B))
#elif defined(HAVE_STPCPY)
#define strmov(A,B) stpcpy((A),(B))
#endif
#endif

/* Declared in int2str() */
extern const char _dig_vec_upper[];
Expand Down
1 change: 1 addition & 0 deletions strings/strmov.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

char *strmov(register char *dst, register const char *src)
{
DBUG_ASSERT(src + strlen(src) < dst || dst + strlen(src) < src);
while ((*dst++ = *src++)) ;
return dst-1;
}
Expand Down

0 comments on commit 5d40ed8

Please sign in to comment.