bash-4.4-coverity.patch 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. diff --git a/builtins/fc.def b/builtins/fc.def
  2. index fe16471..98c53db 100644
  3. --- a/builtins/fc.def
  4. +++ b/builtins/fc.def
  5. @@ -423,6 +423,7 @@ fc_builtin (list)
  6. {
  7. sh_wrerror ();
  8. fclose (stream);
  9. + FREE (fn);
  10. return (EXECUTION_FAILURE);
  11. }
  12. fclose (stream);
  13. diff --git a/execute_cmd.c b/execute_cmd.c
  14. index 63a332a..15b5e19 100644
  15. --- a/execute_cmd.c
  16. +++ b/execute_cmd.c
  17. @@ -2196,8 +2196,10 @@ coproc_setvars (cp)
  18. if (v == 0)
  19. {
  20. v = find_variable_nameref_for_create (cp->c_name, 1);
  21. - if (v == INVALID_NAMEREF_VALUE)
  22. - return;
  23. + if (v == INVALID_NAMEREF_VALUE) {
  24. + free (namevar);
  25. + return;
  26. + }
  27. if (v && nameref_p (v))
  28. {
  29. free (cp->c_name);
  30. @@ -2210,6 +2212,7 @@ coproc_setvars (cp)
  31. {
  32. if (readonly_p (v))
  33. err_readonly (cp->c_name);
  34. + free (namevar);
  35. return;
  36. }
  37. if (v == 0)
  38. @@ -5528,7 +5531,6 @@ shell_execve (command, args, env)
  39. char *interp;
  40. int ilen;
  41. - close (fd);
  42. interp = getinterp (sample, sample_len, (int *)NULL);
  43. ilen = strlen (interp);
  44. errno = i;
  45. diff --git a/expr.c b/expr.c
  46. index 172964a..5dc57c0 100644
  47. --- a/expr.c
  48. +++ b/expr.c
  49. @@ -207,7 +207,8 @@ static intmax_t exp5 __P((void));
  50. static intmax_t exp4 __P((void));
  51. static intmax_t expshift __P((void));
  52. static intmax_t exp3 __P((void));
  53. -static intmax_t exp2 __P((void));
  54. +/* Avoid name clash with standard exp2 */
  55. +static intmax_t bash_exp2 __P((void));
  56. static intmax_t exppower __P((void));
  57. static intmax_t exp1 __P((void));
  58. static intmax_t exp0 __P((void));
  59. @@ -809,14 +810,14 @@ exp3 ()
  60. {
  61. register intmax_t val1, val2;
  62. - val1 = exp2 ();
  63. + val1 = bash_exp2 ();
  64. while ((curtok == PLUS) || (curtok == MINUS))
  65. {
  66. int op = curtok;
  67. readtok ();
  68. - val2 = exp2 ();
  69. + val2 = bash_exp2 ();
  70. if (op == PLUS)
  71. val1 += val2;
  72. @@ -828,7 +829,7 @@ exp3 ()
  73. }
  74. static intmax_t
  75. -exp2 ()
  76. +bash_exp2 ()
  77. {
  78. register intmax_t val1, val2;
  79. #if defined (HAVE_IMAXDIV)
  80. diff --git a/lib/glob/glob.c b/lib/glob/glob.c
  81. index 7f6eafe..c018e29 100644
  82. --- a/lib/glob/glob.c
  83. +++ b/lib/glob/glob.c
  84. @@ -576,7 +576,7 @@ glob_vector (pat, dir, flags)
  85. register char *nextname, *npat, *subdir;
  86. unsigned int count;
  87. int lose, skip, ndirs, isdir, sdlen, add_current, patlen;
  88. - register char **name_vector;
  89. + register char **name_vector = NULL;
  90. register unsigned int i;
  91. int mflags; /* Flags passed to strmatch (). */
  92. int pflags; /* flags passed to sh_makepath () */
  93. @@ -894,7 +894,7 @@ glob_vector (pat, dir, flags)
  94. }
  95. /* Don't call QUIT; here; let higher layers deal with it. */
  96. -
  97. + FREE (name_vector);
  98. return ((char **)NULL);
  99. }
  100. diff --git a/lib/sh/pathcanon.c b/lib/sh/pathcanon.c
  101. index f19bd55..2a565d6 100644
  102. --- a/lib/sh/pathcanon.c
  103. +++ b/lib/sh/pathcanon.c
  104. @@ -227,7 +227,7 @@ sh_canonpath (path, flags)
  105. if (result[2] == '\0') /* short-circuit for bare `//' */
  106. result[1] = '\0';
  107. else
  108. - strcpy (result, result + 1);
  109. + memmove(result, result + 1, strlen(result + 1) + 1);
  110. }
  111. return (result);
  112. diff --git a/lib/sh/pathphys.c b/lib/sh/pathphys.c
  113. index 26016b7..b64c4cd 100644
  114. --- a/lib/sh/pathphys.c
  115. +++ b/lib/sh/pathphys.c
  116. @@ -245,7 +245,7 @@ error:
  117. if (result[2] == '\0') /* short-circuit for bare `//' */
  118. result[1] = '\0';
  119. else
  120. - strcpy (result, result + 1);
  121. + memmove(result, result + 1, strlen(result + 1) + 1);
  122. }
  123. return (result);
  124. diff --git a/shell.c b/shell.c
  125. index b43de50..4aae182 100644
  126. --- a/shell.c
  127. +++ b/shell.c
  128. @@ -1948,8 +1948,10 @@ show_shell_usage (fp, extra)
  129. fputs (_("\t-ilrsD or -c command or -O shopt_option\t\t(invocation only)\n"), fp);
  130. for (i = 0, set_opts = 0; shell_builtins[i].name; i++)
  131. - if (STREQ (shell_builtins[i].name, "set"))
  132. + if (STREQ (shell_builtins[i].name, "set")) {
  133. set_opts = savestring (shell_builtins[i].short_doc);
  134. + break;
  135. + }
  136. if (set_opts)
  137. {
  138. s = strchr (set_opts, '[');
  139. diff --git a/subst.c b/subst.c
  140. index 5f3e41e..7574617 100644
  141. --- a/subst.c
  142. +++ b/subst.c
  143. @@ -5182,8 +5182,11 @@ parameter_list_transform (xc, itype, quoted)
  144. list = list_rest_of_args ();
  145. if (list == 0)
  146. return ((char *)NULL);
  147. - if (xc == 'A')
  148. - return (pos_params_assignment (list, itype, quoted));
  149. + if (xc == 'A') {
  150. + ret = pos_params_assignment (list, itype, quoted);
  151. + dispose_words (list);
  152. + return (ret);
  153. + }
  154. ret = list_transform (xc, (SHELL_VAR *)0, list, itype, quoted);
  155. dispose_words (list);
  156. return (ret);
  157. @@ -6813,6 +6816,7 @@ parameter_brace_expand_rhs (name, value, c, quoted, pflags, qdollaratp, hasdolla
  158. {
  159. report_error (_("%s: invalid indirect expansion"), name);
  160. free (vname);
  161. + free (t1);
  162. dispose_word (w);
  163. return &expand_wdesc_error;
  164. }
  165. @@ -6820,6 +6824,7 @@ parameter_brace_expand_rhs (name, value, c, quoted, pflags, qdollaratp, hasdolla
  166. {
  167. report_error (_("%s: invalid variable name"), vname);
  168. free (vname);
  169. + free (t1);
  170. dispose_word (w);
  171. return &expand_wdesc_error;
  172. }
  173. diff --git a/support/man2html.c b/support/man2html.c
  174. index 6ba5061..1d9e376 100644
  175. --- a/support/man2html.c
  176. +++ b/support/man2html.c
  177. @@ -522,6 +522,7 @@ read_man_page(char *filename)
  178. man_buf[buf_size] = '\n';
  179. man_buf[buf_size + 1] = man_buf[buf_size + 2] = '\0';
  180. } else {
  181. + free (man_buf);
  182. man_buf = NULL;
  183. }
  184. fclose(man_stream);
  185. @@ -2562,7 +2563,6 @@ scan_request(char *c)
  186. h = name;
  187. if (stat(h, &stbuf) != -1)
  188. l = stbuf.st_size;
  189. - buf = stralloc(l + 4);
  190. #if NOCGI
  191. if (!out_length) {
  192. char *t, *s;