From 71707a9074b3d3e6056473f334b7b61a097579ed Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20Kou=C5=99il?= Date: Thu, 4 May 2006 06:04:15 +0000 Subject: [PATCH] Merged fix for bug #16577 (connection hang in recv_token). --- .../project/version.properties | 2 +- org.glite.security.gsoap-plugin/src/glite_gss.c | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/org.glite.security.gsoap-plugin/project/version.properties b/org.glite.security.gsoap-plugin/project/version.properties index 99dbed2..80917e0 100644 --- a/org.glite.security.gsoap-plugin/project/version.properties +++ b/org.glite.security.gsoap-plugin/project/version.properties @@ -1,2 +1,2 @@ -module.version=1.3.0 +module.version=1.3.1 module.age=0 diff --git a/org.glite.security.gsoap-plugin/src/glite_gss.c b/org.glite.security.gsoap-plugin/src/glite_gss.c index 7f79063..02dc1bb 100644 --- a/org.glite.security.gsoap-plugin/src/glite_gss.c +++ b/org.glite.security.gsoap-plugin/src/glite_gss.c @@ -317,6 +317,12 @@ end: return ret; } +#define SSL_TOKEN_HEADER_LENGTH 5 +static size_t ssl_token_length(char *t, int tl) { + unsigned char *b = t; + return (((size_t)(b[3]) << 8) | b[4]) + 5; +} + static int recv_token(int sock, void **token, size_t *token_length, struct timeval *to) { @@ -325,6 +331,7 @@ recv_token(int sock, void **token, size_t *token_length, struct timeval *to) char *t = NULL; char *tmp; size_t tl = 0; + size_t expect = 0; fd_set fds; struct timeval timeout,before,after; int ret; @@ -335,6 +342,7 @@ recv_token(int sock, void **token, size_t *token_length, struct timeval *to) } ret = 0; + expect = SSL_TOKEN_HEADER_LENGTH; do { FD_ZERO(&fds); FD_SET(sock,&fds); @@ -349,7 +357,7 @@ recv_token(int sock, void **token, size_t *token_length, struct timeval *to) break; } - count = read(sock, buf, sizeof(buf)); + count = read(sock, buf, MIN(expect - tl, sizeof(buf))); if (count < 0) { if (errno == EINTR) continue; @@ -368,7 +376,13 @@ recv_token(int sock, void **token, size_t *token_length, struct timeval *to) t = tmp; memcpy(t + tl, buf, count); tl += count; - } while (count == sizeof(buf)); + + if ((expect == SSL_TOKEN_HEADER_LENGTH) && + (tl >= SSL_TOKEN_HEADER_LENGTH)) { + expect = ssl_token_length(t, tl); + } + + } while ((count == 0) || (tl < expect)); end: if (to) { -- 1.8.2.3