X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=unix%2Fuxagentc.c;h=5734a7b0ea62c9f545b3cdb70b357d2f4682d871;hb=f004bcca17a789356c32527a396b68b71a773db2;hp=b612f52f1411cab00c06e94dd3a759d8c7f49814;hpb=f6a208fbddaa2b8299441bf1d1a5571314c0f9c9;p=PuTTY.git diff --git a/unix/uxagentc.c b/unix/uxagentc.c index b612f52f..5734a7b0 100644 --- a/unix/uxagentc.c +++ b/unix/uxagentc.c @@ -8,21 +8,17 @@ #include #include #include +#include #include "putty.h" #include "misc.h" #include "tree234.h" #include "puttymem.h" -#define GET_32BIT(cp) \ - (((unsigned long)(unsigned char)(cp)[0] << 24) | \ - ((unsigned long)(unsigned char)(cp)[1] << 16) | \ - ((unsigned long)(unsigned char)(cp)[2] << 8) | \ - ((unsigned long)(unsigned char)(cp)[3])) - int agent_exists(void) { - if (getenv("SSH_AUTH_SOCK") != NULL) + const char *p = getenv("SSH_AUTH_SOCK"); + if (p && *p) return TRUE; return FALSE; } @@ -79,13 +75,12 @@ static int agent_select_result(int fd, int event) } conn->retlen += ret; if (conn->retsize == 4 && conn->retlen == 4) { - conn->retsize = GET_32BIT(conn->retbuf); + conn->retsize = toint(GET_32BIT(conn->retbuf) + 4); if (conn->retsize <= 0) { conn->retbuf = NULL; conn->retlen = 0; goto done; } - conn->retsize += 4; assert(conn->retbuf == conn->sizebuf); conn->retbuf = snewn(conn->retsize, char); memcpy(conn->retbuf, conn->sizebuf, 4); @@ -127,6 +122,8 @@ int agent_query(void *in, int inlen, void **out, int *outlen, exit(1); } + cloexec(sock); + addr.sun_family = AF_UNIX; strncpy(addr.sun_path, name, sizeof(addr.sun_path)); if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {