Index: ossp-pkg/sa/sa.c RCS File: /v/ossp/cvs/ossp-pkg/sa/sa.c,v rcsdiff -q -kk '-r1.31' '-r1.32' -u '/v/ossp/cvs/ossp-pkg/sa/sa.c,v' 2>/dev/null --- sa.c 2001/10/11 14:36:29 1.31 +++ sa.c 2001/10/11 15:12:19 1.32 @@ -585,13 +585,6 @@ /* import "struct sockaddr" into address object */ sa_rc_t sa_addr_s2a(sa_addr_t *saa, const struct sockaddr *sabuf, socklen_t salen) { - struct sockaddr_un *un; - struct sockaddr_in *sa4; -#ifdef AF_INET6 - struct sockaddr_in6 *sa6; -#endif - int sf; - /* argument sanity check(s) */ if (saa == NULL || sabuf == NULL || salen == 0) return SA_ERR_ARG; @@ -604,28 +597,8 @@ memcpy(saa->saBuf, sabuf, salen); saa->slBuf = salen; - /* resolve family */ - sf = 0; - if (sizeof(struct sockaddr_un) == salen) { - un = (struct sockaddr_un *)((void *)sabuf); - if (un->sun_family == AF_LOCAL) - sf = AF_LOCAL; - } - if (sf == 0 && sizeof(struct sockaddr_in) == salen) { - sa4 = (struct sockaddr_in *)((void *)sabuf); - if (sa4->sin_family == AF_INET) - sf = AF_INET; - } -#ifdef AF_INET6 - if (sf == 0 && sizeof(struct sockaddr_in6) == salen) { - sa6 = (struct sockaddr_in6 *)((void *)sabuf); - if (sa6->sin6_family == AF_INET6) - sf = AF_INET6; - } -#endif - if (sf == 0) - return SA_ERR_ARG; - saa->nFamily = sf; + /* remember family */ + saa->nFamily = sabuf->sa_family; return SA_OK; } @@ -649,7 +622,16 @@ /* export object contents */ if (saa->nFamily == AF_LOCAL) { un = (struct sockaddr_un *)((void *)saa->saBuf); - sa_msnprintf(uribuf, sizeof(uribuf), "unix:%s", un->sun_path); + if ( ( saa->slBuf >= (socklen_t)(&(((struct sockaddr_un *)0)->sun_path[0])) + && un->sun_path[0] == '\0') + || saa->slBuf < sizeof(struct sockaddr_un)) + /* in case the remote side of a Unix Domain socket was not + bound, a "struct sockaddr_un" can occur with a length less + than the expected one. Then there is actually no path at all. + This has been verified under FreeBSD, Linux and Solaris. */ + sa_msnprintf(uribuf, sizeof(uribuf), "unix:/NOT-BOUND"); + else + sa_msnprintf(uribuf, sizeof(uribuf), "unix:%s", un->sun_path); } #ifdef AF_INET6 else if (saa->nFamily == AF_INET || saa->nFamily == AF_INET6) { @@ -1510,6 +1492,7 @@ char c; size_t n; size_t res; + sa_rc_t rv; /* argument sanity check(s) */ if (sa == NULL || cpBuf == NULL || nBufReq == 0) @@ -1527,9 +1510,12 @@ buffers are enabled, this is not as stupid as it looks at the first hand and if buffers are disabled, there is no better solution anyway. */ + rv = SA_OK; res = 0; while (res < (nBufReq-1)) { - sa_read(sa, &c, 1, &n); + rv = sa_read(sa, &c, 1, &n); + if (rv != SA_OK) + break; if (n <= 0) break; cpBuf[res++] = c; @@ -1542,7 +1528,7 @@ if (nBufRes != NULL) *nBufRes = res; - return SA_OK; + return rv; } /* internal raw write operation */