skip the UTF-8 BOM early, then check the magic (ELF, a.out, COFF, …)
This commit is contained in:
parent
a7091123aa
commit
7d3643d7b4
4
check.t
4
check.t
@ -1,4 +1,4 @@
|
||||
# $MirOS: src/bin/mksh/check.t,v 1.442 2011/03/28 21:58:06 tg Exp $
|
||||
# $MirOS: src/bin/mksh/check.t,v 1.443 2011/04/02 10:30:09 tg Exp $
|
||||
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
|
||||
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
|
||||
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
|
||||
@ -25,7 +25,7 @@
|
||||
# http://www.research.att.com/~gsf/public/ifs.sh
|
||||
|
||||
expected-stdout:
|
||||
@(#)MIRBSD KSH R39 2011/03/28
|
||||
@(#)MIRBSD KSH R39 2011/04/01
|
||||
description:
|
||||
Check version of shell.
|
||||
stdin:
|
||||
|
19
exec.c
19
exec.c
@ -22,7 +22,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.88 2011/03/13 01:20:18 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.89 2011/04/02 10:30:10 tg Exp $");
|
||||
|
||||
#ifndef MKSH_DEFAULT_EXECSHELL
|
||||
#define MKSH_DEFAULT_EXECSHELL "/bin/sh"
|
||||
@ -847,8 +847,15 @@ scriptexec(struct op *tp, const char **ap)
|
||||
/* read error -> no good */
|
||||
buf[0] = '\0';
|
||||
close(fd);
|
||||
/* scan for newline (or CR) or NUL _before_ end of buffer */
|
||||
|
||||
/* skip UTF-8 Byte Order Mark, if present */
|
||||
cp = (unsigned char *)buf;
|
||||
if ((cp[0] == 0xEF) && (cp[1] == 0xBB) && (cp[2] == 0xBF))
|
||||
cp += 3;
|
||||
/* save begin of shebang for later */
|
||||
fd = (char *)cp - buf; /* either 0 or (if BOM) 3 */
|
||||
|
||||
/* scan for newline (or CR) or NUL _before_ end of buffer */
|
||||
while ((char *)cp < (buf + sizeof(buf)))
|
||||
if (*cp == '\0' || *cp == '\n' || *cp == '\r') {
|
||||
*cp = '\0';
|
||||
@ -858,13 +865,13 @@ scriptexec(struct op *tp, const char **ap)
|
||||
/* if the shebang line is longer than MAXINTERP, bail out */
|
||||
if ((char *)cp >= (buf + sizeof(buf)))
|
||||
goto noshebang;
|
||||
/* skip UTF-8 Byte Order Mark, if present */
|
||||
cp = (unsigned char *)buf;
|
||||
if ((cp[0] == 0xEF) && (cp[1] == 0xBB) && (cp[2] == 0xBF))
|
||||
cp += 3;
|
||||
|
||||
/* restore begin of shebang position (buf+0 or buf+3) */
|
||||
cp = (unsigned char *)(buf + fd);
|
||||
/* bail out if read error (above) or no shebang */
|
||||
if ((cp[0] != '#') || (cp[1] != '!'))
|
||||
goto noshebang;
|
||||
|
||||
cp += 2;
|
||||
/* skip whitespace before shell name */
|
||||
while (*cp == ' ' || *cp == '\t')
|
||||
|
4
sh.h
4
sh.h
@ -154,9 +154,9 @@
|
||||
#endif
|
||||
|
||||
#ifdef EXTERN
|
||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.457 2011/03/28 08:40:42 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.458 2011/04/02 10:30:11 tg Exp $");
|
||||
#endif
|
||||
#define MKSH_VERSION "R39 2011/03/28"
|
||||
#define MKSH_VERSION "R39 2011/04/01"
|
||||
|
||||
#ifndef MKSH_INCLUDES_ONLY
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user