Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"It takes all sorts of in & out-door schooling to get adapted to my kind of fooling" -- R. Frost


devel / comp.lang.tcl / Re: Expect core dumps with special regexp

SubjectAuthor
* Expect core dumps with special regexpheinrichmartin
`* Re: Expect core dumps with special regexpheinrichmartin
 `- Re: Expect core dumps with special regexpheinrichmartin

1
Expect core dumps with special regexp

<2b4f6809-c9a5-4775-9abc-5503263168fen@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19553&group=comp.lang.tcl#19553

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:600c:4fcb:b0:39c:64cd:cc89 with SMTP id o11-20020a05600c4fcb00b0039c64cdcc89mr14567443wmq.197.1655370571026;
Thu, 16 Jun 2022 02:09:31 -0700 (PDT)
X-Received: by 2002:a9d:ed7:0:b0:60c:79c6:a7ed with SMTP id
81-20020a9d0ed7000000b0060c79c6a7edmr1612863otj.105.1655370570168; Thu, 16
Jun 2022 02:09:30 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.128.87.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Thu, 16 Jun 2022 02:09:29 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=84.115.233.250; posting-account=Od2xOAoAAACEyRX3Iu5rYt4oevuoeYUG
NNTP-Posting-Host: 84.115.233.250
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <2b4f6809-c9a5-4775-9abc-5503263168fen@googlegroups.com>
Subject: Expect core dumps with special regexp
From: martin.heinrich@frequentis.com (heinrichmartin)
Injection-Date: Thu, 16 Jun 2022 09:09:31 +0000
Content-Type: text/plain; charset="UTF-8"
 by: heinrichmartin - Thu, 16 Jun 2022 09:09 UTC

Hi,
I've chased a strange core dump of Expect down to quite a simple regexp - now I am stuck and looking for advice/ideas/memories:

expect:/tmp$ set exp_library
/usr/lib/expect5.45
expect:/tmp$ set tcl_patchLevel
8.6.4
expect:/tmp$ exp_internal 0
expect:/tmp$ log_user 0
1 expect:/tmp$ spawn ls -l
10133
expect:/tmp$ expect -re {(?x)[\r\n]+?}
expect:/tmp$ expect -re {(?x)[\r\n]+?
>}
alloc: invalid block: 0x25fdfe0: ef ef 0
Aborted (core dumped)

Notes:
* A trailing newline in the expanded syntax makes a difference, but it is not the sole contributor to the core dump. (I have a more complex regexp that also ends in [\r\n]+? and that works ...)
* The regexp alone, i.e. with [regexp], has no issue.
* The core dump happens independent of whether the spawn id is open, i.e. while preparing, not while matching against the buffer.

expect:/tmp$ regexp {(?x)[\r\n]+?} foo
0 expect:/tmp$ regexp {(?x)[\r\n]+?
>} foo
0 expect:/tmp$ regexp {(?x)[\r\n]+?
>} foo\nbar\n
1

It looks like Expect has issue generating the glob-gate for that regexp.
no core dump:
expect -re {(?x)^
(foo|bar)
[\r\n]+?
} core dump:
expect -re {(?x)^
(foo)
[\r\n]+?
}

Does anyone have an idea/hint?

Re: Expect core dumps with special regexp

<0bb0ac99-7542-4556-bd47-895e9596f221n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19555&group=comp.lang.tcl#19555

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:adf:e782:0:b0:219:f719:216c with SMTP id n2-20020adfe782000000b00219f719216cmr5116160wrm.613.1655391005602;
Thu, 16 Jun 2022 07:50:05 -0700 (PDT)
X-Received: by 2002:a4a:9b84:0:b0:41b:e2a6:86ea with SMTP id
x4-20020a4a9b84000000b0041be2a686eamr2116741ooj.87.1655391004903; Thu, 16 Jun
2022 07:50:04 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.128.88.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Thu, 16 Jun 2022 07:50:04 -0700 (PDT)
In-Reply-To: <2b4f6809-c9a5-4775-9abc-5503263168fen@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=84.115.233.250; posting-account=Od2xOAoAAACEyRX3Iu5rYt4oevuoeYUG
NNTP-Posting-Host: 84.115.233.250
References: <2b4f6809-c9a5-4775-9abc-5503263168fen@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <0bb0ac99-7542-4556-bd47-895e9596f221n@googlegroups.com>
Subject: Re: Expect core dumps with special regexp
From: martin.heinrich@frequentis.com (heinrichmartin)
Injection-Date: Thu, 16 Jun 2022 14:50:05 +0000
Content-Type: text/plain; charset="UTF-8"
 by: heinrichmartin - Thu, 16 Jun 2022 14:50 UTC

