Skip to content

Commit 43e43ef

Browse files
Include trailing NUL in BIO_ADDR_rawaddress AF_UNIX length
1 parent 0993768 commit 43e43ef

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

crypto/bio/bio_addr.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,10 @@ int BIO_ADDR_rawaddress(const BIO_ADDR *ap, void *p, size_t *l) {
151151
return 0;
152152
}
153153
if (l != NULL) {
154-
*l = len;
154+
// AF_UNIX includes the trailing NUL written below so |*l| matches the
155+
// bytes written to |p| and reflects sockaddr_un's NUL-terminated path.
156+
// OpenSSL does not write this NUL; aws-lc intentionally does.
157+
*l = (ap->sa.sa_family == AF_UNIX) ? len + 1 : len;
155158
}
156159

157160
if (p != NULL) {

include/openssl/bio.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -776,9 +776,9 @@ OPENSSL_EXPORT int BIO_ADDR_family(const BIO_ADDR *ap);
776776
// The address data from |ap| is copied into the buffer |p| if |p| is not NULL.
777777
// If |l| is not NULL, |*l| will be updated with the size of the address data.
778778
// For AF_INET, this is the 4-byte IPv4 address; for AF_INET6, the 16-byte IPv6
779-
// address; for AF_UNIX, the socket path. With AF_UNIX addresses, the buffer |p|
780-
// must be large enough for both the path and a NUL terminator. The function will
781-
// write the terminator to the buffer, but the length stored in |*l| excludes it.
779+
// address; for AF_UNIX, the socket path followed by a NUL terminator. The
780+
// length stored in |*l| includes the NUL for AF_UNIX so that it matches the
781+
// number of bytes written to |p|.
782782
// Returns 1 on success, 0 if the address family is unsupported or |ap| is NULL.
783783
OPENSSL_EXPORT int BIO_ADDR_rawaddress(const BIO_ADDR *ap, void *p, size_t *l);
784784

0 commit comments

Comments
 (0)