Return immediately from get_sock_port if sock <0 so we don't call
authordtucker <dtucker@openbsd.org>
Fri, 31 Mar 2023 04:42:29 +0000 (04:42 +0000)
committerdtucker <dtucker@openbsd.org>
Fri, 31 Mar 2023 04:42:29 +0000 (04:42 +0000)
getsockname on a negative FD.  From Coverity CID 291840, ok djm@

usr.bin/ssh/canohost.c

index 3a73056..bb7ab4d 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: canohost.c,v 1.76 2023/03/03 05:00:34 djm Exp $ */
+/* $OpenBSD: canohost.c,v 1.77 2023/03/31 04:42:29 dtucker Exp $ */
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -129,6 +129,8 @@ get_sock_port(int sock, int local)
        char strport[NI_MAXSERV];
        int r;
 
+       if (sock < 0)
+               return -1;
        /* Get IP address of client. */
        fromlen = sizeof(from);
        memset(&from, 0, sizeof(from));