]> git.meshlink.io Git - meshlink/blobdiff - src/utcp.c
Don't crash when trying to connect a channel to port 0.
[meshlink] / src / utcp.c
index d2a929bf734a598b51ff8d2dd309b08c3383516c..ec74923dd128a85c4b730fefa015127e40a40c8a 100644 (file)
@@ -423,7 +423,6 @@ static int compare(const void *va, const void *vb) {
        const struct utcp_connection *b = *(struct utcp_connection **)vb;
 
        assert(a && b);
-       assert(a->src && b->src);
 
        int c = (int)a->src - (int)b->src;
 
@@ -2052,6 +2051,11 @@ void utcp_abort_all_connections(struct utcp *utcp) {
 }
 
 int utcp_close(struct utcp_connection *c) {
+       if(c->rcvbuf.used) {
+               fprintf(stderr, "UTCP channel closed with stuff in receive buffer\n");
+               return reset_connection(c) ? 0 : -1;
+       }
+
        if(utcp_shutdown(c, SHUT_RDWR) && errno != ENOTCONN) {
                return -1;
        }