On Thursday, June 16, 2022 at 11:09:34 AM UTC+2, heinrichmartin wrote:
> It looks like Expect has issue generating the glob-gate for that regexp.
> no core dump:
> expect -re {(?x)^
> (foo|bar)
> [\r\n]+?
> }
> core dump:
> expect -re {(?x)^
> (foo)
> [\r\n]+?
> }
>
> Does anyone have an idea/hint?

Actually, I have made huge progress by just writing it down for c.l.t. ... and I am answering my own question now:

The difference is (obviously) the branch "|". Expect stops generating glob-gate when a branch is discovered (retglob.c:236:/* branching is too complex */ goto error).
At this point, I have two possible workarounds: (1) do not use expanded syntax for simple regexp or (2) add a bogus branch, e.g. "(?:a|a)" for "a" or in this case "(?:\r|\n)" for "[\r\n]".

Then, I assume the issue is in retglob.c:223:
if (expanded) {
/* Expanded syntax, whitespace and comments, ignore. */
while (MATCHC (' ') ||
MATCHC (0x9) ||
MATCHC (0xa)) CHOP (1);
/* XXX not checking strlen before proceeding */
if (MATCHC ('#')) {
CHOPC (0xa);
if (strlen) CHOP (1);
continue;
}
}

The tight while-loop is safe, iff the string is \0-terminated, but afterwards: if (0 == strlen) break;

Given that I have a simple workaround, I am going to skip fix+build+verify+deploy and will work with simple syntax instead. If comments are needed, one could assemble and document the regexp in a variable before the actual expect.

HTH
Martin

Re: Expect core dumps with special regexp

<93b99e11-a7b2-4d6f-b8c2-37c3a7546588n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19556&group=comp.lang.tcl#19556

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:600c:354f:b0:39c:78c8:a854 with SMTP id i15-20020a05600c354f00b0039c78c8a854mr5469611wmq.121.1655392007823;
Thu, 16 Jun 2022 08:06:47 -0700 (PDT)
X-Received: by 2002:a05:6808:1244:b0:322:6925:3f4f with SMTP id
o4-20020a056808124400b0032269253f4fmr7990491oiv.39.1655392006819; Thu, 16 Jun
2022 08:06:46 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.128.87.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Thu, 16 Jun 2022 08:06:46 -0700 (PDT)
In-Reply-To: <0bb0ac99-7542-4556-bd47-895e9596f221n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=84.115.233.250; posting-account=Od2xOAoAAACEyRX3Iu5rYt4oevuoeYUG
NNTP-Posting-Host: 84.115.233.250
References: <2b4f6809-c9a5-4775-9abc-5503263168fen@googlegroups.com> <0bb0ac99-7542-4556-bd47-895e9596f221n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <93b99e11-a7b2-4d6f-b8c2-37c3a7546588n@googlegroups.com>
Subject: Re: Expect core dumps with special regexp
From: martin.heinrich@frequentis.com (heinrichmartin)
Injection-Date: Thu, 16 Jun 2022 15:06:47 +0000
Content-Type: text/plain; charset="UTF-8"
 by: heinrichmartin - Thu, 16 Jun 2022 15:06 UTC

On Thursday, June 16, 2022 at 4:50:09 PM UTC+2, heinrichmartin wrote:
> Given that I have a simple workaround, I am going to skip fix+build+verify+deploy and will work with simple syntax instead. If comments are needed, one could assemble and document the regexp in a variable before the actual expect.

https://core.tcl-lang.org/expect/tktview/be7d99dcc2a2f082bcdb43cc02f6d636d093699b

"Note that trailing whitespace is quite common if the regexp with expanded syntax is written like a code block inside braces across several lines, i.e. they end in newline and indentation."

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor