[mw-devel] [Git][arthur/mw][master] Don't strdup a freed pointer in ipc_connect

Andrew Price welshbyte at sucs.org
Fri May 27 08:28:57 BST 2016


Andrew Price pushed to branch master at Justin Mitchell / mw


Commits:
fc0e051a by Andrew Price at 2016-05-27T08:22:34+01:00
Don't strdup a freed pointer in ipc_connect

When ipc_check() attempts to reconnect it passes ipc_parent as the
target to connect to. ipc_connect() then reconnects and frees ipc_parent
and sets it to strdup(target). When target is equal to ipc_parent this
means we're strduping a freed pointer and reconnecting a second time (or
using ipc_parent anywhere subsequently) will fail. Add a check to make
sure they're not pointing to the same thing.

- - - - -


1 changed file:

- src/ipc.c


Changes:

=====================================
src/ipc.c
=====================================
--- a/src/ipc.c
+++ b/src/ipc.c
@@ -58,8 +58,11 @@ int ipc_connect(const char *target, struct user *user)
 		fprintf(stderr, "Connection to server failed.\n");
 		return -1;
 	}
-	if (ipc_parent != NULL) free(ipc_parent);
-	ipc_parent = strdup(target);
+
+	if (ipc_parent != target) {
+		if (ipc_parent != NULL) free(ipc_parent);
+		ipc_parent = strdup(target);
+	}
 	ipc_user = user;
 
 	ipcsock->fd = fd;



View it on GitLab: https://projects.sucs.org/arthur/mw/commit/fc0e051a60d35ac0e9b55b18d39c9d60b9cd5ce6
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sucs.org/pipermail/mw-devel/attachments/20160527/eb4e0adb/attachment.html>


More information about the mw-devel mailing list