diff options
author | Linus Nordberg <linus@nordu.net> | 2016-09-21 12:53:31 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordu.net> | 2016-09-21 13:04:24 +0200 |
commit | e12e83b6f905fe6d27371921c36c5c3dad9e5379 (patch) | |
tree | 6360a09ea85ca4197d1677ff05d86d053cfbdf72 | |
parent | 5acfcb4c7ce94482660dedb710e0b1f2ab8e5578 (diff) |
Don't cast int to pointer and back. Portability.stompless-rebased
Thanks to Fabian Mauchle for pointing this out.
-rw-r--r-- | radsecproxy.c | 10 | ||||
-rw-r--r-- | tcp.c | 15 | ||||
-rw-r--r-- | tls.c | 17 | ||||
-rw-r--r-- | udp.c | 8 |
4 files changed, 35 insertions, 15 deletions
diff --git a/radsecproxy.c b/radsecproxy.c index d4b6578..1590e65 100644 --- a/radsecproxy.c +++ b/radsecproxy.c @@ -1990,7 +1990,7 @@ errexit: void createlistener(uint8_t type, char *arg) { pthread_t th; struct addrinfo *res; - int s = -1, on = 1; + int s = -1, on = 1, *sp = NULL; struct hostportres *hp = newhostport(arg, protodefs[type]->portdefault, 0); if (!hp || !resolvehostport(hp, AF_UNSPEC, protodefs[type]->socktype, 1)) @@ -2017,10 +2017,16 @@ void createlistener(uint8_t type, char *arg) { continue; } - if (pthread_create(&th, &pthread_attr, protodefs[type]->listener, (void *)s)) + sp = malloc(sizeof(int)); + if (!sp) + debugx(1, DBG_ERR, "malloc failed"); + *sp = s; + if (pthread_create(&th, &pthread_attr, protodefs[type]->listener, (void *)sp)) debugerrnox(errno, DBG_ERR, "pthread_create failed"); pthread_detach(th); } + if (!sp) + debugx(1, DBG_ERR, "createlistener: socket/bind failed"); debug(DBG_WARN, "createlistener: listening for %s on %s:%s", protodefs[type]->name, hp->host ? hp->host : "*", hp->port); freehostport(hp); @@ -317,6 +317,7 @@ void *tcpservernew(void *arg) { struct client *client; s = *(int *)arg; + free(arg); if (getpeername(s, (struct sockaddr *)&from, &fromlen)) { debug(DBG_DBG, "tcpservernew: getpeername failed, exiting"); goto exit; @@ -344,26 +345,32 @@ exit: void *tcplistener(void *arg) { pthread_t tcpserverth; - int s, listensock = (int) arg; + int s, *sp = (int *)arg, *s_arg = NULL; struct sockaddr_storage from; socklen_t fromlen = sizeof(from); - listen(listensock, 0); + listen(*sp, 0); for (;;) { - s = accept(listensock, (struct sockaddr *)&from, &fromlen); + s = accept(*sp, (struct sockaddr *)&from, &fromlen); if (s < 0) { debug(DBG_WARN, "accept failed"); continue; } - if (pthread_create(&tcpserverth, &pthread_attr, tcpservernew, (void *) s)) { + s_arg = malloc(sizeof(s)); + if (!s_arg) + debugx(1, DBG_ERR, "malloc failed"); + *s_arg = s; + if (pthread_create(&tcpserverth, &pthread_attr, tcpservernew, (void *) s_arg)) { debug(DBG_ERR, "tcplistener: pthread_create failed"); + free(s_arg); shutdown(s, SHUT_RDWR); close(s); continue; } pthread_detach(tcpserverth); } + free(sp); return NULL; } #else @@ -397,7 +397,8 @@ void *tlsservernew(void *arg) { struct client *client; struct tls *accepted_tls = NULL; - s = (int) arg; + s = *(int *)arg; + free(arg); if (getpeername(s, (struct sockaddr *)&from, &fromlen)) { debug(DBG_DBG, "tlsservernew: getpeername failed, exiting"); goto exit; @@ -458,26 +459,32 @@ exit: void *tlslistener(void *arg) { pthread_t tlsserverth; - int s, listensock = (int) arg; + int s, *sp = (int *)arg, *s_arg = NULL; struct sockaddr_storage from; socklen_t fromlen = sizeof(from); - listen(listensock, 0); + listen(*sp, 0); for (;;) { - s = accept(listensock, (struct sockaddr *)&from, &fromlen); + s = accept(*sp, (struct sockaddr *)&from, &fromlen); if (s < 0) { debug(DBG_WARN, "accept failed"); continue; } - if (pthread_create(&tlsserverth, &pthread_attr, tlsservernew, (void *) s)) { + s_arg = malloc(sizeof(s)); + if (!s_arg) + debugx(1, DBG_ERR, "malloc failed"); + *s_arg = s; + if (pthread_create(&tlsserverth, &pthread_attr, tlsservernew, (void *) s_arg)) { debug(DBG_ERR, "tlslistener: pthread_create failed"); + free(s_arg); shutdown(s, SHUT_RDWR); close(s); continue; } pthread_detach(tlsserverth); } + free(sp); return NULL; } #else @@ -258,11 +258,11 @@ int clientradputudp(struct server *server, unsigned char *rad) { void *udpclientrd(void *arg) { struct server *server; unsigned char *buf; - int s = (int) arg; + int *s = (int *)arg; for (;;) { server = NULL; - buf = radudpget(s, NULL, &server, NULL); + buf = radudpget(*s, NULL, &server, NULL); replyh(server, buf); } } @@ -348,10 +348,10 @@ void initextraudp() { } if (client4_sock >= 0) - if (pthread_create(&cl4th, &pthread_attr, udpclientrd, (void *) client4_sock)) + if (pthread_create(&cl4th, &pthread_attr, udpclientrd, (void *)&client4_sock)) debugx(1, DBG_ERR, "pthread_create failed"); if (client6_sock >= 0) - if (pthread_create(&cl6th, &pthread_attr, udpclientrd, (void *) client6_sock)) + if (pthread_create(&cl6th, &pthread_attr, udpclientrd, (void *)&client6_sock)) debugx(1, DBG_ERR, "pthread_create failed"); if (find_clconf_type(handle, NULL)) { |