]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Buffer audit. Resize some.
authorFlorian Krohm <florian@eich-krohm.de>
Sat, 20 Dec 2014 16:52:08 +0000 (16:52 +0000)
committerFlorian Krohm <florian@eich-krohm.de>
Sat, 20 Dec 2014 16:52:08 +0000 (16:52 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14825

coregrind/m_aspacemgr/aspacemgr-common.c
coregrind/m_debuginfo/readelf.c
coregrind/m_debuginfo/tytypes.c
coregrind/m_main.c
coregrind/m_sbprofile.c
coregrind/m_scheduler/scheduler.c
coregrind/m_signals.c
coregrind/m_syswrap/syswrap-generic.c
coregrind/m_syswrap/syswrap-linux.c

index f700c6c14cf5eece71996bd3d32b1ec3cc21f787..2c099a9a23018bb9e62db62fd6991920fac0ddd3 100644 (file)
@@ -321,7 +321,7 @@ Bool ML_(am_resolve_filename) ( Int fd, /*OUT*/HChar* buf, Int nbuf )
 {
 #if defined(VGO_linux)
    Int i;
-   HChar tmp[64];
+   HChar tmp[64];    // large enough
    for (i = 0; i < nbuf; i++) buf[i] = 0;
    ML_(am_sprintf)(tmp, "/proc/self/fd/%d", fd);
    if (ML_(am_readlink)(tmp, buf, nbuf) > 0 && buf[0] == '/')
index 95e4bb00b2c35a4d0486802044e1997e46678757..f5c46748d515a0033391895916cd58c1169bc128 100644 (file)
@@ -748,8 +748,7 @@ void read_elf_symtab__normal(
      )
 {
    if (escn_strtab->img == NULL || escn_symtab->img == NULL) {
-      HChar buf[80];  // FIXME: allocate dynamically
-      vg_assert(VG_(strlen)(tab_name) < 40);
+      HChar buf[VG_(strlen)(tab_name) + 40];
       VG_(sprintf)(buf, "   object doesn't have a %s", tab_name);
       ML_(symerr)(di, False, buf);
       return;
@@ -879,8 +878,7 @@ void read_elf_symtab__ppc64be_linux(
    TempSym    *prev;
 
    if (escn_strtab->img == NULL || escn_symtab->img == NULL) {
-      HChar buf[80];  // FIXME: allocate dynamically
-      vg_assert(VG_(strlen)(tab_name) < 40);
+      HChar buf[VG_(strlen)(tab_name) + 40];
       VG_(sprintf)(buf, "   object doesn't have a %s", tab_name);
       ML_(symerr)(di, False, buf);
       return;
index a2abf7197472c57b58194007e88bd7726d859465..3c91a76bb2a0f92c183e3a7326b628c372d6356c 100644 (file)
@@ -739,8 +739,7 @@ MaybeULong ML_(sizeOfType)( const XArray* /* of TyEnt */ tyents,
 
 static void copy_UWord_into_XA ( XArray* /* of HChar */ xa,
                                  UWord uw ) {
-   HChar buf[32];
-   VG_(memset)(buf, 0, sizeof(buf));
+   HChar buf[32];     // large enough 
    VG_(sprintf)(buf, "%lu", uw);
    VG_(addBytesToXA)( xa, buf, VG_(strlen)(buf));
 }
index 4e9f696abc323db30ae2c49a672a988f2471014a..743ecde233aad1d99b015cd6f72896794743f9b1 100644 (file)
@@ -287,8 +287,8 @@ static void usage_NORETURN ( Bool debug_help )
 "\n";
 
    const HChar* gdb_path = GDB_PATH;
-   HChar default_alignment[30];
-   HChar default_redzone_size[30];
+   HChar default_alignment[30];      // large enough
+   HChar default_redzone_size[30];   // large enough
 
    // Ensure the message goes to stdout
    VG_(log_output_sink).fd = 1;
@@ -2208,7 +2208,7 @@ Int valgrind_main ( Int argc, HChar **argv, HChar **envp )
    }
 
    if (VG_(clo_xml)) {
-      HChar buf[50];
+      HChar buf[50];    // large enough
       VG_(elapsed_wallclock_time)(buf, sizeof buf);
       VG_(printf_xml)( "<status>\n"
                        "  <state>RUNNING</state>\n"
@@ -2545,7 +2545,7 @@ void shutdown_actions_NORETURN( ThreadId tid,
       VG_(message)(Vg_UserMsg, "\n");
 
    if (VG_(clo_xml)) {
-      HChar buf[50];
+      HChar buf[50];    // large enough
       VG_(elapsed_wallclock_time)(buf, sizeof buf);
       VG_(printf_xml)( "<status>\n"
                               "  <state>FINISHED</state>\n"
index 7ed995090d9b36e080cd20ec48989874f4fa4d07..4befbc89323c0be55b80c640219504e18595facc 100644 (file)
@@ -52,7 +52,7 @@ void show_SB_profile ( const SBProfEntry tops[], UInt n_tops,
    ULong score_cumul, score_cumul_saved, score_here;
    Int   r; /* must be signed */
 
-   HChar ecs_txt[50];
+   HChar ecs_txt[50];    // large enough
    if (ecs_done > 0) {
       VG_(sprintf)(ecs_txt, "%'llu ecs done", ecs_done);
    } else {
index 4faf001649d3565495871921db3919772e67de5a..2e1184adde55ec4fc77284dbafb378271e517b8d 100644 (file)
@@ -1091,7 +1091,7 @@ static void handle_syscall(ThreadId tid, UInt trc)
       syscall runs. */
 
    if (VG_(clo_sanity_level) >= 3) {
-      HChar buf[50];
+      HChar buf[50];    // large enough
       VG_(sprintf)(buf, "(BEFORE SYSCALL, tid %d)", tid);
       Bool ok = VG_(am_do_sync_check)(buf, __FILE__, __LINE__);
       vg_assert(ok);
@@ -1100,7 +1100,7 @@ static void handle_syscall(ThreadId tid, UInt trc)
    SCHEDSETJMP(tid, jumped, VG_(client_syscall)(tid, trc));
 
    if (VG_(clo_sanity_level) >= 3) {
-      HChar buf[50];
+      HChar buf[50];    // large enough
       VG_(sprintf)(buf, "(AFTER SYSCALL, tid %d)", tid);
       Bool ok = VG_(am_do_sync_check)(buf, __FILE__, __LINE__);
       vg_assert(ok);
@@ -1320,8 +1320,9 @@ VgSchedReturnCode VG_(scheduler) ( ThreadId tid )
                               tid, 0/*ignored*/, False );
 
       if (VG_(clo_trace_sched) && VG_(clo_verbosity) > 2) {
-        HChar buf[50];
-        VG_(sprintf)(buf, "TRC: %s", name_of_sched_event(trc[0]));
+         const HChar *name = name_of_sched_event(trc[0]);
+         HChar buf[VG_(strlen)(name) + 10];    // large enough
+        VG_(sprintf)(buf, "TRC: %s", name);
         print_sched_event(tid, buf);
       }
 
index 508f315116c692b0b412a617478f31e2b34f4adf..e730d7a18ae295f7c9401c7cd985dd1ddaa94d0c 100644 (file)
@@ -1400,7 +1400,7 @@ void push_signal_frame ( ThreadId tid, const vki_siginfo_t *siginfo,
 
 const HChar *VG_(signame)(Int sigNo)
 {
-   static HChar buf[20];
+   static HChar buf[20];  // large enough
 
    switch(sigNo) {
       case VKI_SIGHUP:    return "SIGHUP";
index c506232d31bf0bd0ab378b5cb4d1edd4ddb5eb75..5c75ddac4d5cd66168d38e42930ccadc2db6b5ee 100644 (file)
@@ -720,7 +720,7 @@ HChar *inet6_to_name(struct vki_sockaddr_in6 *sa, UInt len, HChar *name)
    } else if (sa->sin6_port == 0) {
       VG_(sprintf)(name, "<unbound>");
    } else {
-      char addr[128];
+      HChar addr[100];    // large enough
       inet6_format(addr, (void *)&(sa->sin6_addr));
       VG_(sprintf)(name, "[%s]:%u", addr, VG_(ntohs)(sa->sin6_port));
    }
@@ -748,8 +748,8 @@ getsockdetails(Int fd)
    if(VG_(getsockname)(fd, (struct vki_sockaddr *)&(laddr.a), &llen) != -1) {
       switch(laddr.a.sa_family) {
       case VKI_AF_INET: {
-         static char lname[32];
-         static char pname[32];
+         HChar lname[32];   // large enough
+         HChar pname[32];   // large enough
          struct vki_sockaddr_in paddr;
          Int plen = sizeof(struct vki_sockaddr_in);
 
@@ -764,8 +764,8 @@ getsockdetails(Int fd)
          return;
          }
       case VKI_AF_INET6: {
-         static char lname[128];
-         static char pname[128];
+         HChar lname[128];  // large enough
+         HChar pname[128];  // large enough
          struct vki_sockaddr_in6 paddr;
          Int plen = sizeof(struct vki_sockaddr_in6);
 
@@ -3812,7 +3812,7 @@ PRE(sys_open)
       fake file we cooked up at startup (in m_main).  Also, seek the
       cloned fd back to the start. */
    {
-      HChar  name[30];
+      HChar  name[30];   // large enough
       HChar* arg1s = (HChar*) ARG1;
       SysRes sres;
 
@@ -3837,7 +3837,7 @@ PRE(sys_open)
       fake file we cooked up at startup (in m_main).  Also, seek the
       cloned fd back to the start. */
    {
-      HChar  name[30];
+      HChar  name[30];   // large enough
       HChar* arg1s = (HChar*) ARG1;
       SysRes sres;
 
@@ -3985,7 +3985,7 @@ PRE(sys_readlink)
        * Handle the case where readlink is looking at /proc/self/exe or
        * /proc/<pid>/exe.
        */
-      HChar name[25];
+      HChar  name[30];   // large enough
       HChar* arg1s = (HChar*) ARG1;
       VG_(sprintf)(name, "/proc/%d/exe", VG_(getpid)());
       if (ML_(safe_to_deref)(arg1s, 1) &&
index d63010006d4269a3616b6a23bc1b9a029ec51053..bc86eadbc70de36f0ed64ff851e3f9564eed91c6 100644 (file)
@@ -2264,7 +2264,7 @@ static Bool linux_kernel_2_6_22(void)
 {
    static Int result = -1;
    Int fd, read;
-   HChar release[64];
+   HChar release[64];   // large enough
    SysRes res;
 
    if (result == -1) {
@@ -2273,12 +2273,13 @@ static Bool linux_kernel_2_6_22(void)
          return False;
       fd = sr_Res(res);
       read = VG_(read)(fd, release, sizeof(release) - 1);
-      vg_assert(read >= 0);
+      if (read < 0)
+         return False;
       release[read] = 0;
       VG_(close)(fd);
       //VG_(printf)("kernel release = %s\n", release);
-      result = (VG_(strncmp)(release, "2.6.22", 6) == 0
-                && (release[6] < '0' || release[6] > '9'));
+      result = VG_(strncmp)(release, "2.6.22", 6) == 0
+               && ! VG_(isdigit)(release[6]);
    }
    vg_assert(result == 0 || result == 1);
    return result == 1;
@@ -4384,7 +4385,7 @@ POST(sys_socketpair)
 
 PRE(sys_openat)
 {
-   HChar  name[30];
+   HChar  name[30];   // large enough
    SysRes sres;
 
    if (ARG3 & VKI_O_CREAT) {
@@ -4566,7 +4567,7 @@ PRE(sys_symlinkat)
 
 PRE(sys_readlinkat)
 {
-   HChar name[25];
+   HChar name[30];       // large enough
    Word  saved = SYSNO;
 
    PRINT("sys_readlinkat ( %ld, %#lx(%s), %#lx, %llu )", ARG1,ARG2,(char*)ARG2,ARG3,(ULong)ARG4);
@@ -4826,7 +4827,7 @@ PRE(sys_process_vm_writev)
 PRE(sys_sendmmsg)
 {
    struct vki_mmsghdr *mmsg = (struct vki_mmsghdr *)ARG2;
-   HChar name[32];
+   HChar name[40];     // large enough
    UInt i;
    *flags |= SfMayBlock;
    PRINT("sys_sendmmsg ( %ld, %#lx, %ld, %ld )",ARG1,ARG2,ARG3,ARG4);
@@ -4854,7 +4855,7 @@ POST(sys_sendmmsg)
 PRE(sys_recvmmsg)
 {
    struct vki_mmsghdr *mmsg = (struct vki_mmsghdr *)ARG2;
-   HChar name[32];
+   HChar name[40];     // large enough
    UInt i;
    *flags |= SfMayBlock;
    PRINT("sys_recvmmsg ( %ld, %#lx, %ld, %ld, %#lx )",ARG1,ARG2,ARG3,ARG4,ARG5);
@@ -4875,7 +4876,7 @@ POST(sys_recvmmsg)
 {
    if (RES > 0) {
       struct vki_mmsghdr *mmsg = (struct vki_mmsghdr *)ARG2;
-      HChar name[32];
+      HChar name[32];    // large enough
       UInt i;
       for (i = 0; i < RES; i++) {
          VG_(sprintf)(name, "mmsg[%u].msg_hdr", i);