hi,

Valgrind reports the correct wirte as an invalid write. It is
occurring at /usr/libexec/ld.so.

I run following program.

$ cat main.c
#include <stdio.h>

int
main(int argc, char *argv[])
{
        printf("Hello, world\n");
        return (0);
}
$ cc -g main.c
$ valgrind ./a.out
==46291== Memcheck, a memory error detector
==46291== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==46291== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==46291== Command: /home/asou/tmp/a.out
==46291==
==46291== Invalid write of size 1
==46291==    at 0x410730C: ???
==46291==    by 0x4103CC8: ???
==46291==    by 0x41032EE: ???
==46291==    by 0x4102605: ???
==46291==  Address 0x40052d0 is not stack'd, malloc'd or (recently) free'd
==46291==
==46291== Invalid write of size 1
==46291==    at 0x410730E: ???
==46291==    by 0x4103CC8: ???
==46291==    by 0x41032EE: ???
==46291==    by 0x4102605: ???
==46291==  Address 0x40052d1 is not stack'd, malloc'd or (recently) free'd
==46291==

</snip>

==46291== For counts of detected and suppressed errors, rerun with: -v
==46291== Use --track-origins=yes to see where uninitialised values come from
==46291== ERROR SUMMARY: 3209 errors from 357 contexts (suppressed: 0 from 0)
$ 

I got 3209 errors.

However, when the following patch was applied, the error was reduced
to four as below:

$ valgrind ./a.out
==7449== Memcheck, a memory error detector
==7449== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==7449== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==7449== Command: /home/asou/tmp/a.out
==7449==
==7449== Use of uninitialised value of size 8
==7449==    at 0x4ACB969: write (sys/w_write.c:26)
==7449==    by 0x4AB60DF: __sflush (stdio/fflush.c:80)
==7449==    by 0x4A491F1: __sfvwrite (stdio/fvwrite.c:191)
==7449==    by 0x4A62F62: __sprint (stdio/vfprintf.c:108)
==7449==    by 0x4A62F62: __vfprintf (stdio/vfprintf.c:1067)
==7449==    by 0x4A5F151: vfprintf (stdio/vfprintf.c:263)
==7449==    by 0x4A43DB0: printf (stdio/printf.c:44)
==7449==    by 0x109374: main (main.c:6)
==7449==
==7449== Use of uninitialised value of size 8
==7449==    at 0x4ACB97A: write (sys/w_write.c:26)
==7449==    by 0x4AB60DF: __sflush (stdio/fflush.c:80)
==7449==    by 0x4A491F1: __sfvwrite (stdio/fvwrite.c:191)
==7449==    by 0x4A62F62: __sprint (stdio/vfprintf.c:108)
==7449==    by 0x4A62F62: __vfprintf (stdio/vfprintf.c:1067)
==7449==    by 0x4A5F151: vfprintf (stdio/vfprintf.c:263)
==7449==    by 0x4A43DB0: printf (stdio/printf.c:44)
==7449==    by 0x109374: main (main.c:6)
==7449==
Hello, world
==7449== Use of uninitialised value of size 8
==7449==    at 0x4ACB98E: write (sys/w_write.c:28)
==7449==    by 0x4AB60DF: __sflush (stdio/fflush.c:80)
==7449==    by 0x4A491F1: __sfvwrite (stdio/fvwrite.c:191)
==7449==    by 0x4A62F62: __sprint (stdio/vfprintf.c:108)
==7449==    by 0x4A62F62: __vfprintf (stdio/vfprintf.c:1067)
==7449==    by 0x4A5F151: vfprintf (stdio/vfprintf.c:263)
==7449==    by 0x4A43DB0: printf (stdio/printf.c:44)
==7449==    by 0x109374: main (main.c:6)
==7449==
==7449== Use of uninitialised value of size 8
==7449==    at 0x4ACC31C: _thread_finalize (stdlib/atexit.c:131)
==7449==    by 0x4ACC31C: __cxa_finalize (stdlib/atexit.c:153)
==7449==    by 0x4AD13C0: exit (stdlib/exit.c:54)
==7449==    by 0x109141: ___start (in /home/asou/tmp/a.out)
==7449==
==7449==
==7449== FILE DESCRIPTORS: 3 open at exit.
==7449== Open file descriptor 2:
==7449==    <inherited from parent>
==7449==
==7449== Open file descriptor 1:
==7449==    <inherited from parent>
==7449==
==7449== Open file descriptor 0:
==7449==    <inherited from parent>
==7449==
==7449==
==7449== HEAP SUMMARY:
==7449==     in use at exit: 65,536 bytes in 1 blocks
==7449==   total heap usage: 1 allocs, 0 frees, 65,536 bytes allocated
==7449==
==7449== LEAK SUMMARY:
==7449==    definitely lost: 0 bytes in 0 blocks
==7449==    indirectly lost: 0 bytes in 0 blocks
==7449==      possibly lost: 0 bytes in 0 blocks
==7449==    still reachable: 65,536 bytes in 1 blocks
==7449==         suppressed: 0 bytes in 0 blocks
==7449== Rerun with --leak-check=full to see details of leaked memory
==7449==
==7449== For counts of detected and suppressed errors, rerun with: -v
==7449== Use --track-origins=yes to see where uninitialised values come from
==7449== ERROR SUMMARY: 4 errors from 4 contexts (suppressed: 0 from 0)
$ 


