[apparmor] [PATCH v2 02/11] tests: Fix socket addr lengths in unix_socket/unix_socket_client

Steve Beattie steve at nxnw.org
Tue Sep 16 18:18:37 UTC 2014


On Mon, Sep 15, 2014 at 02:55:55PM -0500, Tyler Hicks wrote:
> Instead of using the entire sun_path buffer for abstract socket names,
> only use the exact length of the string that is specified on the command
> line. The nul-terminator is not included for abstract sockets.
> 
> The size of sun_path is modified to include the nul-terminator for
> pathname address types.
> 
> Signed-off-by: Tyler Hicks <tyhicks at canonical.com>
Acked-by: Steve Beattie <steve at nxnw.org>

Thanks.

> ---
>  tests/regression/apparmor/unix_socket.c        | 13 +++++++++++--
>  tests/regression/apparmor/unix_socket_client.c | 13 +++++++++++--
>  2 files changed, 22 insertions(+), 4 deletions(-)
> 
> diff --git a/tests/regression/apparmor/unix_socket.c b/tests/regression/apparmor/unix_socket.c
> index 3d86225..cd492e3 100644
> --- a/tests/regression/apparmor/unix_socket.c
> +++ b/tests/regression/apparmor/unix_socket.c
> @@ -107,11 +107,20 @@ int main (int argc, char *argv[])
>  	sun_path = argv[1];
>  	sun_path_len = strlen(sun_path);
>  	if (sun_path[0] == '@') {
> +		if (sun_path_len > sizeof(addr.sun_path)) {
> +			fprintf(stderr, "FAIL - socket addr too big\n");
> +			exit(1);
> +		}
>  		memcpy(addr.sun_path, sun_path, sun_path_len);
>  		addr.sun_path[0] = '\0';
> -		sun_path_len = sizeof(addr.sun_path);
>  	} else {
> -		memcpy(addr.sun_path, sun_path, sun_path_len + 1);
> +		/* include the nul terminator for pathname addr types */
> +		sun_path_len++;
> +		if (sun_path_len > sizeof(addr.sun_path)) {
> +			fprintf(stderr, "FAIL - socket addr too big\n");
> +			exit(1);
> +		}
> +		memcpy(addr.sun_path, sun_path, sun_path_len);
>  	}
>  
>  	if (!strcmp(argv[2], "stream")) {
> diff --git a/tests/regression/apparmor/unix_socket_client.c b/tests/regression/apparmor/unix_socket_client.c
> index ac53ecd..d7d5510 100644
> --- a/tests/regression/apparmor/unix_socket_client.c
> +++ b/tests/regression/apparmor/unix_socket_client.c
> @@ -98,11 +98,20 @@ int main(int argc, char *argv[])
>  	sun_path = argv[1];
>  	sun_path_len = strlen(sun_path);
>  	if (sun_path[0] == '@') {
> +		if (sun_path_len > sizeof(peer_addr.sun_path)) {
> +			fprintf(stderr, "FAIL CLIENT - socket addr too big\n");
> +			exit(1);
> +		}
>  		memcpy(peer_addr.sun_path, sun_path, sun_path_len);
>  		peer_addr.sun_path[0] = '\0';
> -		sun_path_len = sizeof(peer_addr.sun_path);
>  	} else {
> -		memcpy(peer_addr.sun_path, sun_path, sun_path_len + 1);
> +		/* include the nul terminator for pathname addr types */
> +		sun_path_len++;
> +		if (sun_path_len > sizeof(peer_addr.sun_path)) {
> +			fprintf(stderr, "FAIL CLIENT - socket addr too big\n");
> +			exit(1);
> +		}
> +		memcpy(peer_addr.sun_path, sun_path, sun_path_len);
>  	}
>  
>  	if (!strcmp(argv[2], "stream")) {

-- 
Steve Beattie
<sbeattie at ubuntu.com>
http://NxNW.org/~steve/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <https://lists.ubuntu.com/archives/apparmor/attachments/20140916/dfa7a804/attachment.pgp>


More information about the AppArmor mailing list