Author: florian
Date: Sat Dec 20 16:52:08 2014
New Revision: 14825
Log:
Buffer audit. Resize some.
Modified:
trunk/coregrind/m_aspacemgr/aspacemgr-common.c
trunk/coregrind/m_debuginfo/readelf.c
trunk/coregrind/m_debuginfo/tytypes.c
trunk/coregrind/m_main.c
trunk/coregrind/m_sbprofile.c
trunk/coregrind/m_scheduler/scheduler.c
trunk/coregrind/m_signals.c
trunk/coregrind/m_syswrap/syswrap-generic.c
trunk/coregrind/m_syswrap/syswrap-linux.c
Modified: trunk/coregrind/m_aspacemgr/aspacemgr-common.c
==============================================================================
--- trunk/coregrind/m_aspacemgr/aspacemgr-common.c (original)
+++ trunk/coregrind/m_aspacemgr/aspacemgr-common.c Sat Dec 20 16:52:08 2014
@@ -321,7 +321,7 @@
{
#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] == '/')
Modified: trunk/coregrind/m_debuginfo/readelf.c
==============================================================================
--- trunk/coregrind/m_debuginfo/readelf.c (original)
+++ trunk/coregrind/m_debuginfo/readelf.c Sat Dec 20 16:52:08 2014
@@ -748,8 +748,7 @@
)
{
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 @@
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;
Modified: trunk/coregrind/m_debuginfo/tytypes.c
==============================================================================
--- trunk/coregrind/m_debuginfo/tytypes.c (original)
+++ trunk/coregrind/m_debuginfo/tytypes.c Sat Dec 20 16:52:08 2014
@@ -739,8 +739,7 @@
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));
}
Modified: trunk/coregrind/m_main.c
==============================================================================
--- trunk/coregrind/m_main.c (original)
+++ trunk/coregrind/m_main.c Sat Dec 20 16:52:08 2014
@@ -287,8 +287,8 @@
"\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 @@
}
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 @@
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"
Modified: trunk/coregrind/m_sbprofile.c
==============================================================================
--- trunk/coregrind/m_sbprofile.c (original)
+++ trunk/coregrind/m_sbprofile.c Sat Dec 20 16:52:08 2014
@@ -52,7 +52,7 @@
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 {
Modified: trunk/coregrind/m_scheduler/scheduler.c
==============================================================================
--- trunk/coregrind/m_scheduler/scheduler.c (original)
+++ trunk/coregrind/m_scheduler/scheduler.c Sat Dec 20 16:52:08 2014
@@ -1091,7 +1091,7 @@
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 @@
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 @@
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);
}
Modified: trunk/coregrind/m_signals.c
==============================================================================
--- trunk/coregrind/m_signals.c (original)
+++ trunk/coregrind/m_signals.c Sat Dec 20 16:52:08 2014
@@ -1400,7 +1400,7 @@
const HChar *VG_(signame)(Int sigNo)
{
- static HChar buf[20];
+ static HChar buf[20]; // large enough
switch(sigNo) {
case VKI_SIGHUP: return "SIGHUP";
Modified: trunk/coregrind/m_syswrap/syswrap-generic.c
==============================================================================
--- trunk/coregrind/m_syswrap/syswrap-generic.c (original)
+++ trunk/coregrind/m_syswrap/syswrap-generic.c Sat Dec 20 16:52:08 2014
@@ -720,7 +720,7 @@
} 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 @@
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 @@
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 @@
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 @@
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 @@
* 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) &&
Modified: trunk/coregrind/m_syswrap/syswrap-linux.c
==============================================================================
--- trunk/coregrind/m_syswrap/syswrap-linux.c (original)
+++ trunk/coregrind/m_syswrap/syswrap-linux.c Sat Dec 20 16:52:08 2014
@@ -2264,7 +2264,7 @@
{
static Int result = -1;
Int fd, read;
- HChar release[64];
+ HChar release[64]; // large enough
SysRes res;
if (result == -1) {
@@ -2273,12 +2273,13 @@
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 @@
PRE(sys_openat)
{
- HChar name[30];
+ HChar name[30]; // large enough
SysRes sres;
if (ARG3 & VKI_O_CREAT) {
@@ -4566,7 +4567,7 @@
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_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 @@
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 @@
{
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);
|