Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Your mode of life will be changed to EBCDIC.


devel / comp.lang.forth / Re: EVALUATE in minimum search order

SubjectAuthor
* EVALUATE in minimum search ordernone
+- Re: EVALUATE in minimum search orderStephen Pelc
+* Re: EVALUATE in minimum search orderAnton Ertl
|`* Re: EVALUATE in minimum search ordernone
| +- Re: EVALUATE in minimum search orderRuvim
| `- Re: EVALUATE in minimum search orderAnton Ertl
`- Re: EVALUATE in minimum search orderS Jack

1
EVALUATE in minimum search order

<nnd$66ea20ee$7fc8e28f@5569ede25e4143de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17776&group=comp.lang.forth#17776

  copy link   Newsgroups: comp.lang.forth
Newsgroups: comp.lang.forth
Subject: EVALUATE in minimum search order
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
From: alb...@cherry (none)
Originator: albert@cherry.(none) (albert)
Message-ID: <nnd$66ea20ee$7fc8e28f@5569ede25e4143de>
Organization: KPN B.V.
Date: Sat, 30 Apr 2022 14:38:52 +0200
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feed.abavia.com!abe004.abavia.com!abp001.abavia.com!news.kpn.nl!not-for-mail
Lines: 25
Injection-Date: Sat, 30 Apr 2022 14:38:52 +0200
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
X-Received-Bytes: 1390
 by: none - Sat, 30 Apr 2022 12:38 UTC

I'm doing my taxes and i have to evaluate strings like "4,54"
resulting in a number of cents.
A do a precaution, I want that numbers are only recognized
after ONLY, i.e. in the minimum search order, to prevent
executing of arbitrary strings, such
" ""rm *"" SYSTEM ".

So I begin the dotaxes word

: dotaxes ONLY ... ;

That works in my simple (own) Forth and also in gforth.

I wonder if that is a portable technique?

Groetjes Albert

P.S. My Forth ignores comma's in numbers. It doable by >NUMBER
but that is a pain.
--
"in our communism country Viet Nam, people are forced to be
alive and in the western country like US, people are free to
die from Covid 19 lol" duc ha
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

Re: EVALUATE in minimum search order

<t4jfmk$43c$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17777&group=comp.lang.forth#17777

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: step...@vfxforth.com (Stephen Pelc)
Newsgroups: comp.lang.forth
Subject: Re: EVALUATE in minimum search order
Date: Sat, 30 Apr 2022 14:05:08 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <t4jfmk$43c$1@dont-email.me>
References: <nnd$66ea20ee$7fc8e28f@5569ede25e4143de>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=fixed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 30 Apr 2022 14:05:08 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="b5a6bdd71d2e5ce94ce4f52f6db2a96f";
logging-data="4204"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18ZERT/T0XESaOxn//0Jy1P"
User-Agent: Usenapp for MacOS
Cancel-Lock: sha1:P9qL8e/AW8mfbrkj+H1JMsb7bfQ=
X-Usenapp: v1.19/l - Full License
 by: Stephen Pelc - Sat, 30 Apr 2022 14:05 UTC

On 30 Apr 2022 at 14:38:52 CEST, "none) (albert" <none) (albert> wrote:

> I'm doing my taxes and i have to evaluate strings like "4,54"
> resulting in a number of cents.
> A do a precaution, I want that numbers are only recognized
> after ONLY, i.e. in the minimum search order, to prevent
> executing of arbitrary strings, such
> " ""rm *"" SYSTEM ".
>
> So I begin the dotaxes word
>
> : dotaxes ONLY ... ;
>
> That works in my simple (own) Forth and also in gforth.
>
> I wonder if that is a portable technique?

I'm not convinced that ONLY is sufficiently defined for you.

"Set the search order to the implementation-defined minimum search order. The
minimum search order shall include the words FORTH-WORDLIST and SET-ORDER.
"

The ANS/Forth200x/Forth202x failure to define how number separators can be
defined is a problem that forces people to bury tools. MPE Forths have allowed
users to define separators for 25+ years.

Stephen

--
Stephen Pelc, stephen@vfxforth.com
MicroProcessor Engineering, Ltd. - More Real, Less Time
133 Hill Lane, Southampton SO15 5AF, England
tel: +44 (0)23 8063 1441, +44 (0)78 0390 3612, +34 649 662 974
http://www.mpeforth.com - free VFX Forth downloads

Re: EVALUATE in minimum search order

<2022Apr30.193157@mips.complang.tuwien.ac.at>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17778&group=comp.lang.forth#17778

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ant...@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.lang.forth
Subject: Re: EVALUATE in minimum search order
Date: Sat, 30 Apr 2022 17:31:57 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 39
Message-ID: <2022Apr30.193157@mips.complang.tuwien.ac.at>
References: <nnd$66ea20ee$7fc8e28f@5569ede25e4143de>
Injection-Info: reader02.eternal-september.org; posting-host="0a982708a1ecf4caa459b05701c8552a";
logging-data="9451"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1//O5wkBwPhbb49izzJ29pN"
Cancel-Lock: sha1:WUfreqjvSuhfDxD4B5LFACjo2ug=
X-newsreader: xrn 10.00-beta-3
 by: Anton Ertl - Sat, 30 Apr 2022 17:31 UTC

albert@cherry.(none) (albert) writes:
>I'm doing my taxes and i have to evaluate strings like "4,54"
>resulting in a number of cents.
>A do a precaution, I want that numbers are only recognized
>after ONLY

I assume you mean that you only want to use EVALUATE, but only
recognize numbers.

>i.e. in the minimum search order, to prevent
>executing of arbitrary strings, such
>" ""rm *"" SYSTEM ".
>
>So I begin the dotaxes word
>
>: dotaxes ONLY ... ;
>
>That works in my simple (own) Forth and also in gforth.

It's not clear what's up with the quotes in the example above, but in
Gforth you can break out of ONLY with FORTH (ONLY is not SEAL, and
even SEAL is not what you want). E.g.

only forth
s" evil-command" system

You can also break out of ONLY with FORTH in iForth, lxf, SwiftForth,
and VFX.

If you want to remove all word lists from the search order, use

0 set-order

- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: http://www.forth200x.org/forth200x.html
EuroForth 2021: https://euro.theforth.net/2021

Re: EVALUATE in minimum search order

<nnd$21d44e75$1034620e@bc428715b44184cf>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17779&group=comp.lang.forth#17779

  copy link   Newsgroups: comp.lang.forth
Newsgroups: comp.lang.forth
References: <nnd$66ea20ee$7fc8e28f@5569ede25e4143de> <2022Apr30.193157@mips.complang.tuwien.ac.at>
Subject: Re: EVALUATE in minimum search order
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
From: alb...@cherry (none)
Originator: albert@cherry.(none) (albert)
Message-ID: <nnd$21d44e75$1034620e@bc428715b44184cf>
Organization: KPN B.V.
Date: Sun, 01 May 2022 11:27:40 +0200
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!feeder.usenetexpress.com!tr1.eu1.usenetexpress.com!94.232.112.245.MISMATCH!abe005.abavia.com!abp003.abavia.com!news.kpn.nl!not-for-mail
Lines: 97
Injection-Date: Sun, 01 May 2022 11:27:40 +0200
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
 by: none - Sun, 1 May 2022 09:27 UTC

In article <2022Apr30.193157@mips.complang.tuwien.ac.at>,
Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>albert@cherry.(none) (albert) writes:
>>I'm doing my taxes and i have to evaluate strings like "4,54"
>>resulting in a number of cents.
>>A do a precaution, I want that numbers are only recognized
>>after ONLY
>
>I assume you mean that you only want to use EVALUATE, but only
>recognize numbers.
>
>>i.e. in the minimum search order, to prevent
>>executing of arbitrary strings, such
>>" ""rm *"" SYSTEM ".
>>
>>So I begin the dotaxes word
>>
>>: dotaxes ONLY ... ;
>>
>>That works in my simple (own) Forth and also in gforth.
>
>It's not clear what's up with the quotes in the example above, but in

As long as the prefix " was not ISO anyway I adopted the ALGOL68
convention that you can insert " in a string by doubling it.
I was not prepared to invent a string denotation that doesn't
allow me to define strings of printable characters. (AD MMI that was).

>Gforth you can break out of ONLY with FORTH (ONLY is not SEAL, and
>even SEAL is not what you want). E.g.
>
>only forth
>s" evil-command" system

That was what I wanted to prevent. So no forth-wordlist in the
search-order containing the evil `SYSTEM command.

