diff mbox

[1/1] policycoreutils: semodule_package: do not fail with an empty fc file

Message ID 20161030212722.24743-1-nicolas.iooss@m4x.org (mailing list archive)
State Not Applicable
Headers show

Commit Message

Nicolas Iooss Oct. 30, 2016, 9:27 p.m. UTC
When running sepolgen tests on a Linux 4.7 kernel, one test fails with
the following message:

    /usr/bin/semodule_package:  Failed to mmap
    tmp/module_compile_test.mod.fc:  Invalid argument

The .fc file is empty, which is why it cannot be used with mmap().
Anyway the current code supports empty files (with if() conditions in
main()) so do not try to mmap an empty file in file_to_data().

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
---

While at it, it seems that neither seusersdata nor user_extradata are
unmapped at the end of main(). As this does not cause a test to fail
I will not send a patch to fix this.

 policycoreutils/semodule_package/semodule_package.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

William Roberts Oct. 30, 2016, 9:35 p.m. UTC | #1
Ack on this, I've had similar issues in Android that I patched up in the
Android specific tooling.

On Oct 30, 2016 14:28, "Nicolas Iooss" <nicolas.iooss@m4x.org> wrote:

> When running sepolgen tests on a Linux 4.7 kernel, one test fails with
> the following message:
>
>     /usr/bin/semodule_package:  Failed to mmap
>     tmp/module_compile_test.mod.fc:  Invalid argument
>
> The .fc file is empty, which is why it cannot be used with mmap().
> Anyway the current code supports empty files (with if() conditions in
> main()) so do not try to mmap an empty file in file_to_data().
>
> Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
> ---
>
> While at it, it seems that neither seusersdata nor user_extradata are
> unmapped at the end of main(). As this does not cause a test to fail
> I will not send a patch to fix this.
>
>  policycoreutils/semodule_package/semodule_package.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/policycoreutils/semodule_package/semodule_package.c
> b/policycoreutils/semodule_package/semodule_package.c
> index d2a5fd07bd71..e472054826a3 100644
> --- a/policycoreutils/semodule_package/semodule_package.c
> +++ b/policycoreutils/semodule_package/semodule_package.c
> @@ -72,6 +72,10 @@ static int file_to_data(const char *path, char **data,
> size_t * len)
>                         path, strerror(errno));
>                 goto err;
>         }
> +       if (!sb.st_size) {
> +               *len = 0;
> +               return 0;
> +       }
>
>         *data = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
>         if (*data == MAP_FAILED) {
> --
> 2.10.1
>
> _______________________________________________
> Selinux mailing list
> Selinux@tycho.nsa.gov
> To unsubscribe, send email to Selinux-leave@tycho.nsa.gov.
> To get help, send an email containing "help" to
> Selinux-request@tycho.nsa.gov.
>
Stephen Smalley Oct. 31, 2016, 4:52 p.m. UTC | #2
On 10/30/2016 05:27 PM, Nicolas Iooss wrote:
> When running sepolgen tests on a Linux 4.7 kernel, one test fails with
> the following message:
> 
>     /usr/bin/semodule_package:  Failed to mmap
>     tmp/module_compile_test.mod.fc:  Invalid argument
> 
> The .fc file is empty, which is why it cannot be used with mmap().
> Anyway the current code supports empty files (with if() conditions in
> main()) so do not try to mmap an empty file in file_to_data().

Thanks, applied.

> 
> Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
> ---
> 
> While at it, it seems that neither seusersdata nor user_extradata are
> unmapped at the end of main(). As this does not cause a test to fail
> I will not send a patch to fix this.
> 
>  policycoreutils/semodule_package/semodule_package.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/policycoreutils/semodule_package/semodule_package.c b/policycoreutils/semodule_package/semodule_package.c
> index d2a5fd07bd71..e472054826a3 100644
> --- a/policycoreutils/semodule_package/semodule_package.c
> +++ b/policycoreutils/semodule_package/semodule_package.c
> @@ -72,6 +72,10 @@ static int file_to_data(const char *path, char **data, size_t * len)
>  			path, strerror(errno));
>  		goto err;
>  	}
> +	if (!sb.st_size) {
> +		*len = 0;
> +		return 0;
> +	}
>  
>  	*data = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
>  	if (*data == MAP_FAILED) {
>
diff mbox

Patch

diff --git a/policycoreutils/semodule_package/semodule_package.c b/policycoreutils/semodule_package/semodule_package.c
index d2a5fd07bd71..e472054826a3 100644
--- a/policycoreutils/semodule_package/semodule_package.c
+++ b/policycoreutils/semodule_package/semodule_package.c
@@ -72,6 +72,10 @@  static int file_to_data(const char *path, char **data, size_t * len)
 			path, strerror(errno));
 		goto err;
 	}
+	if (!sb.st_size) {
+		*len = 0;
+		return 0;
+	}
 
 	*data = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
 	if (*data == MAP_FAILED) {