[apparmor] [patch] fix load of binary cache files, v2

Seth Arnold seth.arnold at canonical.com
Tue May 6 21:05:53 UTC 2014


On Tue, May 06, 2014 at 01:07:53PM -0700, John Johansen wrote:
> +++ 2.9-test/parser/parser_interface.c
> @@ -634,52 +634,73 @@
>  	return NULL;
>  int sd_load_buffer(int option, char *buffer, int size)
>  {
>  	int fd = -1;
> +	int error = -ENOMEM, bsize;
>  	char *filename = NULL;
> +
> +	/* TODO: push backup into caller */
> +	if (!kernel_load)
> +		return 0;
>  
>  	switch (option) {
>  	case OPTION_ADD:
>  		if (asprintf(&filename, "%s/.load", subdomainbase) == -1)
> +			goto out;
>  		break;
>  	case OPTION_REPLACE:
>  		if (asprintf(&filename, "%s/.replace", subdomainbase) == -1)
> +			goto out;
>  		break;
>  	default:
> +		return -EINVAL;
>  	}
> [...]
>  	}
> +	close(fd);
> +
> +out:
>  	free(filename);
> +
>  	return error;
>  }

Most of this patch looked alright but in the event of an error return
from asprintf() the contents of &filename are undefined. We shouldn't
pass it to free() in the event of failure.

Thanks
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: Digital signature
URL: <https://lists.ubuntu.com/archives/apparmor/attachments/20140506/4e785cd7/attachment.pgp>


More information about the AppArmor mailing list