Source and destination overlap in memcpy(0x1BB700C0, 0x1BB700D0, 42)

Daniel Reed n at ml.org
Sun Apr 10 08:13:23 EST 2005


==21467== Source and destination overlap in memcpy(0x1BB700C0, 0x1BB700D0, 42)
==21467==    at 0x1B902BBD: memcpy (mac_replace_strmem.c:113)
==21467==    by 0x1B981EAF: copy (dbus-string.c:1408)
==21467==    by 0x1B982FEC: _dbus_string_copy_len (dbus-string.c:1578)
==21467==    by 0x1B97657A: marshal_len_followed_by_bytes (dbus-marshal-basic.c:776)
==21467==    by 0x1B976605: marshal_string (dbus-marshal-basic.c:808)
==21467==    by 0x1B976806: _dbus_marshal_write_basic (dbus-marshal-basic.c:889)
==21467==    by 0x1B94E490: _dbus_type_writer_write_basic_no_typecode (dbus-marshal-recursive.c:1682)
==21467==    by 0x1B94F29A: _dbus_type_writer_write_basic (dbus-marshal-recursive.c:2387)
==21467==    by 0x1B949B26: write_basic_field (dbus-marshal-header.c:304)
==21467==    by 0x1B94A279: _dbus_header_create (dbus-marshal-header.c:619)
==21467==    by 0x1B953012: dbus_message_new_error (dbus-message.c:936)
==21467==    by 0x1B909DD4: _ndbus_obj_call_perform (libndbus.c:368)

The client code is:
         if (reply == NULL) {
                 DBusMessage *dummy;

                 dummy = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL);
                 reply = dbus_message_new_error(dummy, error.name, error.message);



The manual page for memcpy() does indicate overlap is never allowed. 
memmove() may be used when overlap is possible, as it can take measures to 
ensure it never writes over something it has yet to copy.



Index: dbus/dbus-string.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-string.c,v
retrieving revision 1.67
diff -u -r1.67 dbus-string.c
--- dbus/dbus-string.c	25 Feb 2005 22:03:30 -0000	1.67
+++ dbus/dbus-string.c	9 Apr 2005 19:44:24 -0000
@@ -1405,7 +1405,7 @@
    if (!open_gap (len, dest, insert_at))
      return FALSE;

-  memcpy (dest->str + insert_at,
+  memmove (dest->str + insert_at,
            source->str + start,
            len);


Test suite still passes after applying, and valgrind becomes happy.

-- 
Daniel Reed <n at ml.org>	http://naim-users.org/nmlorg/	http://naim.n.ml.org/
A democracy is a sheep and two wolves deciding on what to have for
lunch. Freedom is a well armed sheep contesting the results of the
decision. -- Benjamin Franklin


More information about the dbus mailing list