[mw-devel] [Git][arthur/mw][master] 2 commits: Address sanitizer fixups

Andrew Price welshbyte at sucs.org
Sun Aug 13 19:16:50 BST 2017


Andrew Price pushed to branch master at Justin Mitchell / mw


Commits:
5abdc979 by Andrew Price at 2017-08-13T18:48:15+01:00
Address sanitizer fixups

- - - - -
ec5ceec1 by Andrew Price at 2017-08-13T19:10:58+01:00
Tidy up the poller interfaces

Make them more generic, which means we can ditch a function

- - - - -


8 changed files:

- Makefile.common
- src/client/strings.c
- src/server/poll-epoll.c
- src/server/poll-kqueue.c
- src/server/poll.h
- src/server/replay.c
- src/server/servsock.c
- src/socket.c


Changes:

=====================================
Makefile.common
=====================================
--- a/Makefile.common
+++ b/Makefile.common
@@ -83,9 +83,10 @@ endif
 
 # Let the user add some flags at the end
 CFLAGS_APPEND =
+LDFLAGS_APPEND =
 
 CFLAGS = $(MWCFLAGS) $(CFLAGS_APPEND)
-LDFLAGS = $(MWLDFLAGS)
+LDFLAGS = $(MWLDFLAGS) $(LDFLAGS_APPEND)
 
 CODE=$(wildcard *.c)
 HDRS=$(wildcard *.h)


=====================================
src/client/strings.c
=====================================
--- a/src/client/strings.c
+++ b/src/client/strings.c
@@ -60,5 +60,5 @@ void pop_cmd(char *string, int len, int *type)
 		free(free_me);
 		if (cmd_stack == NULL) last_cmd = &cmd_stack;
 	}
-	string[len]=0;
+	string[len - 1] = '\0';
 }


=====================================
src/server/poll-epoll.c
=====================================
--- a/src/server/poll-epoll.c
+++ b/src/server/poll-epoll.c
@@ -1,7 +1,6 @@
 #include <sys/epoll.h>
 #include <string.h>
 
-#include <socket.h>
 #include "poll.h"
 
 struct epoll_priv {
@@ -12,15 +11,15 @@ struct epoll_priv ep = {
 	.pollfd = -1
 };
 
-int poll_addconn(ipc_connection_t *conn)
+int poll_addconn(int fd, void *data)
 {
 	struct epoll_event ev;
 	int ret;
 
 	memset(&ev, 0, sizeof(ev));
 	ev.events = EPOLLIN | EPOLLERR;
-	ev.data.ptr = conn;
-	ret = epoll_ctl(ep.pollfd, EPOLL_CTL_ADD, conn->fd, &ev);
+	ev.data.ptr = data;
+	ret = epoll_ctl(ep.pollfd, EPOLL_CTL_ADD, fd, &ev);
 	return ret;
 }
 
@@ -39,34 +38,25 @@ void poll_delete(int fd)
 	epoll_ctl(ep.pollfd, EPOLL_CTL_DEL, fd, &ev);
 }
 
-int poll_with_writes(ipc_connection_t *conn)
+int poll_with_writes(int fd, void *data)
 {
 	struct epoll_event ev;
 
 	memset(&ev, 0, sizeof(ev));
 	ev.events = EPOLLIN | EPOLLOUT | EPOLLERR;
-	ev.data.ptr = conn;
-	return epoll_ctl(ep.pollfd, EPOLL_CTL_MOD, conn->fd, &ev);
+	ev.data.ptr = data;
+	return epoll_ctl(ep.pollfd, EPOLL_CTL_MOD, fd, &ev);
 }
 
-int poll_without_writes(ipc_connection_t *conn)
+int poll_without_writes(int fd, void *data)
 {
+	int op = (data == NULL) ? EPOLL_CTL_ADD : EPOLL_CTL_MOD;
 	struct epoll_event ev;
 
 	memset(&ev, 0, sizeof(ev));
 	ev.events = EPOLLIN | EPOLLERR;
-	ev.data.ptr = conn;
-	return epoll_ctl(ep.pollfd, EPOLL_CTL_MOD, conn->fd, &ev);
-}
-
-int poll_fd_without_writes(int fd)
-{
-	struct epoll_event ev;
-
-	memset(&ev, 0, sizeof(ev));
-	ev.events = EPOLLIN | EPOLLERR;
-	ev.data.ptr = NULL;
-	return epoll_ctl(ep.pollfd, EPOLL_CTL_ADD, fd, &ev);
+	ev.data.ptr = data;
+	return epoll_ctl(ep.pollfd, op, fd, &ev);
 }
 
 int poll_wait(int timeout_millis, int (*callback)(poll_event_t *, int, void *), void *data)


=====================================
src/server/poll-kqueue.c
=====================================
--- a/src/server/poll-kqueue.c
+++ b/src/server/poll-kqueue.c
@@ -2,9 +2,9 @@
 #include <sys/event.h>
 #include <sys/time.h>
 #include <strings.h>
+#include <string.h>
 #include <errno.h>
 
-#include <socket.h>
 #include "poll.h"
 
 struct kq_priv {
@@ -15,11 +15,11 @@ struct kq_priv kp = {
 	.kqd = -1
 };
 
-int poll_addconn(ipc_connection_t *conn)
+int poll_addconn(int fd, void *data)
 {
 	struct kevent ev;
 
-	EV_SET(&ev, conn->fd, EVFILT_READ, EV_ADD, 0, 0, conn);
+	EV_SET(&ev, fd, EVFILT_READ, EV_ADD, 0, 0, data);
 	return kevent(kp.kqd, &ev, 1, NULL, 0, NULL);
 }
 
@@ -40,32 +40,20 @@ void poll_delete(int fd)
 	kevent(kp.kqd, &ev, 1, NULL, 0, NULL);
 }
 