>
>You can also break out of ONLY with FORTH in iForth, lxf, SwiftForth,
>and VFX.

And ciforth. Everybody uses
`` ONLY FORTH ''
That is not the way the standard expects it apparently.
You are supposed to do
`` forth-wordlist 1 set-order ''
because it is not guaranteed that FORTH is in the minimum search order.
(Last time I looked.)

>
>If you want to remove all word lists from the search order, use
>
>0 set-order

The trick^H^H^H^H technique works in gforth and mpe forth.
: test ONLY S" 1 2 3 DROP" EVALUATE ; redefined test ok
test
*evaluated string*:-1: Undefined word
1 2 3 >>>DROP<<<
Backtrace:
....

What you recommend, works also in ciforth and gforth.

ONLY FORTH ok
: test 0 set-order S" 1 2 3 DROP" EVALUATE ; redefined test ok
test
*evaluated string*:-1: Undefined word
1 2 3 >>>DROP<<<

It works more or less in mpe forth, but you cannot recover
from `` 0 set-order '' . You can only type ^C .
`` ONLY FORTH '' doesn't help. This is certainly a
viable interpretation of the standard, making ONLY the
best portable way to have the Forth system understand numbers
("denotations") only.

>- anton

Groetjes Albert

P.S.
I'm doing my taxes, and an unbridled EVALUATE feels not right.

