Blame SOURCES/bash-4.4-coverity.patch

9014c4
diff --git a/builtins/fc.def b/builtins/fc.def
9014c4
index fe16471..98c53db 100644
9014c4
--- a/builtins/fc.def
9014c4
+++ b/builtins/fc.def
9014c4
@@ -423,6 +423,7 @@ fc_builtin (list)
9014c4
     {
9014c4
       sh_wrerror ();
9014c4
       fclose (stream);
9014c4
+      FREE (fn);
9014c4
       return (EXECUTION_FAILURE);
9014c4
     }
9014c4
   fclose (stream);
9014c4
diff --git a/execute_cmd.c b/execute_cmd.c
9014c4
index 63a332a..15b5e19 100644
9014c4
--- a/execute_cmd.c
9014c4
+++ b/execute_cmd.c
9014c4
@@ -2196,8 +2196,10 @@ coproc_setvars (cp)
9014c4
   if (v == 0)
9014c4
     {
9014c4
       v = find_variable_nameref_for_create (cp->c_name, 1);
9014c4
-      if (v == INVALID_NAMEREF_VALUE)
9014c4
-	return;
9014c4
+      if (v == INVALID_NAMEREF_VALUE) {
9014c4
+        free (namevar);
9014c4
+        return;
9014c4
+      }
9014c4
       if (v && nameref_p (v))
9014c4
 	{
9014c4
 	  free (cp->c_name);
9014c4
@@ -2210,6 +2212,7 @@ coproc_setvars (cp)
9014c4
     {
9014c4
       if (readonly_p (v))
9014c4
 	err_readonly (cp->c_name);
9014c4
+      free (namevar);
9014c4
       return;
9014c4
     }
9014c4
   if (v == 0)
9014c4
@@ -5528,7 +5531,6 @@ shell_execve (command, args, env)
9014c4
 	      char *interp;
9014c4
 	      int ilen;
9014c4
 
9014c4
-              close (fd);
9014c4
 	      interp = getinterp (sample, sample_len, (int *)NULL);
9014c4
 	      ilen = strlen (interp);
9014c4
 	      errno = i;
9014c4
diff --git a/expr.c b/expr.c
9014c4
index 172964a..5dc57c0 100644
9014c4
--- a/expr.c
9014c4
+++ b/expr.c
9014c4
@@ -207,7 +207,8 @@ static intmax_t exp5 __P((void));
9014c4
 static intmax_t exp4 __P((void));
9014c4
 static intmax_t expshift __P((void));
9014c4
 static intmax_t exp3 __P((void));
9014c4
-static intmax_t exp2 __P((void));
9014c4
+/* Avoid name clash with standard exp2 */
9014c4
+static intmax_t bash_exp2 __P((void));
9014c4
 static intmax_t	exppower __P((void));
9014c4
 static intmax_t exp1 __P((void));
9014c4
 static intmax_t exp0 __P((void));
9014c4
@@ -809,14 +810,14 @@ exp3 ()
9014c4
 {
9014c4
   register intmax_t val1, val2;
9014c4
 
9014c4
-  val1 = exp2 ();
9014c4
+  val1 = bash_exp2 ();
9014c4
 
9014c4
   while ((curtok == PLUS) || (curtok == MINUS))
9014c4
     {
9014c4
       int op = curtok;
9014c4
 
9014c4
       readtok ();
9014c4
-      val2 = exp2 ();
9014c4
+      val2 = bash_exp2 ();
9014c4
 
9014c4
       if (op == PLUS)
9014c4
 	val1 += val2;
9014c4
@@ -828,7 +829,7 @@ exp3 ()
9014c4
 }
9014c4
 
9014c4
 static intmax_t
9014c4
-exp2 ()
9014c4
+bash_exp2 ()
9014c4
 {
9014c4
   register intmax_t val1, val2;
9014c4
 #if defined (HAVE_IMAXDIV)
9014c4
diff --git a/lib/glob/glob.c b/lib/glob/glob.c
9014c4
index 7f6eafe..c018e29 100644
9014c4
--- a/lib/glob/glob.c
9014c4
+++ b/lib/glob/glob.c
9014c4
@@ -576,7 +576,7 @@ glob_vector (pat, dir, flags)
9014c4
   register char *nextname, *npat, *subdir;
9014c4
   unsigned int count;
9014c4
   int lose, skip, ndirs, isdir, sdlen, add_current, patlen;
9014c4
-  register char **name_vector;
9014c4
+  register char **name_vector = NULL;
9014c4
   register unsigned int i;
9014c4
   int mflags;		/* Flags passed to strmatch (). */
9014c4
   int pflags;		/* flags passed to sh_makepath () */
9014c4
@@ -894,7 +894,7 @@ glob_vector (pat, dir, flags)
9014c4
 	}
9014c4
 
9014c4
       /* Don't call QUIT; here; let higher layers deal with it. */
9014c4
-
9014c4
+      FREE (name_vector);
9014c4
       return ((char **)NULL);
9014c4
     }
9014c4
 
9014c4
diff --git a/lib/sh/pathcanon.c b/lib/sh/pathcanon.c
9014c4
index f19bd55..2a565d6 100644
9014c4
--- a/lib/sh/pathcanon.c
9014c4
+++ b/lib/sh/pathcanon.c
9014c4
@@ -227,7 +227,7 @@ sh_canonpath (path, flags)
9014c4
       if (result[2] == '\0')	/* short-circuit for bare `//' */
9014c4
 	result[1] = '\0';
9014c4
       else
9014c4
-	strcpy (result, result + 1);
9014c4
+	memmove(result, result + 1, strlen(result + 1) + 1);
9014c4
     }
9014c4
 
9014c4
   return (result);
9014c4
diff --git a/lib/sh/pathphys.c b/lib/sh/pathphys.c
9014c4
index 26016b7..b64c4cd 100644
9014c4
--- a/lib/sh/pathphys.c
9014c4
+++ b/lib/sh/pathphys.c
9014c4
@@ -245,7 +245,7 @@ error:
9014c4
       if (result[2] == '\0')	/* short-circuit for bare `//' */
9014c4
 	result[1] = '\0';
9014c4
       else
9014c4
-	strcpy (result, result + 1);
9014c4
+	memmove(result, result + 1, strlen(result + 1) + 1);
9014c4
     }
