x_t automatically. + */ + pathmax = sizeof(tok->tt.sockunix.path); + remaining = (size_t)(len - (int)tok->len); + search = remaining < pathmax ? remaining : pathmax; + p = (u_char *)memchr((const void *)(buf + tok->len), '\0', search); + slen = (p ? (int)(p - (buf + tok->len)) + 1 : (int)search); READ_TOKEN_BYTES(buf, len, tok->tt.sockunix.path, slen, tok->len, err); if (err) return (-1); + /* guarantee NUL termination when no NUL was found in the token data */ + tok->tt.sockunix.path[pathmax - 1] = '\0'; return (0); } @@ -3278,7 +3316,7 @@ fetch_socket_tok(tokenstr_t *tok, u_char *buf, int len) if (err) return (-1); - READ_TOKEN_BYTES(buf, len, &tok->tt.socket.l_addr, + READ_TOKEN_BYTES(buf, len, &tok->tt.socket.r_addr, sizeof(tok->tt.socket.r_addr), tok->len, err); if (err) return (-1); diff --git a/contrib/openbsm/libbsm/bsm_token.c b/contrib/openbsm/libbsm/bsm_token.c index 682836f43870..8f55945cb33b 100644 --- a/contrib/openbsm/libbsm/bsm_token.c +++ b/contrib/openbsm/libbsm/bsm_token.c @@ -1051,7 +1051,7 @@ au_to_socket_ex(u_short so_domain, u_short so_type, /* * token ID 1 byte * socket family 2 bytes - * path (up to) 104 bytes + NULL (NULL terminated string) + * path (up to) AU_UNIX_PATH_MAX bytes (NUL terminated) */ token_t * au_to_sock_unix(struct sockaddr_un *so)