-int poll_with_writes(ipc_connection_t *conn)
+int poll_with_writes(int fd, void *data)
 {
 	struct kevent ev;
 
-	EV_SET(&ev, conn->fd, EVFILT_WRITE, EV_ADD, 0, 0, conn);
+	EV_SET(&ev, fd, EVFILT_WRITE, EV_ADD, 0, 0, data);
 	return kevent(kp.kqd, &ev, 1, NULL, 0, NULL);
 }
 
-int poll_without_writes(ipc_connection_t *conn)
+int poll_without_writes(int fd, void *data)
 {
 	struct kevent ev;
 	int ret;
 
-	EV_SET(&ev, conn->fd, EVFILT_WRITE, EV_DELETE, 0, 0, NULL);
-	ret = kevent(kp.kqd, &ev, 1, NULL, 0, NULL);
-	if (ret != 0 && errno != ENOENT)
-		return ret;
-	return 0;
-}
-
-int poll_fd_without_writes(int fd)
-{
-	struct kevent ev;
-	int ret;
-
-	EV_SET(&ev, fd, EVFILT_READ, EV_ADD, 0, 0, NULL);
+	EV_SET(&ev, fd, EVFILT_READ, EV_ADD, 0, 0, data);
 	ret = kevent(kp.kqd, &ev, 1, NULL, 0, NULL);
 	if (ret != 0)
 		return ret;


=====================================
src/server/poll.h
=====================================
--- a/src/server/poll.h
+++ b/src/server/poll.h
@@ -8,12 +8,11 @@ typedef struct {
 	void *data;
 } poll_event_t;
 
-extern int poll_addconn(ipc_connection_t *conn);
+extern int poll_addconn(int fd, void *data);
 extern int poll_init(void);
 extern void poll_delete(int fd);
-extern int poll_with_writes(ipc_connection_t *conn);
-extern int poll_without_writes(ipc_connection_t *conn);
-extern int poll_fd_without_writes(int fd);
+extern int poll_with_writes(int fd, void *data);
+extern int poll_without_writes(int fd, void *data);
 extern int poll_wait(int timeout_millis, int (*callback)(poll_event_t *events, int nmemb, void *data), void *data);
 
 #endif /* SERVER_POLL_H */


=====================================
src/server/replay.c
=====================================
--- a/src/server/replay.c
+++ b/src/server/replay.c
@@ -4,6 +4,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/socket.h>
+#include <sys/uio.h>
 #include <netinet/in.h>
 #include <string.h>
 #include <errno.h>


=====================================
src/server/servsock.c
=====================================
--- a/src/server/servsock.c
+++ b/src/server/servsock.c
@@ -82,7 +82,7 @@ ipc_connection_t * add_connection(int fd)
 	list_add_tail(&(new->list), &connection_list);
 
 	/* register interest in read events */
-	if (poll_addconn(new)) {
+	if (poll_addconn(new->fd, new)) {
 		fprintf(stderr, "Error adding new conn to poll: %s\n", strerror(errno));
 	}
 
@@ -176,9 +176,8 @@ static int mainsock_event_cb(poll_event_t *events, int nmemb, void *data)
 			/* connections that went bad */
 			if (c->fd != -1 && c->state == IPCSTATE_ERROR) {
 				drop_connection(c);
-			}
+			} else if (c->state == IPCSTATE_PURGE && list_empty(&(c->outq))) {
 			/* connections with a soft close */
-			if (c->state == IPCSTATE_PURGE && list_empty(&(c->outq))) {
 				drop_connection(c);
 			}
 		}
@@ -192,7 +191,7 @@ void watch_mainsock(int mainsock)
 	struct timeval last;
 	gettimeofday(&last, NULL);
 
-	if (poll_fd_without_writes(mainsock)) {
+	if (poll_without_writes(mainsock, NULL)) {
 		fprintf(stderr, "Error adding mainsock: %s\n", strerror(errno));
 		return;
 	}
@@ -214,7 +213,7 @@ void write_socket(ipc_connection_t * conn)
 
 	if (list_empty(&conn->outq)) {
 		/* tx queue is empty, stop write events */
-		if (poll_without_writes(conn))
+		if (poll_without_writes(conn->fd, conn))
 			fprintf(stderr, "Error updating poll fd=%d: %s\n",
 			        conn->fd, strerror(errno));
 		return;
@@ -612,7 +611,7 @@ void msg_attach(ipc_message_t *msg, ipc_connection_t *conn)
 
 	/* nothing was queueed, switch on write notifications */
 	if (wasempty)
-		poll_with_writes(conn);
+		poll_with_writes(conn->fd, conn);
 }
 
 /* test if the user is gagged and apply the filter


=====================================
src/socket.c
=====================================
--- a/src/socket.c
+++ b/src/socket.c
@@ -134,7 +134,7 @@ int ipcconn_connect(const char * target)
 	struct addrinfo *list;
 	int fd;
 
-	char *host = alloca(strlen(target));
+	char *host = alloca(strlen(target) + 1);
 	char *port = NULL;
 	strcpy(host, target);
 



View it on GitLab: https://projects.sucs.org/arthur/mw/compare/e87def53766805048374a2a346ee1b6c566251cb...ec5ceec1e83faa63076cc0371405947391945482

---
View it on GitLab: https://projects.sucs.org/arthur/mw/compare/e87def53766805048374a2a346ee1b6c566251cb...ec5ceec1e83faa63076cc0371405947391945482
You're receiving this email because of your account on projects.sucs.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sucs.org/pipermail/mw-devel/attachments/20170813/a5346e85/attachment-0001.html>


More information about the mw-devel mailing list