• fix memory leaks found by coverity

from netbsd via oksh
  we had the NULL pointer deref already fixed
• avoid a bogus not-setting the return value of edit.c:x_file_glob()
  introduced by the above change in oksh
• escape ? as well (but not ] because that’s wrong)
  reminded by cbiere@netbsd via oksh
• Unsetting a non-existent variable is not an error. See
  http://www.opengroup.org/onlinepubs/009695399/utilities/unset.html
  report from Arkadiusz Miskiewicz; fixed based on
  http://cvs.pld-linux.org diff via oksh but modified slightly
• Be more smart waiting for input for non-interactive scripts.  Fix
  based on a diff from debian:  see their bug#296446 (via oksh)
  modified slightly
  this also fixes cnuke@’s “mksh busy loop” problem, for which I never
  received a bug report, but the Debian bug page contains a set of two
  scripts to reproduce this before (and no longer after) this commit
• some KNF
• bump version
This commit is contained in:
tg
2007-09-09 18:06:42 +00:00
parent fe65f616e4
commit c1c939e340
9 changed files with 78 additions and 57 deletions

23
exec.c
View File

@ -1,8 +1,8 @@
/* $OpenBSD: exec.c,v 1.46 2006/04/10 14:38:59 jaredy Exp $ */
/* $OpenBSD: exec.c,v 1.48 2007/09/05 19:02:01 otto Exp $ */
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.37 2007/07/24 11:22:04 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.38 2007/09/09 18:06:40 tg Exp $");
static int comexec(struct op *, struct tbl *volatile, const char **,
int volatile);
@ -881,7 +881,7 @@ findcom(const char *name, int flags)
struct tbl *tp = NULL, *tbi;
int insert = Flag(FTRACKALL); /* insert if not found */
char *fpath; /* for function autoloading */
const char *npath;
union mksh_cchack npath;
if (vstrchr(name, '/')) {
insert = 0;
@ -934,14 +934,21 @@ findcom(const char *name, int flags)
}
tp->flag = DEFINED; /* make ~ISSET */
}
npath = search(name, flags & FC_DEFPATH ? def_path : path,
npath.ro = search(name, flags & FC_DEFPATH ? def_path : path,
X_OK, &tp->u2.errno_);
if (npath) {
tp->val.s = str_save(npath, APERM);
if (npath.ro) {
/* XXX unsure about this, oksh does that
if (tp == &temp)
tp->val.s = npath.ro;
else */ {
tp->val.s = str_save(npath.ro, APERM);
if (npath.ro != name)
afree(npath.rw, ATEMP);
}
tp->flag |= ISSET|ALLOC;
} else if ((flags & FC_FUNC) &&
(fpath = str_val(global("FPATH"))) != null &&
(npath = search(name, fpath, R_OK,
(npath.ro = search(name, fpath, R_OK,
&tp->u2.errno_)) != NULL) {
/* An undocumented feature of at&t ksh is that it
* searches FPATH if a command is not found, even
@ -951,7 +958,7 @@ findcom(const char *name, int flags)
tp = &temp;
tp->type = CFUNC;
tp->flag = DEFINED; /* make ~ISSET */
tp->u.fpath = npath;
tp->u.fpath = npath.ro;
}
}
return tp;