From: Florian Krohm Date: Sat, 20 Dec 2014 16:52:08 +0000 (+0000) Subject: Buffer audit. Resize some. X-Git-Tag: svn/VALGRIND_3_11_0~761 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=87dbf329ed3a498d7ebb582c39c83a4729be7970;p=thirdparty%2Fvalgrind.git Buffer audit. Resize some. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14825 --- diff --git a/coregrind/m_aspacemgr/aspacemgr-common.c b/coregrind/m_aspacemgr/aspacemgr-common.c index f700c6c14c..2c099a9a23 100644 --- a/coregrind/m_aspacemgr/aspacemgr-common.c +++ b/coregrind/m_aspacemgr/aspacemgr-common.c @@ -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] == '/') diff --git a/coregrind/m_debuginfo/readelf.c b/coregrind/m_debuginfo/readelf.c index 95e4bb00b2..f5c46748d5 100644 --- a/coregrind/m_debuginfo/readelf.c +++ b/coregrind/m_debuginfo/readelf.c @@ -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; diff --git a/coregrind/m_debuginfo/tytypes.c b/coregrind/m_debuginfo/tytypes.c index a2abf71974..3c91a76bb2 100644 --- a/coregrind/m_debuginfo/tytypes.c +++ b/coregrind/m_debuginfo/tytypes.c @@ -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)); } diff --git a/coregrind/m_main.c b/coregrind/m_main.c index 4e9f696abc..743ecde233 100644 --- a/coregrind/m_main.c +++ b/coregrind/m_main.c @@ -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)( "\n" " RUNNING\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)( "\n" " FINISHED\n" diff --git a/coregrind/m_sbprofile.c b/coregrind/m_sbprofile.c index 7ed995090d..4befbc8932 100644 --- a/coregrind/m_sbprofile.c +++ b/coregrind/m_sbprofile.c @@ -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 { diff --git a/coregrind/m_scheduler/scheduler.c b/coregrind/m_scheduler/scheduler.c index 4faf001649..2e1184adde 100644 --- a/coregrind/m_scheduler/scheduler.c +++ b/coregrind/m_scheduler/scheduler.c @@ -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); } diff --git a/coregrind/m_signals.c b/coregrind/m_signals.c index 508f315116..e730d7a18a 100644 --- a/coregrind/m_signals.c +++ b/coregrind/m_signals.c @@ -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"; diff --git a/coregrind/m_syswrap/syswrap-generic.c b/coregrind/m_syswrap/syswrap-generic.c index c506232d31..5c75ddac4d 100644 --- a/coregrind/m_syswrap/syswrap-generic.c +++ b/coregrind/m_syswrap/syswrap-generic.c @@ -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, ""); } 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//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) && diff --git a/coregrind/m_syswrap/syswrap-linux.c b/coregrind/m_syswrap/syswrap-linux.c index d63010006d..bc86eadbc7 100644 --- a/coregrind/m_syswrap/syswrap-linux.c +++ b/coregrind/m_syswrap/syswrap-linux.c @@ -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);