commit fc75e5ea3e57d58bbbbd3fd8fff3a71de9a1b172
Author: tom <tom@a5019735-40e9-0310-863c-91ae7b9d1cf9>
Date: Thu Feb 28 12:50:55 2013 +0000
Don't check the flags word in msghdr for sendmsg as the
kernel will neither read nor write it.
Patch from Mark Wielaard to fix BZ#315441.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@13294 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/memcheck/tests/filter_stderr b/memcheck/tests/filter_stderr
index abd6792..3d62d94 100755
--- a/memcheck/tests/filter_stderr
+++ b/memcheck/tests/filter_stderr
@@ -22,6 +22,9 @@ sed "s/checked [0-9,]* bytes./checked ... bytes./" |
# records. So we filter out the loss record numbers.
perl -p -e "s/in loss record \d+ of \d+/in loss record ... of .../" |
+# Filter out glibc debuginfo if installed.
+perl -p -e "s/\(syscall-template.S:[0-9]*\)/(in \/...libc...)/" |
+
$dir/../../memcheck/tests/filter_memcheck "$@"
exit 0
diff --git a/memcheck/tests/sendmsg.c b/memcheck/tests/sendmsg.c
new file mode 100644
index 0000000..2039f07
--- /dev/null
+++ b/memcheck/tests/sendmsg.c
@@ -0,0 +1,74 @@
+#include <netinet/ip.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#define PORT 12345
+
+int
+main (int argc, char **argv)
+{
+ int fd;
+ struct sockaddr_in sa;
+ struct msghdr msg;
+ struct iovec iov[2];
+
+ fd = socket (AF_INET, SOCK_DGRAM, 0);
+ if (fd == -1)
+ {
+ perror ("socket()");
+ exit (EXIT_FAILURE);
+ }
+
+ sa.sin_family = AF_INET;
+ sa.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
+ sa.sin_port = htons (PORT);
+ if (connect (fd, (struct sockaddr *) &sa, sizeof (sa)) == -1)
+ {
+ perror ("connect ()");
+ exit (EXIT_FAILURE);
+ }
+
+ // Create msg_hdr. Oops, we forget to set msg_name...
+ msg.msg_namelen = 0;
+ iov[0].iov_base = "one";
+ iov[0].iov_len = 3;
+ iov[1].iov_base = "two";
+ iov[1].iov_len = 3;
+ msg.msg_iov = &iov;
+ msg.msg_iovlen = 2;
+ msg.msg_control = NULL;
+ msg.msg_controllen = 0;
+
+ size_t s = sendmsg (fd, &msg, 0);
+
+ // Note how we now do set msg_name, but don't set msg_flags.
+ // The msg_flags field is ignored by sendmsg.
+ msg.msg_name = NULL;
+
+ fd = socket (AF_INET, SOCK_DGRAM, 0);
+ if (fd == -1)
+ {
+ perror ("socket()");
+ exit (EXIT_FAILURE);
+ }
+
+ if (connect (fd, (struct sockaddr *) &sa, sizeof (sa)) == -1)
+ {
+ perror ("connect ()");
+ exit (EXIT_FAILURE);
+ }
+
+ s = sendmsg (fd, &msg, 0);
+ if (s == -1)
+ {
+ perror ("sendmsg ()");
+ exit (EXIT_FAILURE);
+ }
+ else
+ fprintf (stderr, "sendmsg: %d\n", (int) s);
+
+ exit(0);
+}
diff --git a/memcheck/tests/sendmsg.stderr.exp b/memcheck/tests/sendmsg.stderr.exp
new file mode 100644
index 0000000..38e20c5
--- /dev/null
+++ b/memcheck/tests/sendmsg.stderr.exp
@@ -0,0 +1,6 @@
+Syscall param sendmsg(msg) points to uninitialised byte(s)
+ at 0x........: sendmsg (in /...libc...)
+ by 0x........: main (sendmsg.c:45)
+ Address 0x........ is on thread 1's stack
+
+sendmsg: 6
diff --git a/memcheck/tests/sendmsg.vgtest b/memcheck/tests/sendmsg.vgtest
new file mode 100644
index 0000000..f252b62
--- /dev/null
+++ b/memcheck/tests/sendmsg.vgtest
@@ -0,0 +1,2 @@
+prog: sendmsg
+vgopts: -q
--- valgrind-3.8.1/memcheck/tests/Makefile.in.orig 2013-02-19 14:46:14.305186272 +0100
+++ valgrind-3.8.1/memcheck/tests/Makefile.in 2013-02-19 14:59:41.284835217 +0100
@@ -105,20 +105,20 @@
partial_load$(EXEEXT) pdb-realloc$(EXEEXT) \
pdb-realloc2$(EXEEXT) pipe$(EXEEXT) pointer-trace$(EXEEXT) \
post-syscall$(EXEEXT) realloc1$(EXEEXT) realloc2$(EXEEXT) \
- realloc3$(EXEEXT) sbfragment$(EXEEXT) sh-mem$(EXEEXT) \
- sh-mem-random$(EXEEXT) sigaltstack$(EXEEXT) signal2$(EXEEXT) \
- sigprocmask$(EXEEXT) static_malloc$(EXEEXT) sigkill$(EXEEXT) \
- stpncpy$(EXEEXT) strchr$(EXEEXT) str_tester$(EXEEXT) \
- supp_unknown$(EXEEXT) supp1$(EXEEXT) supp2$(EXEEXT) \
- suppfree$(EXEEXT) test-plo$(EXEEXT) trivialleak$(EXEEXT) \
- unit_libcbase$(EXEEXT) unit_oset$(EXEEXT) varinfo1$(EXEEXT) \
- varinfo2$(EXEEXT) varinfo3$(EXEEXT) varinfo4$(EXEEXT) \
- varinfo5$(EXEEXT) varinfo5so.so$(EXEEXT) varinfo6$(EXEEXT) \
- vcpu_fbench$(EXEEXT) vcpu_fnfns$(EXEEXT) wcs$(EXEEXT) \
- xml1$(EXEEXT) wrap1$(EXEEXT) wrap2$(EXEEXT) wrap3$(EXEEXT) \
- wrap4$(EXEEXT) wrap5$(EXEEXT) wrap6$(EXEEXT) wrap7$(EXEEXT) \
- wrap7so.so$(EXEEXT) wrap8$(EXEEXT) writev1$(EXEEXT) \
- $(am__EXEEXT_1)
+ realloc3$(EXEEXT) sbfragment$(EXEEXT) sendmsg$(EXEEXT) \
+ sh-mem$(EXEEXT) sh-mem-random$(EXEEXT) sigaltstack$(EXEEXT) \
+ signal2$(EXEEXT) sigprocmask$(EXEEXT) static_malloc$(EXEEXT) \
+ sigkill$(EXEEXT) stpncpy$(EXEEXT) strchr$(EXEEXT) \
+ str_tester$(EXEEXT) supp_unknown$(EXEEXT) supp1$(EXEEXT) \
+ supp2$(EXEEXT) suppfree$(EXEEXT) test-plo$(EXEEXT) \
+ trivialleak$(EXEEXT) unit_libcbase$(EXEEXT) unit_oset$(EXEEXT) \
+ varinfo1$(EXEEXT) varinfo2$(EXEEXT) varinfo3$(EXEEXT) \
+ varinfo4$(EXEEXT) varinfo5$(EXEEXT) varinfo5so.so$(EXEEXT) \
+ varinfo6$(EXEEXT) vcpu_fbench$(EXEEXT) vcpu_fnfns$(EXEEXT) \
+ wcs$(EXEEXT) xml1$(EXEEXT) wrap1$(EXEEXT) wrap2$(EXEEXT) \
+ wrap3$(EXEEXT) wrap4$(EXEEXT) wrap5$(EXEEXT) wrap6$(EXEEXT) \
+ wrap7$(EXEEXT) wrap7so.so$(EXEEXT) wrap8$(EXEEXT) \
+ writev1$(EXEEXT) $(am__EXEEXT_1)
@DWARF4_TRUE@am__append_12 = dw4
subdir = memcheck/tests
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@@ -434,6 +434,9 @@
sbfragment_SOURCES = sbfragment.c
sbfragment_OBJECTS = sbfragment.$(OBJEXT)
sbfragment_LDADD = $(LDADD)
+sendmsg_SOURCES = sendmsg.c
+sendmsg_OBJECTS = sendmsg.$(OBJEXT)
+sendmsg_LDADD = $(LDADD)
sh_mem_SOURCES = sh-mem.c
sh_mem_OBJECTS = sh-mem.$(OBJEXT)
sh_mem_LDADD = $(LDADD)
@@ -610,8 +613,8 @@
origin3-no.c origin4-many.c origin5-bz2.c origin6-fp.c \
overlap.c partial_load.c partiallydefinedeq.c pdb-realloc.c \
pdb-realloc2.c pipe.c pointer-trace.c post-syscall.c \
- realloc1.c realloc2.c realloc3.c sbfragment.c sh-mem.c \
- sh-mem-random.c sigaltstack.c sigkill.c signal2.c \
+ realloc1.c realloc2.c realloc3.c sbfragment.c sendmsg.c \
+ sh-mem.c sh-mem-random.c sigaltstack.c sigkill.c signal2.c \
sigprocmask.c static_malloc.c stpncpy.c str_tester.c strchr.c \
$(supp1_SOURCES) $(supp2_SOURCES) $(supp_unknown_SOURCES) \
suppfree.c test-plo.c trivialleak.c unit_libcbase.c \
@@ -641,8 +644,8 @@
origin3-no.c origin4-many.c origin5-bz2.c origin6-fp.c \
overlap.c partial_load.c partiallydefinedeq.c pdb-realloc.c \
pdb-realloc2.c pipe.c pointer-trace.c post-syscall.c \
- realloc1.c realloc2.c realloc3.c sbfragment.c sh-mem.c \
- sh-mem-random.c sigaltstack.c sigkill.c signal2.c \
+ realloc1.c realloc2.c realloc3.c sbfragment.c sendmsg.c \
+ sh-mem.c sh-mem-random.c sigaltstack.c sigkill.c signal2.c \
sigprocmask.c static_malloc.c stpncpy.c str_tester.c strchr.c \
$(supp1_SOURCES) $(supp2_SOURCES) $(supp_unknown_SOURCES) \
suppfree.c test-plo.c trivialleak.c unit_libcbase.c \
@@ -1112,6 +1115,7 @@
realloc2.stderr.exp realloc2.vgtest \
realloc3.stderr.exp realloc3.vgtest \
sbfragment.stdout.exp sbfragment.stderr.exp sbfragment.vgtest \
+ sendmsg.stderr.exp sendmsg.vgtest \
sh-mem.stderr.exp sh-mem.vgtest \
sh-mem-random.stderr.exp sh-mem-random.stdout.exp64 \
sh-mem-random.stdout.exp sh-mem-random.vgtest \
@@ -1560,6 +1564,9 @@
sbfragment$(EXEEXT): $(sbfragment_OBJECTS) $(sbfragment_DEPENDENCIES)
@rm -f sbfragment$(EXEEXT)
$(LINK) $(sbfragment_OBJECTS) $(sbfragment_LDADD) $(LIBS)
+sendmsg$(EXEEXT): $(sendmsg_OBJECTS) $(sendmsg_DEPENDENCIES)
+ @rm -f sendmsg$(EXEEXT)
+ $(LINK) $(sendmsg_OBJECTS) $(sendmsg_LDADD) $(LIBS)
sh-mem$(EXEEXT): $(sh_mem_OBJECTS) $(sh_mem_DEPENDENCIES)
@rm -f sh-mem$(EXEEXT)
$(LINK) $(sh_mem_OBJECTS) $(sh_mem_LDADD) $(LIBS)
@@ -1775,6 +1782,7 @@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/realloc2.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/realloc3.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sbfragment.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sendmsg.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sh-mem-random.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sh-mem.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sigaltstack.Po@am__quote@
--- a/coregrind/m_syswrap/syswrap-generic.c.orig 2013-02-28 15:14:08.035441439 +0100
+++ b/coregrind/m_syswrap/syswrap-generic.c 2013-02-28 15:18:13.035249059 +0100
@@ -848,7 +848,8 @@
Char *name,
struct vki_msghdr *msg,
UInt length,
- void (*foreach_func)( ThreadId, Bool, Char *, Addr, SizeT )
+ void (*foreach_func)( ThreadId, Bool, Char *, Addr, SizeT ),
+ Bool recv
)
{
Char *fieldName;
@@ -866,7 +867,11 @@
foreach_func ( tid, True, fieldName, (Addr)&msg->msg_iovlen, sizeof( msg->msg_iovlen ) );
foreach_func ( tid, True, fieldName, (Addr)&msg->msg_control, sizeof( msg->msg_control ) );
foreach_func ( tid, True, fieldName, (Addr)&msg->msg_controllen, sizeof( msg->msg_controllen ) );
- foreach_func ( tid, False, fieldName, (Addr)&msg->msg_flags, sizeof( msg->msg_flags ) );
+
+ /* msg_flags is completely ignored for send_mesg, recv_mesg doesn't read
+ the field, but does write to it. */
+ if ( recv )
+ foreach_func ( tid, False, fieldName, (Addr)&msg->msg_flags, sizeof( msg->msg_flags ) );
if ( msg->msg_name ) {
VG_(sprintf) ( fieldName, "(%s.msg_name)", name );
@@ -1509,7 +1514,7 @@
void
ML_(generic_PRE_sys_sendmsg) ( ThreadId tid, Char *name, struct vki_msghdr *msg )
{
- msghdr_foreachfield ( tid, name, msg, ~0, pre_mem_read_sendmsg );
+ msghdr_foreachfield ( tid, name, msg, ~0, pre_mem_read_sendmsg, False );
}
/* ------ */
@@ -1517,13 +1522,13 @@
void
ML_(generic_PRE_sys_recvmsg) ( ThreadId tid, Char *name, struct vki_msghdr *msg )
{
- msghdr_foreachfield ( tid, name, msg, ~0, pre_mem_write_recvmsg );
+ msghdr_foreachfield ( tid, name, msg, ~0, pre_mem_write_recvmsg, True );
}
void
ML_(generic_POST_sys_recvmsg) ( ThreadId tid, Char *name, struct vki_msghdr *msg, UInt length )
{
- msghdr_foreachfield( tid, name, msg, length, post_mem_write_recvmsg );
+ msghdr_foreachfield( tid, name, msg, length, post_mem_write_recvmsg, True );
check_cmsg_for_fds( tid, msg );
}
--- a/memcheck/tests/Makefile.am.orig 2013-02-28 15:14:08.220442048 +0100
+++ b/memcheck/tests/Makefile.am 2013-02-28 15:20:17.575659460 +0100
@@ -179,6 +179,7 @@
realloc2.stderr.exp realloc2.vgtest \
realloc3.stderr.exp realloc3.vgtest \
sbfragment.stdout.exp sbfragment.stderr.exp sbfragment.vgtest \
+ sendmsg.stderr.exp sendmsg.vgtest \
sh-mem.stderr.exp sh-mem.vgtest \
sh-mem-random.stderr.exp sh-mem-random.stdout.exp64 \
sh-mem-random.stdout.exp sh-mem-random.vgtest \
@@ -282,6 +283,7 @@
post-syscall \
realloc1 realloc2 realloc3 \
sbfragment \
+ sendmsg \
sh-mem sh-mem-random \
sigaltstack signal2 sigprocmask static_malloc sigkill \
stpncpy \