mirror of
https://github.com/0intro/libtask
synced 2024-11-24 14:49:57 +03:00
fix warnings reported by Coverity
fd.c:230 negative_returns: fd is passed to a parameter that cannot be negative. net.c:65 check_return: Calling setsockopt(fd, 1, 2, (char *)&n, 4U) without checking return value. net.c:77 check_return: Calling fdnoblock(fd) without checking return value. net.c:112 check_return: Calling fdnoblock(cfd) without checking return value. net.c:114 check_return: Calling setsockopt(cfd, IPPROTO_TCP, 1, (char *)&one, 4U) without checking return value. net.c:144 leaked_storage: Variable result going out of scope leaks the storage it points to. net.c:168 check_return: Calling fdnoblock(fd) without checking return value. net.c:173 check_return: Calling setsockopt(fd, 1, 6, &n, 4U) without checking return value. net.c:206 check_return: Calling getsockopt(fd, 1, 4, (void *)&n, &sn) without checking return value. task.c:59 negative_returns: fd is passed to a parameter that cannot be negative. tcpload.c:50 Calling fdread without checking return value (as is done elsewhere 4 out of 5 times). tcpproxy.c:51 check_return: Calling fdnoblock(fd) without checking return value.
This commit is contained in:
parent
728d616727
commit
798c8c6df8
5
echo.c
5
echo.c
@ -48,7 +48,10 @@ taskmain(int argc, char **argv)
|
||||
fprintf(stderr, "cannot announce on tcp port %d: %s\n", atoi(argv[1]), strerror(errno));
|
||||
taskexitall(1);
|
||||
}
|
||||
fdnoblock(fd);
|
||||
if(fdnoblock(fd) < 0){
|
||||
fprintf(stderr, "fdnoblock\n");
|
||||
taskexitall(1);
|
||||
}
|
||||
while((cfd = netaccept(fd, remote, &rport)) >= 0){
|
||||
if(verbose)
|
||||
fprintf(stderr, "connection from %s:%d\n", remote, rport);
|
||||
|
2
fd.c
2
fd.c
@ -220,6 +220,8 @@ fdwait(int fd, int rw)
|
||||
if(r < 0 || errno == EEXIST){
|
||||
duped = 1;
|
||||
fd = dup(fd);
|
||||
if(fd < 0)
|
||||
abort();
|
||||
r = epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &ev);
|
||||
if(r != 0)
|
||||
abort();
|
||||
|
37
net.c
37
net.c
@ -62,7 +62,10 @@ netannounce(int istcp, char *server, int port)
|
||||
sn = sizeof n;
|
||||
if(istcp && getsockopt(fd, SOL_SOCKET, SO_TYPE, (void*)&n, &sn) >= 0){
|
||||
n = 1;
|
||||
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char*)&n, sizeof n);
|
||||
if(setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char*)&n, sizeof n) < 0){
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if(bind(fd, (struct sockaddr*)&ss, sizeof ss) < 0){
|
||||
@ -74,7 +77,10 @@ netannounce(int istcp, char *server, int port)
|
||||
if(proto == SOCK_STREAM)
|
||||
listen(fd, 16);
|
||||
|
||||
fdnoblock(fd);
|
||||
if(fdnoblock(fd) < 0){
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
taskstate("netannounce succeeded");
|
||||
return fd;
|
||||
}
|
||||
@ -109,9 +115,15 @@ netaccept(int fd, char *server, int *port)
|
||||
*port = nhgets(&((struct sockaddr_in6*)&ss)->sin6_port);
|
||||
break;
|
||||
}
|
||||
fdnoblock(cfd);
|
||||
if(fdnoblock(cfd) < 0){
|
||||
close(cfd);
|
||||
return -1;
|
||||
}
|
||||
one = 1;
|
||||
setsockopt(cfd, IPPROTO_TCP, TCP_NODELAY, (char*)&one, sizeof one);
|
||||
if(setsockopt(cfd, IPPROTO_TCP, TCP_NODELAY, (char*)&one, sizeof one) < 0){
|
||||
close(cfd);
|
||||
return -1;
|
||||
}
|
||||
taskstate("netaccept succeeded");
|
||||
return cfd;
|
||||
}
|
||||
@ -136,10 +148,12 @@ netlookup(char *name, unsigned char *ip)
|
||||
break;
|
||||
}
|
||||
taskstate("netlookup succeeded");
|
||||
freeaddrinfo(result);
|
||||
return 0;
|
||||
}
|
||||
|
||||
taskstate("netlookup failed");
|
||||
freeaddrinfo(result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -160,12 +174,18 @@ netdial(int istcp, char *server, int port)
|
||||
taskstate("socket failed");
|
||||
return -1;
|
||||
}
|
||||
fdnoblock(fd);
|
||||
if(fdnoblock(fd) < 0){
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* for udp */
|
||||
if(!istcp){
|
||||
n = 1;
|
||||
setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &n, sizeof n);
|
||||
if(setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &n, sizeof n) < 0){
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* start connecting */
|
||||
@ -198,7 +218,10 @@ netdial(int istcp, char *server, int port)
|
||||
|
||||
/* report error */
|
||||
sn = sizeof n;
|
||||
getsockopt(fd, SOL_SOCKET, SO_ERROR, (void*)&n, &sn);
|
||||
if(getsockopt(fd, SOL_SOCKET, SO_ERROR, (void*)&n, &sn) < 0){
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
if(n == 0)
|
||||
n = ECONNREFUSED;
|
||||
close(fd);
|
||||
|
3
task.c
3
task.c
@ -46,7 +46,8 @@ taskdebug(char *fmt, ...)
|
||||
p = argv0;
|
||||
snprint(buf, sizeof buf, "/tmp/%s.tlog", p);
|
||||
if((fd = open(buf, O_CREAT|O_WRONLY, 0666)) < 0)
|
||||
fd = open("/dev/null", O_WRONLY);
|
||||
if((fd = open("/dev/null", O_WRONLY)) < 0)
|
||||
abort();
|
||||
}
|
||||
|
||||
va_start(arg, fmt);
|
||||
|
@ -47,7 +47,6 @@ fetchtask(void *v)
|
||||
}
|
||||
snprintf(buf, sizeof buf, "xxxxxxxxxx");
|
||||
fdwrite(fd, buf, strlen(buf));
|
||||
fdread(fd, buf, sizeof buf);
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
|
@ -51,7 +51,10 @@ taskmain(int argc, char **argv)
|
||||
fprintf(stderr, "cannot announce on tcp port %d: %s\n", atoi(argv[1]), strerror(errno));
|
||||
taskexitall(1);
|
||||
}
|
||||
fdnoblock(fd);
|
||||
if(fdnoblock(fd) < 0){
|
||||
fprintf(stderr, "fdnoblock\n");
|
||||
taskexitall(1);
|
||||
}
|
||||
while((cfd = netaccept(fd, remote, &rport)) >= 0){
|
||||
if(verbose)
|
||||
fprintf(stderr, "connection from %s:%d\n", remote, rport);
|
||||
|
Loading…
Reference in New Issue
Block a user