From f5bec0484b649e1114bdfa915d81cac9f2eca921 Mon Sep 17 00:00:00 2001 From: Greg Hudson Date: Thu, 4 Oct 2018 18:10:48 -0400 Subject: Fix 64-bit Windows socket write error handling 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. (cherry picked from commit d98c3238894986765631f1e556f29ca817988816) ticket: 8746 version_fixed: 1.13.8 --- src/include/port-sockets.h | 5 +++-- src/lib/krb5/os/net_write.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/include/port-sockets.h b/src/include/port-sockets.h index b3ab9c9..f0fc2b8 100644 --- a/src/include/port-sockets.h +++ b/src/include/port-sockets.h @@ -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 diff --git a/src/lib/krb5/os/net_write.c b/src/lib/krb5/os/net_write.c index 9290726..cc8c309 100644 --- a/src/lib/krb5/os/net_write.c +++ b/src/lib/krb5/os/net_write.c @@ -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) { -- cgit v1.1