: doit ONLY
"ING1742206_2021.csv" SLURP-FILE TRANSACTIONS 2!
"recipients.txt" SLURP-FILE DONATIONS 2!
process-recipients ;

Making this into a turnkey, it is not a big deal that the (mpe)
interpreter is messed up, so either technique works.
--
"in our communism country Viet Nam, people are forced to be
alive and in the western country like US, people are free to
die from Covid 19 lol" duc ha
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

Re: EVALUATE in minimum search order

<t4ltjc$fm7$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17780&group=comp.lang.forth#17780

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ruvim.pi...@gmail.com (Ruvim)
Newsgroups: comp.lang.forth
Subject: Re: EVALUATE in minimum search order
Date: Sun, 1 May 2022 16:14:34 +0400
Organization: A noiseless patient Spider
Lines: 78
Message-ID: <t4ltjc$fm7$1@dont-email.me>
References: <nnd$66ea20ee$7fc8e28f@5569ede25e4143de>
<2022Apr30.193157@mips.complang.tuwien.ac.at>
<nnd$21d44e75$1034620e@bc428715b44184cf>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 1 May 2022 12:14:36 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="6806ec525c5f773062c4d5470060c309";
logging-data="16071"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/1xpvUDytg7Ux1S8KqFr4A"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.8.1
Cancel-Lock: sha1:xAlkKyltUFx3UvrqnGFJ6Hos4ck=
In-Reply-To: <nnd$21d44e75$1034620e@bc428715b44184cf>
Content-Language: en-US
 by: Ruvim - Sun, 1 May 2022 12:14 UTC

On 2022-05-01 13:27, albert wrote:
> In article <2022Apr30.193157@mips.complang.tuwien.ac.at>,
> Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>> albert@cherry.(none) (albert) writes:
>>> I'm doing my taxes and i have to evaluate strings like "4,54"
>>> resulting in a number of cents.
>>> A do a precaution, I want that numbers are only recognized
>>> after ONLY
>>
>> I assume you mean that you only want to use EVALUATE, but only
>> recognize numbers.
>>
[...]

