Commit fc0e051a authored by Andrew Price's avatar Andrew Price
Browse files

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.
parent fbbe2ceb
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -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 != target) {
		if (ipc_parent != NULL) free(ipc_parent);
		ipc_parent = strdup(target);
	}
	ipc_user = user;

	ipcsock->fd = fd;