Hello,

This is with valgrind 3.14.0 compiled and used on SuSE Linux 12 and 15 x86_64.

I have had a hart time to nail down the reason for a lot(!) of such vg
messages:

==1272== Invalid read of size 8
==1272==    at 0x4C355BF: memmove (vg_replace_strmem.c:1270)
==1272==    by 0x64A50D7: zzstrncpy (zzstdc.C:143)
==1272==    by 0x67366DE: SqlCharToChar (ec_general.ec:165)
==1272==    by 0x675ED84: Para2Host (acq_update.h:59)
==1272==    by 0x675FCE7: SQLExistUpdateEntry (ec_acq_update.ec:200)
...
==1272==  Address 0x17d80148 is 24 bytes after a block of size 16 in arena 
"client"

The reason was at the end of debugging that we replaced in some central
place of the server a function call (due to vg messages about
overlapping args)

        strncpy(dst, src, n);

by

        memset(dst, 0, n);
        memmove(dst, src, n);

which is not fully equivalent because strncpy(3) will stop at the first
\0 byte in src, while memmove(3) will copy n bytes, regardles if they
are valid bytes in src. As this was in some low level function, it
generated a mass of the above vg messages.

To debug it, I ended up printing in hex the pointer src, the value of n
and the first n bytes of src which finally gave me a clue what was wrong:
the number n was some kind of a fixed maximal length for dst and regardless of
the provided bytes in src. Fixed by:

        memset(dst, 0, n);
        n = strlen(src);
        memmove(dst, src, n);

So far so good. What would have helped me is that vg could print in its
replacement functions for memmove(3) ... (vg_replace_strmem.c:1270)
the provided pointers and other args, and as well part of the src
buffer. For sure vg knows exactly these values to watch the illegal
memory access.

Any thoughts about this?

        matthias

-- 
Matthias Apitz, ✉ g...@unixarea.de, http://www.unixarea.de/ +49-176-38902045
Public GnuPG key: http://www.unixarea.de/key.pub
¡Con Cuba no te metas!  «»  Don't mess with Cuba!  «»  Leg Dich nicht mit Kuba 
an!
http://www.cubadebate.cu/noticias/2020/12/25/en-video-con-cuba-no-te-metas/


_______________________________________________
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to