9014c4
 
9014c4
   return (result);
9014c4
diff --git a/shell.c b/shell.c
9014c4
index b43de50..4aae182 100644
9014c4
--- a/shell.c
9014c4
+++ b/shell.c
9014c4
@@ -1948,8 +1948,10 @@ show_shell_usage (fp, extra)
9014c4
   fputs (_("\t-ilrsD or -c command or -O shopt_option\t\t(invocation only)\n"), fp);
9014c4
 
9014c4
   for (i = 0, set_opts = 0; shell_builtins[i].name; i++)
9014c4
-    if (STREQ (shell_builtins[i].name, "set"))
9014c4
+    if (STREQ (shell_builtins[i].name, "set")) {
9014c4
       set_opts = savestring (shell_builtins[i].short_doc);
9014c4
+      break;
9014c4
+    }
9014c4
   if (set_opts)
9014c4
     {
9014c4
       s = strchr (set_opts, '[');
9014c4
diff --git a/subst.c b/subst.c
9014c4
index 5f3e41e..7574617 100644
9014c4
--- a/subst.c
9014c4
+++ b/subst.c
9014c4
@@ -5182,8 +5182,11 @@ parameter_list_transform (xc, itype, quoted)
9014c4
   list = list_rest_of_args ();
9014c4
   if (list == 0)
9014c4
     return ((char *)NULL);
9014c4
-  if (xc == 'A')
9014c4
-    return (pos_params_assignment (list, itype, quoted));
9014c4
+  if (xc == 'A') {
9014c4
+      ret = pos_params_assignment (list, itype, quoted);
9014c4
+      dispose_words (list);
9014c4
+      return (ret);
9014c4
+  }
9014c4
   ret = list_transform (xc, (SHELL_VAR *)0, list, itype, quoted);
9014c4
   dispose_words (list);
9014c4
   return (ret);
9014c4
@@ -6813,6 +6816,7 @@ parameter_brace_expand_rhs (name, value, c, quoted, pflags, qdollaratp, hasdolla
9014c4
 	{
9014c4
 	  report_error (_("%s: invalid indirect expansion"), name);
9014c4
 	  free (vname);
9014c4
+      free (t1);
9014c4
 	  dispose_word (w);
9014c4
 	  return &expand_wdesc_error;
9014c4
 	}
9014c4
@@ -6820,6 +6824,7 @@ parameter_brace_expand_rhs (name, value, c, quoted, pflags, qdollaratp, hasdolla
9014c4
 	{
9014c4
 	  report_error (_("%s: invalid variable name"), vname);
9014c4
 	  free (vname);
9014c4
+      free (t1);
9014c4
 	  dispose_word (w);
9014c4
 	  return &expand_wdesc_error;
9014c4
 	}
9014c4
diff --git a/support/man2html.c b/support/man2html.c
9014c4
index 6ba5061..1d9e376 100644
9014c4
--- a/support/man2html.c
9014c4
+++ b/support/man2html.c
9014c4
@@ -522,6 +522,7 @@ read_man_page(char *filename)
9014c4
 			man_buf[buf_size] = '\n';
9014c4
 			man_buf[buf_size + 1] = man_buf[buf_size + 2] = '\0';
9014c4
 		} else {
9014c4
+            free (man_buf);
9014c4
 			man_buf = NULL;
9014c4
 		}
9014c4
 		fclose(man_stream);
9014c4
@@ -2562,7 +2563,6 @@ scan_request(char *c)
9014c4
 					h = name;
9014c4
 				if (stat(h, &stbuf) != -1)
9014c4
 					l = stbuf.st_size;
9014c4
-				buf = stralloc(l + 4);
9014c4
 #if NOCGI
9014c4
 				if (!out_length) {
9014c4
 					char   *t, *s;