Commits

Anonymous committed 9ca4088

android.c: fix free of uninitialized memory

Under certain error conditions, freecon is called with a pointer
to uninitialized memory. Make sure everything is initialized.

Move variable declaration before any goto statements. Variable
declaration after a goto statement produces weird runtime artifacts.

Change-Id: Ie1db5a8466bbf259f09a612a1c97afc3713e33df

  • Participants
  • Parent commits 7f90cf4

Comments (0)

Files changed (1)

 				const char *seinfo,
 				uid_t uid)
 {
-	char *orig_ctx_str = NULL, *ctx_str;
+	char *orig_ctx_str = NULL;
+	char *ctx_str = NULL;
 	context_t ctx = NULL;
-	int rc;
+	int rc = -1;
 
 	if (is_selinux_enabled() <= 0)
 		return 0;
 {
 	char *orig_ctx_str = NULL, *ctx_str;
 	context_t ctx = NULL;
-	int rc;
+	int rc = -1;
 
 	if (is_selinux_enabled() <= 0)
 		return 0;
 int selinux_android_restorecon(const char *pathname)
 {
 
+	char* oldcontext = NULL;
+	char* newcontext = NULL;
+	struct stat sb;
+	int ret = -1;
+
 	if (is_selinux_enabled() <= 0)
 		return 0;
 
 	__selinux_once(fc_once, file_context_init);
 
-	int ret;
-
 	if (!sehandle)
 		goto bail;
 
-	struct stat sb;
-
 	if (lstat(pathname, &sb) < 0)
 		goto err;
 
-	char *oldcontext, *newcontext;
-
 	if (lgetfilecon(pathname, &oldcontext) < 0)
 		goto err;