Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 16 Mar 2017 20:17:02 +0100
From:      Oliver Pinter <oliver.pinter@hardenedbsd.org>
To:        Bruce Evans <brde@optusnet.com.au>
Cc:        Bruce Evans <bde@freebsd.org>, svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org
Subject:   Re: svn commit: r315418 - in head/sys/teken: . libteken
Message-ID:  <CAPQ4ffs=NkWnUuuNPMHQTFsU6rKCRTvDgLa5ebgjfgcSCiua3w@mail.gmail.com>
In-Reply-To: <20170317055036.D27477@besplex.bde.org>
References:  <201703161640.v2GGes8N033822@repo.freebsd.org> <20170317040832.N26977@besplex.bde.org> <CAPQ4ffvWtZ4fRMOP6_KKHmmy2aPsZ%2BiLFQ5zQB6XWM8LAiNAag@mail.gmail.com> <20170317055036.D27477@besplex.bde.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On 3/16/17, Bruce Evans <brde@optusnet.com.au> wrote:
> On Thu, 16 Mar 2017, Oliver Pinter wrote:
>
>> On 3/16/17, Bruce Evans <brde@optusnet.com.au> wrote:
>>> On Thu, 16 Mar 2017, Bruce Evans wrote:
>>>
>>>> Log:
>>>>  Add teken_256to16() to convert xterm-256 256-color codes to xterm
>>>> 16-color
>>>>  codes.  This will be used to fix bright colors.
>>>>
>>>>  Improve teken_256to8().  Use a lookup table instead of calculations.
>>>> The
>>>>  ...
>>>
>>> A shell script for printing some text color maps is attached.  Also a
>>> sloppier one for printing some CSI sequences.
>>> ...
>>
>> If I'm not wrong, these scripts where made on OS X. They use \r\n line
>> endings,
>> and this triggers random cryptic runtime errors:
>>
>> op@opn /tmp> sh -x sc-vt-CSI
>> + printf $'\\033[m\r'
>> + printf $'\\033[x\r'
>> sc-vt-CSI: 5: Syntax error: word unexpected
>>
>> The simple fix is to delete the '\r's from the scripts:
>>
>> cat sc-vt-CSI | tr -d '\r' > trans.sh
>
> No OS X here.
>
> It means that some mailers mangle even attachments.
>
> Shells should probably accept \r\n as newline on systems where this is
> not the native newline.  Some C compilers do.

The problems stats with imgact_shell, you can easily verify this with
the following:

op@opn /tmp> printf '#\!/bin/sh\r\n' > test.sh
op@opn /tmp> chmod +x test.sh
op@opn /tmp> ./test.sh
./test.sh: Command not found.
op@opn /tmp> sh -x ./test.sh
op@opn /tmp>

A possible solution would be the following patch:

Xdiff --git a/sys/kern/imgact_shell.c b/sys/kern/imgact_shell.c
Xindex aaf521cf251..7b3feb20a3c 100644
X--- a/sys/kern/imgact_shell.c
X+++ b/sys/kern/imgact_shell.c
X@@ -146,7 +146,7 @@ exec_shell_imgact(imgp)
X               ihp++;
X       interpb = ihp;
X       while (ihp < maxp && ((*ihp != ' ') && (*ihp != '\t') && (*ihp != '\n')
X-          && (*ihp != '\0')))
X+          && (*ihp != '\r') && (*ihp != '\0')))
X               ihp++;
X       interpe = ihp;
X       if (interpb == interpe)
X@@ -162,7 +162,7 @@ exec_shell_imgact(imgp)
X       while (ihp < maxp && ((*ihp == ' ') || (*ihp == '\t')))
X               ihp++;
X       optb = ihp;
X-      while (ihp < maxp && ((*ihp != '\n') && (*ihp != '\0')))
X+      while (ihp < maxp && ((*ihp != '\n') && (*ihp != '\r') &&
(*ihp != '\0')))
X               ihp++;
X       opte = ihp;
X       if (opte == maxp)

this is not tested, even nor compile tested, just a PoC.



>
> Bruce
>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAPQ4ffs=NkWnUuuNPMHQTFsU6rKCRTvDgLa5ebgjfgcSCiua3w>