OSDN Git Service

Upgrade to mksh 50e.
[android-x86/external-mksh.git] / src / misc.c
index 82d47d6..7c8d114 100644 (file)
@@ -1,9 +1,9 @@
-/*     $OpenBSD: misc.c,v 1.38 2013/11/28 10:33:37 sobrado Exp $       */
+/*     $OpenBSD: misc.c,v 1.39 2015/01/16 06:39:32 deraadt Exp $       */
 /*     $OpenBSD: path.c,v 1.12 2005/03/30 17:16:37 deraadt Exp $       */
 
 /*-
  * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
- *              2011, 2012, 2013, 2014
+ *              2011, 2012, 2013, 2014, 2015
  *     Thorsten Glaser <tg@mirbsd.org>
  *
  * Provided that these terms and disclaimer and all copyright notices
@@ -30,7 +30,7 @@
 #include <grp.h>
 #endif
 
-__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.219 2014/01/05 21:57:27 tg Exp $");
+__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.219.2.2 2015/03/01 15:43:02 tg Exp $");
 
 #define KSH_CHVT_FLAG
 #ifdef MKSH_SMALL
@@ -281,15 +281,15 @@ change_flag(enum sh_flag f, int what, bool newset)
 #endif
                DO_SETUID(setresuid, (ksheuid, ksheuid, ksheuid));
 #else /* !HAVE_SETRESUGID */
-               /* seteuid, setegid, setgid don't EAGAIN on Linux */
+               /* setgid, setegid, seteuid don't EAGAIN on Linux */
+               setgid(kshegid);
 #ifndef MKSH__NO_SETEUGID
-               seteuid(ksheuid);
+               setegid(kshegid);
 #endif
                DO_SETUID(setuid, (ksheuid));
 #ifndef MKSH__NO_SETEUGID
-               setegid(kshegid);
+               seteuid(ksheuid);
 #endif
-               setgid(kshegid);
 #endif /* !HAVE_SETRESUGID */
        } else if ((f == FPOSIX || f == FSH) && newval) {
                /* Turning on -o posix or -o sh? */
@@ -304,6 +304,11 @@ change_flag(enum sh_flag f, int what, bool newset)
 void
 change_xtrace(unsigned char newval, bool dosnapshot)
 {
+       static bool in_xtrace;
+
+       if (in_xtrace)
+               return;
+
        if (!dosnapshot && newval == Flag(FXTRACE))
                return;
 
@@ -328,8 +333,13 @@ change_xtrace(unsigned char newval, bool dosnapshot)
                shl_xtrace->fd = 2;
 
  changed_xtrace:
-       if ((Flag(FXTRACE) = newval) == 2)
+       if ((Flag(FXTRACE) = newval) == 2) {
+               in_xtrace = true;
+               Flag(FXTRACE) = 0;
                shf_puts(substitute(str_val(global("PS4")), 0), shl_xtrace);
+               Flag(FXTRACE) = 2;
+               in_xtrace = false;
+       }
 }
 
 /*
@@ -485,7 +495,6 @@ parse_args(const char **argv,
        if (arrayset) {
                const char *ccp = NULL;
 
-               mkssert(array != NULL);
                if (*array)
                        ccp = skip_varname(array, false);
                if (!ccp || !(!ccp[0] || (ccp[0] == '+' && !ccp[1]))) {
@@ -1384,8 +1393,7 @@ do_realpath(const char *upath)
 {
        char *xp, *ip, *tp, *ipath, *ldest = NULL;
        XString xs;
-       ptrdiff_t pos;
-       size_t len;
+       size_t pos, len;
        int llen;
        struct stat sb;
 #ifdef MKSH__NO_PATH_MAX