From 7b408d356094ab0ef0a07904a3ddf3832a8aa197 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Wed, 15 Nov 2017 15:43:24 +0100 Subject: Fix the nanosleep case of __assuan_usleep. * src/system-posix.c (__assuan_usleep): Handle full seconds. -- This function would have failed for any value >= 1000000 because the nsec field is limited to 999999999 and the function fails for larger values. Signed-off-by: Werner Koch --- src/assuan-socket.c | 5 +++++ src/system-posix.c | 5 ++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/assuan-socket.c b/src/assuan-socket.c index 6131e5b..147ec2a 100644 --- a/src/assuan-socket.c +++ b/src/assuan-socket.c @@ -745,6 +745,11 @@ socks5_connect (assuan_context_t ctx, assuan_fd_t sock, ret = _assuan_connect (ctx, HANDLE2SOCKET (sock), proxyaddr, proxyaddrlen); } + /* If we get an EINPROGRESS here the caller is trying to do a + * non-blocking connect (e.g. for custom time out handling) which + * fails here. The easiest fix would be to allow the client to tell + * us the timeout value and we do the timeout handling later on in the + * Socks protocol. */ if (ret) return ret; buffer[0] = 5; /* RFC-1928 VER field. */ diff --git a/src/system-posix.c b/src/system-posix.c index 52376da..65d2c8c 100644 --- a/src/system-posix.c +++ b/src/system-posix.c @@ -68,9 +68,8 @@ __assuan_usleep (assuan_context_t ctx, unsigned int usec) struct timespec req; struct timespec rem; - req.tv_sec = 0; - req.tv_nsec = usec * 1000; - + req.tv_sec = usecs / 1000000; + req.tv_nsec = (usecs % 1000000) * 1000; while (nanosleep (&req, &rem) < 0 && errno == EINTR) req = rem; } -- cgit v1.2.3