>> Gforth you can break out of ONLY with FORTH (ONLY is not SEAL, and
>> even SEAL is not what you want). E.g.
>>
>> only forth
>> s" evil-command" system
>
> That was what I wanted to prevent. So no forth-wordlist in the
> search-order containing the evil `SYSTEM command.
>

[...]
>>
>> If you want to remove all word lists from the search order, use
>>
>> 0 set-order
>
> The trick^H^H^H^H technique works in gforth and mpe forth.
> : test ONLY S" 1 2 3 DROP" EVALUATE ; redefined test ok
> test
> *evaluated string*:-1: Undefined word
> 1 2 3 >>>DROP<<<
> Backtrace:
> ...
>
> What you recommend, works also in ciforth and gforth.
>
> ONLY FORTH ok
> : test 0 set-order S" 1 2 3 DROP" EVALUATE ; redefined test ok
> test
> *evaluated string*:-1: Undefined word
> 1 2 3 >>>DROP<<<
>
> It works more or less in mpe forth, but you cannot recover
> from `` 0 set-order '' . You can only type ^C .
> `` ONLY FORTH '' doesn't help. This is certainly a
> viable interpretation of the standard, making ONLY the
> best portable way to have the Forth system understand numbers
> ("denotations") only.

You have to use CATCH and restore the search order.

: within-order-execute ( i*x xt i*wid u.i -- j*x )
get-order n>r set-order catch nr> set-order throw
;
: string-to-numbers ( sd.numbers -- i*x ) ( f: -- j*r )
['] evaluate 0 within-order-execute
;
: string-to-numbers-count ( f: -- j*r )
( sd.numbers -- i*x u.i-integers u.j-floats )
fdepth >r depth 2 - >r string-to-numbers depth r> - fdepth r> -
;
: s-to-n ( sd.number -- x )
string-to-numbers-count swap 1 <> or
abort" Error: not a single integer"
;

\ test
s" 1 2 3" string-to-numbers . . . \ "3 2 1"
s" 1 2 3 also forth drop" string-to-numbers \ error

--
Ruvim

Re: EVALUATE in minimum search order

<2022May1.160159@mips.complang.tuwien.ac.at>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17781&group=comp.lang.forth#17781

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ant...@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.lang.forth
Subject: Re: EVALUATE in minimum search order
Date: Sun, 01 May 2022 14:01:59 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 57
Message-ID: <2022May1.160159@mips.complang.tuwien.ac.at>
References: <nnd$66ea20ee$7fc8e28f@5569ede25e4143de> <2022Apr30.193157@mips.complang.tuwien.ac.at> <nnd$21d44e75$1034620e@bc428715b44184cf>
Injection-Info: reader02.eternal-september.org; posting-host="30353a15bf4ccd9106f25f1968f33008";
logging-data="4858"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18VdjZrQfalqW7lDvEryfeB"
Cancel-Lock: sha1:0aXhdKCFpkQ5KxOdlQJg5v2JKXs=
X-newsreader: xrn 10.00-beta-3
 by: Anton Ertl - Sun, 1 May 2022 14:01 UTC

albert@cherry.(none) (albert) writes:
>In article <2022Apr30.193157@mips.complang.tuwien.ac.at>,
>Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>>only forth
>>s" evil-command" system
>
>That was what I wanted to prevent. So no forth-wordlist in the
>search-order containing the evil `SYSTEM command.

Does not help if you can change the search order.

>Everybody uses
>`` ONLY FORTH ''
>That is not the way the standard expects it apparently.
>You are supposed to do
>`` forth-wordlist 1 set-order ''
>because it is not guaranteed that FORTH is in the minimum search order.
>(Last time I looked.)

FORTH is SEARCH-EXT, just like ONLY.

