|
From: jody <jod...@gm...> - 2009-01-28 10:06:42
|
Hi
I have checked a TCP-server which i wrote with valgrind-3.4.0,
and encountered these errors:
==15611== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 17 from 1)
==15611==
==15611== 1 errors in context 1 of 2:
==15611== Syscall param socketcall.accept(addr) points to unaddressable byte(s)
==15611== at 0xA4BA01: accept (in /lib/libc-2.7.so)
==15611== by 0x98D38F: (below main) (in /lib/libc-2.7.so)
==15611== Address 0xbea43000 is not stack'd, malloc'd or (recently) free'd
==15611==
==15611== 1 errors in context 2 of 2:
==15611== Syscall param socketcall.accept(addrlen_in) points to
uninitialised byte(s)
==15611== at 0xA4BA01: accept (in /lib/libc-2.7.so)
==15611== by 0x98D38F: (below main) (in /lib/libc-2.7.so)
==15611== Address 0xbea4233c is on thread 1's stack
I simplified the server to the point where it only calls accept (see below),
and the errors still prevail.
I compile it with
g++ -g -Wall dummysrv.cpp -o dummysrv
(g++ (GCC) 4.1.2 20070925 (Red Hat 4.1.2-33))
What do these messages mean and how can i fix that?
The position "below main" is a little bit vague...
Thank You
Jody
Here's the code:
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
int main(int iArgC, char *apArgV[]) {
int iPort = 27667;
int iSock = socket(PF_INET, SOCK_STREAM, 0);
if (iSock >= 0) {
char sName[256];
gethostname(sName, 256);
struct hostent *phe = gethostbyname(sName);
struct sockaddr_in sa;
bzero((char *)&sa, sizeof(sa));
sa.sin_family = AF_INET;
sa.sin_port = htons(iPort); // port is short
sa.sin_addr.s_addr = htonl(INADDR_ANY);
printf("hostent addr %0x\n", (*(struct in_addr*) phe->h_addr).s_addr);
int iResult = bind(iSock, (struct sockaddr *)&sa, sizeof(sa));
struct sockaddr_in addrCli;
bzero(&addrCli, sizeof(struct sockaddr_in));
socklen_t slAddr;
if (iResult == 0) {
int iSockCli = accept(iSock,(struct sockaddr *) &addrCli, &slAddr);
if (iResult == 0) {
printf("accept ok\n");
} else {
printf("accept failed");
}
} else {
printf("bind error");
}
close(iSock);
}
}
|
|
From: Bart V. A. <bar...@gm...> - 2009-01-28 10:24:39
|
On Wed, Jan 28, 2009 at 11:06 AM, jody <jod...@gm...> wrote: > Hi > > I have checked a TCP-server which i wrote with valgrind-3.4.0, > and encountered these errors: > ==15611== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 17 from 1) > ==15611== > ==15611== 1 errors in context 1 of 2: > ==15611== Syscall param socketcall.accept(addr) points to unaddressable byte(s) > ==15611== at 0xA4BA01: accept (in /lib/libc-2.7.so) > ==15611== by 0x98D38F: (below main) (in /lib/libc-2.7.so) > ==15611== Address 0xbea43000 is not stack'd, malloc'd or (recently) free'd > ==15611== > ==15611== 1 errors in context 2 of 2: > ==15611== Syscall param socketcall.accept(addrlen_in) points to > uninitialised byte(s) > ==15611== at 0xA4BA01: accept (in /lib/libc-2.7.so) > ==15611== by 0x98D38F: (below main) (in /lib/libc-2.7.so) > ==15611== Address 0xbea4233c is on thread 1's stack > > > I simplified the server to the point where it only calls accept (see below), > and the errors still prevail. > I compile it with > g++ -g -Wall dummysrv.cpp -o dummysrv > (g++ (GCC) 4.1.2 20070925 (Red Hat 4.1.2-33)) > > What do these messages mean and how can i fix that? > The position "below main" is a little bit vague... I'm not sure this is the cause of the above message, but the call of accept() is not correct: the third argument of accept() is a value-result parameter, and should be initialized before passing it to accept(). Bart. |
|
From: Tom H. <to...@co...> - 2009-01-28 10:27:35
|
jody wrote: > I simplified the server to the point where it only calls accept (see below), > and the errors still prevail. > I compile it with > g++ -g -Wall dummysrv.cpp -o dummysrv > (g++ (GCC) 4.1.2 20070925 (Red Hat 4.1.2-33)) > > What do these messages mean and how can i fix that? > The position "below main" is a little bit vague... The problem is that you're not setting slAddr before you make the call to accept - you are supposed to set it to indicate how many bytes the addr argument points to. So valgrind is saying addrlen_in is uninitialised (correct) and then checking for an undefined number of bytes at addr being writable and find that some of them aren't. Tom -- Tom Hughes (to...@co...) http://www.compton.nu/ |
|
From: jody <jod...@gm...> - 2009-01-28 11:16:31
|
Thanks for the explanation - that fixed the issue! Jody On Wed, Jan 28, 2009 at 11:27 AM, Tom Hughes <to...@co...> wrote: > jody wrote: > >> I simplified the server to the point where it only calls accept (see >> below), >> and the errors still prevail. >> I compile it with >> g++ -g -Wall dummysrv.cpp -o dummysrv >> (g++ (GCC) 4.1.2 20070925 (Red Hat 4.1.2-33)) >> >> What do these messages mean and how can i fix that? >> The position "below main" is a little bit vague... > > The problem is that you're not setting slAddr before you make the call to > accept - you are supposed to set it to indicate how many bytes the addr > argument points to. > > So valgrind is saying addrlen_in is uninitialised (correct) and then > checking for an undefined number of bytes at addr being writable and find > that some of them aren't. > > Tom > > -- > Tom Hughes (to...@co...) > http://www.compton.nu/ > |
|
From: <ol...@gm...> - 2009-01-28 10:52:31
|
On Wed, 28 Jan 2009 11:06:37 +0100 jody <jod...@gm...> wrote: > Hi > > I have checked a TCP-server which i wrote with valgrind-3.4.0, > and encountered these errors: > ==15611== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 17 from 1) > ==15611== > ==15611== 1 errors in context 1 of 2: > ==15611== Syscall param socketcall.accept(addr) points to unaddressable byte(s) > ==15611== at 0xA4BA01: accept (in /lib/libc-2.7.so) > ==15611== by 0x98D38F: (below main) (in /lib/libc-2.7.so) > ==15611== Address 0xbea43000 is not stack'd, malloc'd or (recently) free'd > ==15611== > ==15611== 1 errors in context 2 of 2: > ==15611== Syscall param socketcall.accept(addrlen_in) points to > uninitialised byte(s) > ==15611== at 0xA4BA01: accept (in /lib/libc-2.7.so) > ==15611== by 0x98D38F: (below main) (in /lib/libc-2.7.so) > ==15611== Address 0xbea4233c is on thread 1's stack > > > I simplified the server to the point where it only calls accept (see below), > and the errors still prevail. > I compile it with > g++ -g -Wall dummysrv.cpp -o dummysrv > (g++ (GCC) 4.1.2 20070925 (Red Hat 4.1.2-33)) > > What do these messages mean and how can i fix that? > The position "below main" is a little bit vague... Try compiling with -O0 to switch off optimization; this sometimes helps to get better backtraces. Regards, Oliver |