[vhffs-dev] [1609] obviously, setting on a field of a struct a pointer on the stack is a really... |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
Revision: 1609
Author: gradator
Date: 2010-06-02 00:32:02 +0200 (Wed, 02 Jun 2010)
Log Message:
-----------
obviously, setting on a field of a struct a pointer on the stack is a really... really bad idea, furthermore sockaddr_in should be cleared before using it, luckily the concerned content was only used in debug mode ;-)
Modified Paths:
--------------
trunk/vhffs-fssync/vhffsfssync_master.c
trunk/vhffs-fssync/vhffsfssync_slave.c
Modified: trunk/vhffs-fssync/vhffsfssync_master.c
===================================================================
--- trunk/vhffs-fssync/vhffsfssync_master.c 2010-05-28 08:31:03 UTC (rev 1608)
+++ trunk/vhffs-fssync/vhffsfssync_master.c 2010-06-01 22:32:02 UTC (rev 1609)
@@ -1806,6 +1806,7 @@
fprintf(stderr, "setsockopt() failed on socket %d: %s\n", listenfd, strerror(errno));
}
+ memset((char*)&src, 0, sizeof(src));
src.sin_addr.s_addr = bindaddr;
src.sin_family = AF_INET;
src.sin_port = htons(bindport);
@@ -1916,6 +1917,7 @@
//struct hostent *ent;
addr_len = sizeof(addr);
+ memset((char*)&addr, 0, addr_len);
newfd = accept(listenfd, (struct sockaddr*)&addr, &addr_len);
if(newfd <= 0) {
switch(errno) {
@@ -1941,7 +1943,7 @@
/* register the connection */
conn = malloc(sizeof(vhffsfssync_conn));
conn->fd = newfd;
- conn->sockaddr = addr;
+ memcpy((char*)&conn->sockaddr, (char*)&addr, addr_len);
conn->order = 0;
conn->recvbuf = NULL;
conn->recvbuf_begin = 0;
Modified: trunk/vhffs-fssync/vhffsfssync_slave.c
===================================================================
--- trunk/vhffs-fssync/vhffsfssync_slave.c 2010-05-28 08:31:03 UTC (rev 1608)
+++ trunk/vhffs-fssync/vhffsfssync_slave.c 2010-06-01 22:32:02 UTC (rev 1609)
@@ -1103,6 +1103,7 @@
signal(SIGPIPE, SIG_IGN);
conn = malloc(sizeof(vhffsfssync_conn));
conn->fd = -1;
+ memset((char*)&conn->sockaddr, 0, sizeof(conn->sockaddr));
conn->recvbuf = NULL;
conn->recvbuf_begin = 0;
conn->recvbuf_end = 0;
@@ -1152,6 +1153,7 @@
conn->limitrate_timeprev = vhffsfssync_time();
/* connect */
+ memset((char*)&conn->sockaddr, 0, sizeof(conn->sockaddr));
inet_aton(host, &conn->sockaddr.sin_addr);
conn->sockaddr.sin_family = AF_INET;
conn->sockaddr.sin_port = htons(port);