Skip to contentSkip to conversation

Libsepol Mac Build Errors

PATCH In review [email protected] 4 participants 9 messages Sep 23, 2016 – Sep 26, 2016 SELinux security module

lore
Share & tools
lore
#0 lore raw

The patches below fix some warnings reported by Josh Brindle on the libsepol build.

Josh can you test these and see if those three warning go away and give an ack if they are ok?

[PATCH 1/3] libsepol: fix unused variable 'size' on mac build [PATCH 2/3] libsepol: fix unused variable 'len' on mac build [PATCH 3/3] libsepol: fix unitialized variable 'nread' on mac build

#1 lore raw

PATCH 1/3 libsepol: fix unused variable 'size' on mac build

From: William Roberts <[email protected]>

Fix this on Mac build:
genbools.c:71:9: warning: unused variable 'size' [-Wunused-variable]

        size_t size = 0;
               ^
---
 libsepol/src/genbools.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libsepol/src/genbools.c +1 -1
index c81e848..c1f5405 100644
@@ -68,7 +68,6 @@ static int load_booleans(struct policydb *policydb, const char *path,
 {
 	FILE *boolf;
 	char *buffer = NULL;
-	size_t size = 0;
 	char localbools[BUFSIZ];
 	char name[BUFSIZ];
 	int val;
@@ -87,6 +86,7 @@ static int load_booleans(struct policydb *policydb, const char *path,
 
         while(fgets(buffer, 255, boolf) != NULL) {
 #else
+	size_t size = 0;
 	while (getline(&buffer, &size, boolf) > 0) {
 #endif
 		int ret = process_boolean(buffer, name, sizeof(name), &val);
Signature · 1 line
1.9.1
#2 lore raw

PATCH 2/3 libsepol: fix unused variable 'len' on mac build

In reply to [email protected]

From: William Roberts <[email protected]>

Fix this:
genusers.c:39:9: warning: unused variable 'len' [-Wunused-variable]

        size_t len = 0;
---
 libsepol/src/genusers.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libsepol/src/genusers.c +1 -1
index 0b98a76..57a9a2e 100644
@@ -36,7 +36,6 @@ static int load_users(struct policydb *policydb, const char *path)
 {
 	FILE *fp;
 	char *buffer = NULL, *p, *q, oldc;
-	size_t len = 0;
 	ssize_t nread;
 	unsigned lineno = 0, islist = 0, bit;
 	user_datum_t *usrdatum;
@@ -55,6 +54,7 @@ static int load_users(struct policydb *policydb, const char *path)
 
 	while(fgets(buffer, 255, fp) != NULL) {
 #else
+	size_t len = 0;
 	__fsetlocking(fp, FSETLOCKING_BYCALLER);
 	while ((nread = getline(&buffer, &len, fp)) > 0) {
 #endif
Signature · 1 line
1.9.1
#3 lore raw

PATCH 3/3 libsepol: fix unitialized variable 'nread' on mac build

In reply to [email protected]

From: William Roberts <[email protected]>

Fix this:
genusers.c:63:14: warning: variable 'nread' is uninitialized when used here [-Wuninitialized]

                if (buffer[nread - 1] == '\n')
                           ^~~~~
genusers.c:40:15: note: initialize the variable 'nread' to silence this warning
        ssize_t nread;
                     ^
                      = 0
---
 libsepol/src/genusers.c | 1 +
 1 file changed, 1 insertion(+)
libsepol/src/genusers.c +1 -0
index 57a9a2e..5568210 100644
@@ -53,6 +53,7 @@ static int load_users(struct policydb *policydb, const char *path)
 	}
 
 	while(fgets(buffer, 255, fp) != NULL) {
+		nread = strlen(buffer);
 #else
 	size_t len = 0;
 	__fsetlocking(fp, FSETLOCKING_BYCALLER);
Signature · 1 line
1.9.1
#5 lore raw
In reply to [email protected]
Quoted 9 lines · [email protected] wrote:

The patches below fix some warnings reported by Josh Brindle on the libsepol build.

Josh can you test these and see if those three warning go away and give an ack if they are ok?

[PATCH 1/3] libsepol: fix unused variable 'size' on mac build [PATCH 2/3] libsepol: fix unused variable 'len' on mac build [PATCH 3/3] libsepol: fix unitialized variable 'nread' on mac build

That fixed the build errors. The linker does not like the soname, version map, etc stuff though so I still don't get a sofile out.

#6 lore raw
Quoted 8 lines · Joshua Brindle
Quoted 7 lines · [email protected] wrote:

The patches below fix some warnings reported by Josh Brindle on the libsepol build.

Josh can you test these and see if those three warning go away and give an ack if they are ok?

Quoted 7 lines
Quoted 3 lines

[PATCH 1/3] libsepol: fix unused variable 'size' on mac build [PATCH 2/3] libsepol: fix unused variable 'len' on mac build [PATCH 3/3] libsepol: fix unitialized variable 'nread' on mac build

That fixed the build errors. The linker does not like the soname, version map, etc stuff though so I still don't get a sofile out.

FYI I managed to set up macincloud today, so I have an el capitain instance with 8 cores and 16GB ram I can use for testing. I'm currently syncing the source tree, so ill be able to test on mac.

#7 lore raw
Quoted 13 lines · William Roberts
Quoted 11 lines · Joshua Brindle
Quoted 9 lines · [email protected] wrote:

The patches below fix some warnings reported by Josh Brindle on the libsepol build.

Josh can you test these and see if those three warning go away and give an ack if they are ok?

[PATCH 1/3] libsepol: fix unused variable 'size' on mac build [PATCH 2/3] libsepol: fix unused variable 'len' on mac build [PATCH 3/3] libsepol: fix unitialized variable 'nread' on mac build

Quoted 6 lines
Quoted 2 lines

That fixed the build errors. The linker does not like the soname, version map, etc stuff though so I still don't get a sofile out.

FYI I managed to set up macincloud today, so I have an el capitain instance with 8 cores and 16GB ram I can use for testing. I'm currently syncing the source tree, so ill be able to test on mac.

Well that is neat.

FWIW I have an Android tree but I was building your selinux repo outside of Android. I personally keep around darwin libsepol.so files built out of Android for use with setools 4 since it works on Mac's now so I appreciate any work to make it work better on Mac :)

#8 lore raw
Quoted 28 lines · Joshua Brindle
Quoted 17 lines · William Roberts
Quoted 14 lines · Joshua Brindle
Quoted 10 lines · [email protected] wrote:

The patches below fix some warnings reported by Josh Brindle on the libsepol build.

Josh can you test these and see if those three warning go away and give an ack if they are ok?

[PATCH 1/3] libsepol: fix unused variable 'size' on mac build [PATCH 2/3] libsepol: fix unused variable 'len' on mac build [PATCH 3/3] libsepol: fix unitialized variable 'nread' on mac build

Quoted 8 lines
Quoted 2 lines

That fixed the build errors. The linker does not like the soname, version map, etc stuff though so I still don't get a sofile out.

FYI I managed to set up macincloud today, so I have an el capitain instance
with 8 cores and 16GB ram I can use for testing. I'm currently syncing the source tree, so ill be able to test on mac.

Quoted 6 lines

Well that is neat.

FWIW I have an Android tree but I was building your selinux repo outside of Android. I personally keep around darwin libsepol.so files built out of Android for use with setools 4 since it works on Mac's now so I appreciate any work to make it work better on Mac :)

I cant believe that code was actually working, nread was used uninitialized for accessing memory locations within an array.

#4 lore raw

Re: [PATCH 3/3] libsepol: fix unitialized variable 'nread' on mac build

In reply to [email protected]
Quoted 4 lines · On 09/23/2016 04:55 PM, [email protected] wrote:

From: William Roberts <[email protected]>

Fix this:
genusers.c:63:14: warning: variable 'nread' is uninitialized when used here [-Wuninitialized]

Quoted 8 lines
                if (buffer[nread - 1] == '\n')
                           ^~~~~
genusers.c:40:15: note: initialize the variable 'nread' to silence this warning
        ssize_t nread;
                     ^
                      = 0

Thanks, applied all 3 patches.
NB none of this code is actually used on the Mac or elsewhere in Android for that matter, and even on Linux, it is just legacy code (not used in modern distributions).

Quoted 17 lines
---
 libsepol/src/genusers.c | 1 +
 1 file changed, 1 insertion(+)
libsepol/src/genusers.c +1 -0
index 57a9a2e..5568210 100644
@@ -53,6 +53,7 @@ static int load_users(struct policydb *policydb, const char *path)
 	}
 
 	while(fgets(buffer, 255, fp) != NULL) {
+		nread = strlen(buffer);
 #else
 	size_t len = 0;
 	__fsetlocking(fp, FSETLOCKING_BYCALLER);