But it does not matter whether you use FORTH, or FORTH-WORDLIST 1
SET-ORDER. It means that ONLY is not a way to prevent an attacker
from doing everything Forth can do.

>>If you want to remove all word lists from the search order, use
>>
>>0 set-order
>
>The trick^H^H^H^H technique works in gforth and mpe forth.
>: test ONLY S" 1 2 3 DROP" EVALUATE ; redefined test ok
>test
>*evaluated string*:-1: Undefined word
>1 2 3 >>>DROP<<<
>Backtrace:
>...

: test ONLY S" 1 2 3 FORTH DROP" EVALUATE ; ok
test ok 2
..s <2> 1 2 ok 2

: test1 only s\" forth s\" echo *\" system" evaluate ; cr test1
\ output: #Makefile# #timings.sc~ 2012words.fs AUTHORS ...

Now try replacing "echo" with "rm".

>It works more or less in mpe forth, but you cannot recover
>from `` 0 set-order '' .

Sure I can, and Ruvim told you how you can, too.

- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: http://www.forth200x.org/forth200x.html
EuroForth 2021: https://euro.theforth.net/2021

Re: EVALUATE in minimum search order

<b69e5292-2a9b-4ad6-8d99-f97e379c6dc1n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17830&group=comp.lang.forth#17830

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:622a:6115:b0:2f1:d8fa:84aa with SMTP id hg21-20020a05622a611500b002f1d8fa84aamr7939861qtb.689.1651939983836;
Sat, 07 May 2022 09:13:03 -0700 (PDT)
X-Received: by 2002:ad4:5c69:0:b0:45a:99cb:4c54 with SMTP id
i9-20020ad45c69000000b0045a99cb4c54mr7390003qvh.72.1651939983702; Sat, 07 May
2022 09:13:03 -0700 (PDT)
Path: i2pn2.org!i2pn.org!aioe.org!news.mixmin.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Sat, 7 May 2022 09:13:03 -0700 (PDT)
In-Reply-To: <nnd$66ea20ee$7fc8e28f@5569ede25e4143de>
Injection-Info: google-groups.googlegroups.com; posting-host=38.65.72.242; posting-account=V5nGoQoAAAC_P2U0qnxm2kC0s1jNJXJa
NNTP-Posting-Host: 38.65.72.242
References: <nnd$66ea20ee$7fc8e28f@5569ede25e4143de>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b69e5292-2a9b-4ad6-8d99-f97e379c6dc1n@googlegroups.com>
Subject: Re: EVALUATE in minimum search order
From: sdwjac...@gmail.com (S Jack)
Injection-Date: Sat, 07 May 2022 16:13:03 +0000
Content-Type: text/plain; charset="UTF-8"
 by: S Jack - Sat, 7 May 2022 16:13 UTC

On Saturday, April 30, 2022 at 7:38:56 AM UTC-5, none albert wrote:
> A do a precaution, I want that numbers are only recognized
> after ONLY, i.e. in the minimum search order, to prevent
You inspired me to implement ONLY that works with FIG vocabularies.
Readily done:
i. Create a vocabulary, VOC0, to be minimal:
forth definitions
vocabulary voc0
voc0 definitions
: fths Forth Definitions ;
fths
i. Now for the FIG part need to link the first (and only) word in
voc0 to the null word in Forth vocabulary. Note, I moved the null
word to the start of the dictionary before LIT so that only the
null word will be linked into voc0:
' lit nfa
hex
{ begin c1 over @ - while cell- repeat } e \ find null word's nfa, C1
decimal
voc0
' fths lfa ! \ link first word in voc0 to null word
fths
i. : ONLY voc0 definitions ;

That's it.
only 1 2 3 \ input numbers
fths . . . \ ==> 3 2 1 , do something with the numbers

In my enhanced interpreter I can also get enclosed strings:
only 42 "Today's number is "
fths count type . \ => Today's number is 42

May not provide much, just some savings of search time but it doesn't
cost anything. It didn't change core other than moving the null word
around. The feature can be left out and loaded when desired.

--
me

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor