Skip to content

Commit 5d40ed8

Browse files
committed
MDEV-11752 Unsafe strmov - function definition in include/m_string.h
assert that strmov() cannot be used on overlapping strings. (because strpcpy cannot)
1 parent e0a03ca commit 5d40ed8

File tree

3 files changed

+4
-1
lines changed

3 files changed

+4
-1
lines changed

dbug/dbug.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1883,7 +1883,7 @@ static void DBUGOpenFile(CODE_STATE *cs,
18831883
cs->stack->name[len]=0;
18841884
}
18851885
else
1886-
strmov(cs->stack->name,name);
1886+
strmov(cs->stack->name,name);
18871887
name=cs->stack->name;
18881888
if (strcmp(name, "-") == 0)
18891889
{

include/m_string.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,13 @@ extern void *(*my_str_malloc)(size_t);
7373
extern void *(*my_str_realloc)(void *, size_t);
7474
extern void (*my_str_free)(void *);
7575

76+
#ifdef DBUG_OFF
7677
#if defined(HAVE_STPCPY) && MY_GNUC_PREREQ(3, 4) && !defined(__INTEL_COMPILER)
7778
#define strmov(A,B) __builtin_stpcpy((A),(B))
7879
#elif defined(HAVE_STPCPY)
7980
#define strmov(A,B) stpcpy((A),(B))
8081
#endif
82+
#endif
8183

8284
/* Declared in int2str() */
8385
extern const char _dig_vec_upper[];

strings/strmov.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
char *strmov(register char *dst, register const char *src)
4242
{
43+
DBUG_ASSERT(src + strlen(src) < dst || dst + strlen(src) < src);
4344
while ((*dst++ = *src++)) ;
4445
return dst-1;
4546
}

0 commit comments

Comments
 (0)