Skip to contentSkip to conversation

libsemanage patch

PATCH Daniel J Walsh 3 participants 7 messages Dec 3, 2007 – Dec 5, 2007 SELinux security module

lore
Share & tools
lore
#0 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

genhomedircon includes the "\n" in /etc/shells so no shells in the /etc/passwd match.

Rawhide Policy includes policy without a user_context_tpl

swig causes a doublefree if I don't allocate memory when specifying a alternate store.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iD8DBQFHVFmZrlYvE4MpobMRArfoAJ460UxLWEFjgmQx6CewOcTSGxivywCdGcGL GDS/6bPpBJRQfiVlOwWPvBI=
=cvuG
-----END PGP SIGNATURE-----

src/genhomedircon.c +13 -10
diff --exclude-from=exclude -N -u -r nsalibsemanage/src/genhomedircon.c libsemanage-2.0.14/src/genhomedircon.c
@@ -135,6 +135,7 @@
 	if (!shells)
 		return default_shell_list();
 	while (getline(&temp, &buff_len, shells) >= 0) {
+		temp[strlen(temp)-1]=0;
 		if (strcmp(temp, PATH_NOLOGIN_SHELL)) {
 			if (semanage_list_push(&list, temp)) {
 				free(temp);
@@ -790,7 +791,7 @@
 	homedir_context_tpl = make_template(s, &HOME_DIR_PRED);
 	homeroot_context_tpl = make_template(s, &HOME_ROOT_PRED);
 	user_context_tpl = make_template(s, &USER_CONTEXT_PRED);
-	if (!homedir_context_tpl || !homeroot_context_tpl || !user_context_tpl) {
+	if (!homedir_context_tpl || !homeroot_context_tpl) {
 		retval = STATUS_ERR;
 		goto done;
 	}
@@ -828,16 +829,18 @@
 
 		ustr_sc_free(&temp);
 	}
-	if (write_user_context(s, out, user_context_tpl,
-			       ".*", s->fallback_user,
-			       s->fallback_user_prefix) != STATUS_SUCCESS) {
-		retval = STATUS_ERR;
-		goto done;
-	}
+	if (user_context_tpl) {
+		if (write_user_context(s, out, user_context_tpl,
+				       ".*", s->fallback_user,
+				       s->fallback_user_prefix) != STATUS_SUCCESS) {
+			retval = STATUS_ERR;
+			goto done;
+		}
 
-	if (write_gen_home_dir_context(s, out, user_context_tpl,
-				       homedir_context_tpl) != STATUS_SUCCESS) {
-		retval = STATUS_ERR;
+		if (write_gen_home_dir_context(s, out, user_context_tpl,
+					       homedir_context_tpl) != STATUS_SUCCESS) {
+			retval = STATUS_ERR;
+		}
 	}
 
       done:
src/handle.c +2 -1
diff --exclude-from=exclude -N -u -r nsalibsemanage/src/handle.c libsemanage-2.0.14/src/handle.c
@@ -27,6 +27,7 @@
 #include <assert.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <string.h>
 #include <sys/time.h>
 
 #include "direct_api.h"
@@ -131,7 +132,7 @@
 
 	/* This just sets the storename to what the user requests, no 
 	   verification of existance will be done until connect */
-	sh->conf->store_path = storename;
+	sh->conf->store_path = strdup(storename);
 	sh->conf->store_type = storetype;
 
 	return;
#1 lore raw
Quoted 5 lines · Daniel J Walsh

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

genhomedircon includes the "\n" in /etc/shells so no shells in the /etc/passwd match.

Isn't this going to cause problems if the last line in /etc/shells has no newline?

Instead of:

    temp[strlen(temp)-1]=0;

I would use:

    temp[strcspn(temp, "\n")] = '\0';

That will overwrite the first newline with a NUL or, if there is no newline, the terminating NUL will be overwritten with another NUL, which is harmless. It is a useful idiom...

- todd

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#2 lore raw
Quoted 11 lines · Todd Miller
Quoted 5 lines · Daniel J Walsh

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

genhomedircon includes the "\n" in /etc/shells so no shells in the /etc/passwd match.

Isn't this going to cause problems if the last line in /etc/shells has no newline?

Instead of:

Quoted 8 lines
    temp[strlen(temp)-1]=0;

I would use:

    temp[strcspn(temp, "\n")] = '\0';

That will overwrite the first newline with a NUL or, if there is no newline, the terminating NUL will be overwritten with another NUL, which is harmless. It is a useful idiom...

Given that getline() returns the length read (not to be confused with the buffer length), why not just:

	while ((len = getline(&temp, &buff_len, shells)) > 0) {
		if (temp[len-1] == '\n') temp[len-1] = 0;
Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#3 lore raw
Quoted 4 lines · Stephen Smalley

Given that getline() returns the length read (not to be confused with the buffer length), why not just:

	while ((len = getline(&temp, &buff_len, shells)) > 0) {
		if (temp[len-1] == '\n') temp[len-1] = 0;

That is probably the simplest fix.

- todd

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#4 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 9 lines · Todd Miller
Quoted 4 lines · Stephen Smalley

Given that getline() returns the length read (not to be confused with the buffer length), why not just:

	while ((len = getline(&temp, &buff_len, shells)) > 0) {
		if (temp[len-1] == '\n') temp[len-1] = 0;

That is probably the simplest fix.

- todd

Fine with me, Do you want another patch.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iD8DBQFHVGJJrlYvE4MpobMRApYvAJ9IVdhR+SwUqZVdaTSayldB0LwQoACgyK4y JovC/Zp6veX/jbP2m+qPbv0=
=5Azc
-----END PGP SIGNATURE-----

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#5 lore raw
In reply to Stephen Smalley

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 16 lines · Stephen Smalley
Quoted 15 lines · Todd Miller
Quoted 5 lines · Daniel J Walsh

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

genhomedircon includes the "\n" in /etc/shells so no shells in the /etc/passwd match.

Isn't this going to cause problems if the last line in /etc/shells has no newline?

Instead of:

    temp[strlen(temp)-1]=0;

I would use:

    temp[strcspn(temp, "\n")] = '\0';
Quoted 9 lines
Quoted 3 lines

That will overwrite the first newline with a NUL or, if there is no newline, the terminating NUL will be overwritten with another NUL, which is harmless. It is a useful idiom...

Given that getline() returns the length read (not to be confused with the buffer length), why not just:

	while ((len = getline(&temp, &buff_len, shells)) > 0) {
		if (temp[len-1] == '\n') temp[len-1] = 0;

Second try.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iD8DBQFHVGvnrlYvE4MpobMRAhxfAJ4vuvC1uijEUDqFdj8Ju+cTJQIqoQCeMVqP 086ZRyvnHu9fsF7V8hLeEyI=
=jyGo
-----END PGP SIGNATURE-----

src/genhomedircon.c +15 -11
diff --exclude-from=exclude -N -u -r nsalibsemanage/src/genhomedircon.c libsemanage-2.0.14/src/genhomedircon.c
@@ -130,11 +130,13 @@
 	char *temp = NULL;
 	semanage_list_t *list = NULL;
 	size_t buff_len = 0;
+	int len;
 
 	shells = fopen(PATH_SHELLS_FILE, "r");
 	if (!shells)
 		return default_shell_list();
-	while (getline(&temp, &buff_len, shells) >= 0) {
+	while ((len = getline(&temp, &buff_len, shells)) > 0) {
+		if (temp[len-1] == '\n') temp[len-1] = 0;
 		if (strcmp(temp, PATH_NOLOGIN_SHELL)) {
 			if (semanage_list_push(&list, temp)) {
 				free(temp);
@@ -790,7 +792,7 @@
 	homedir_context_tpl = make_template(s, &HOME_DIR_PRED);
 	homeroot_context_tpl = make_template(s, &HOME_ROOT_PRED);
 	user_context_tpl = make_template(s, &USER_CONTEXT_PRED);
-	if (!homedir_context_tpl || !homeroot_context_tpl || !user_context_tpl) {
+	if (!homedir_context_tpl || !homeroot_context_tpl) {
 		retval = STATUS_ERR;
 		goto done;
 	}
@@ -828,16 +830,18 @@
 
 		ustr_sc_free(&temp);
 	}
-	if (write_user_context(s, out, user_context_tpl,
-			       ".*", s->fallback_user,
-			       s->fallback_user_prefix) != STATUS_SUCCESS) {
-		retval = STATUS_ERR;
-		goto done;
-	}
+	if (user_context_tpl) {
+		if (write_user_context(s, out, user_context_tpl,
+				       ".*", s->fallback_user,
+				       s->fallback_user_prefix) != STATUS_SUCCESS) {
+			retval = STATUS_ERR;
+			goto done;
+		}
 
-	if (write_gen_home_dir_context(s, out, user_context_tpl,
-				       homedir_context_tpl) != STATUS_SUCCESS) {
-		retval = STATUS_ERR;
+		if (write_gen_home_dir_context(s, out, user_context_tpl,
+					       homedir_context_tpl) != STATUS_SUCCESS) {
+			retval = STATUS_ERR;
+		}
 	}
 
       done:
src/handle.c +2 -1
diff --exclude-from=exclude -N -u -r nsalibsemanage/src/handle.c libsemanage-2.0.14/src/handle.c
@@ -27,6 +27,7 @@
 #include <assert.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <string.h>
 #include <sys/time.h>
 
 #include "direct_api.h"
@@ -131,7 +132,7 @@
 
 	/* This just sets the storename to what the user requests, no 
 	   verification of existance will be done until connect */
-	sh->conf->store_path = storename;
+	sh->conf->store_path = strdup(storename);
 	sh->conf->store_type = storetype;
 
 	return;
#6 lore raw
Quoted 24 lines · Daniel J Walsh

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 20 lines · Stephen Smalley
Quoted 18 lines · Todd Miller
Quoted 5 lines · Daniel J Walsh

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

genhomedircon includes the "\n" in /etc/shells so no shells in the /etc/passwd match.

Isn't this going to cause problems if the last line in /etc/shells has no newline?

Instead of:

    temp[strlen(temp)-1]=0;

I would use:

    temp[strcspn(temp, "\n")] = '\0';

That will overwrite the first newline with a NUL or, if there is no newline, the terminating NUL will be overwritten with another NUL, which is harmless. It is a useful idiom...

Quoted 6 lines
Quoted 5 lines

Given that getline() returns the length read (not to be confused with the buffer length), why not just:

	while ((len = getline(&temp, &buff_len, shells)) > 0) {
		if (temp[len-1] == '\n') temp[len-1] = 0;

Second try.

Merged with two changes (type on len => ssize_t, assert on store_path after strdup so that we don't continue if allocation fails).

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.