]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
Fix 64-bit Windows socket write error handling 855/head
authorGreg Hudson <ghudson@mit.edu>
Thu, 4 Oct 2018 22:10:48 +0000 (18:10 -0400)
committerGreg Hudson <ghudson@mit.edu>
Wed, 17 Oct 2018 16:38:22 +0000 (12:38 -0400)
Add casts to ensure that the result type of SOCKET_WRITEV() on Windows
can represent -1.  Otherwise it will be treated as 2^32-1 when cast to
ssize_t on 64-bit Windows, which can lead to crashes in
krb5_sendto_kdc().  Reported by Puran Chand.

ticket: 8746 (new)
tags: pullup
target_version: 1.13-next

src/include/port-sockets.h
src/lib/krb5/os/net_write.c

index b3ab9c906bb7bd6cb2d75bfca6f92c19aa68f807..f0fc2b804e0e3eaa3d3bd2fd8918d0b0d414d49f 100644 (file)
@@ -40,8 +40,9 @@ typedef WSABUF sg_buf;
  */
 /* WSASend returns 0 or SOCKET_ERROR.  */
 #define SOCKET_WRITEV_TEMP DWORD
-#define SOCKET_WRITEV(FD, SG, LEN, TMP)                         \
-    (WSASend((FD), (SG), (LEN), &(TMP), 0, 0, 0) ? -1 : (TMP))
+#define SOCKET_WRITEV(FD, SG, LEN, TMP)                 \
+    (WSASend((FD), (SG), (LEN), &(TMP), 0, 0, 0) ?      \
+     (ssize_t)-1 : (ssize_t)(TMP))
 
 #define SHUTDOWN_READ   SD_RECEIVE
 #define SHUTDOWN_WRITE  SD_SEND
index 929072653ea0de37e50fa7477741387ba2c2f5d8..cc8c309db7dc9d546570af404692b1ced5bc4340 100644 (file)
@@ -47,7 +47,7 @@ krb5_net_write(krb5_context context, int fd, const char *buf, int len)
 int
 krb5int_net_writev(krb5_context context, int fd, sg_buf *sgp, int nsg)
 {
-    int cc, len = 0;
+    ssize_t cc, len = 0;
     SOCKET_WRITEV_TEMP tmp;
 
     while (nsg > 0) {