[RFC PATCH v3 6/9] [fixup] fix handling of invalid context in convert_context

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We can reuse the temporary string 's' and save one kstrdup() call.
---
 security/selinux/ss/services.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c
index 3c5887838e12..e70c7c5d7f26 100644
--- a/security/selinux/ss/services.c
+++ b/security/selinux/ss/services.c
@@ -1934,15 +1934,19 @@ static int convert_context(struct context *oldc, struct context *newc, void *p)
 
 		rc = string_to_context_struct(args->newp, NULL, s,
 					      newc, SECSID_NULL);
+		if (rc == -EINVAL) {
+			/* Retain string representation for later mapping. */
+			context_init(newc);
+			newc->str = s;
+			newc->len = oldc->len;
+			rc = 0;
+			goto out;
+		}
 		kfree(s);
 		if (!rc) {
 			pr_info("SELinux:  Context %s became valid (mapped).\n",
 				oldc->str);
 			goto out;
-		} else if (rc == -EINVAL) {
-			/* Retain string representation for later mapping. */
-			rc = 0;
-			goto out;
 		} else {
 			/* Other error condition, e.g. ENOMEM. */
 			pr_err("SELinux:   Unable to map context %s, rc = %d.\n",
-- 
2.19.2




[Index of Archives]     [Selinux Refpolicy]     [Linux SGX]     [Fedora Users]     [Fedora Desktop]     [Yosemite Photos]     [Yosemite Camping]     [Yosemite Campsites]     [KDE Users]     [Gnome Users]

  Powered by Linux