The patch to Makefile is a temporary. Because, my previous patch
https://marc.info/?l=openbsd-ports&m=158624064212984&w=2
does not get OK.

ok?

Index: Makefile
===================================================================
RCS file: /cvs/ports/devel/valgrind/Makefile,v
retrieving revision 1.23
diff -u -p -u -r1.23 Makefile
--- Makefile    23 Dec 2019 23:26:32 -0000      1.23
+++ Makefile    30 Apr 2020 06:39:41 -0000
@@ -7,7 +7,7 @@ CATEGORIES =            devel
 
 V =                    3.10.1
 PV =                   20160331
-REVISION =             16
+REVISION =             17
 DISTNAME =             valgrind-${V}
 EXTRACT_SUFX =         .tar.bz2
 
Index: patches/patch-coregrind_m_syswrap_syswrap_openbsd_c
===================================================================
RCS file: 
/cvs/ports/devel/valgrind/patches/patch-coregrind_m_syswrap_syswrap_openbsd_c,v
retrieving revision 1.2
diff -u -p -u -r1.2 patch-coregrind_m_syswrap_syswrap_openbsd_c
--- patches/patch-coregrind_m_syswrap_syswrap_openbsd_c 23 Dec 2019 23:26:32 
-0000      1.2
+++ patches/patch-coregrind_m_syswrap_syswrap_openbsd_c 30 Apr 2020 06:39:41 
-0000
@@ -55,7 +55,7 @@
  PRE(sys_getsockname)
  {
     PRINT("sys_getsockname ( %ld, %#lx, %#lx )",ARG1,ARG2,ARG3);
-@@ -791,15 +791,6 @@
+@@ -780,15 +791,6 @@
     SET_STATUS_Success(0);
  }
  
@@ -71,7 +71,7 @@
  PRE(sys_getlogin)
  {
     PRINT("sys_getlogin ( %#lx, %ld )",ARG1,ARG2);
-@@ -2787,17 +2778,40 @@
+@@ -2776,17 +2778,40 @@
  
  PRE(sys___thrsleep)
  {
@@ -115,7 +115,7 @@
  }
  
  PRE(sys___thrsigdivert)
-@@ -2830,6 +2843,68 @@
+@@ -2819,6 +2844,68 @@
  // XXXTBD
  }
  
@@ -184,7 +184,7 @@
  PRE(sys_utimensat)
  {
  // XXXTBD
-@@ -3961,7 +4036,7 @@
+@@ -3950,7 +4037,7 @@
    
    GENXY(__NR_close,           sys_close),             // 6
    BSDXY(__NR_getentropy,      sys_getentropy),        // 7
@@ -193,7 +193,16 @@
    GENX_(__NR_link,            sys_link),              // 9
    GENX_(__NR_unlink,          sys_unlink),            // 10
    
-@@ -4053,7 +4128,7 @@
+@@ -4031,7 +4118,7 @@
+   GENX_(__NR_select,          sys_select),            // 71
+   BSDXY(__NR_kevent,          sys_kevent),            // 72
+   GENX_(__NR_munmap,          sys_munmap),            // 73
+-  GENX_(__NR_mprotect,                sys_mprotect),          // 74
++  GENXY(__NR_mprotect,                sys_mprotect),          // 74
+   GENX_(__NR_madvise,         sys_madvise),           // 75
+ 
+   GENX_(__NR_utimes,          sys_utimes),            // 76
+@@ -4042,7 +4129,7 @@
  
    GENX_(__NR_getpgrp,         sys_getpgrp),           // 81
    GENX_(__NR_setpgid,         sys_setpgid),           // 82
@@ -202,7 +211,7 @@
    BSDX_(__NR_utimensat,               sys_utimensat),         // 84
    BSDX_(__NR_futimens,                sys_futimens),          // 85
  
-@@ -4079,7 +4094,7 @@
+@@ -4079,7 +4166,7 @@
    BSDX_(__NR_sigsuspend,      sys_sigsuspend),        // 111
    BSDX_(__NR_sendsyslog,      sys_sendsyslog),        // 112
    // obsol orecvmsg                                   // 113
--
ASOU Masato

Reply via email to