From: Alejandro Colomar <alx.manpages@gmail.com>
To: GNU C Library <libc-alpha@sourceware.org>,
Siddhesh Poyarekar <siddhesh@gotplt.org>
Cc: наб <nabijaczleweli@nabijaczleweli.xyz>
Subject: Re: regexec(3): REG_STARTEND is not documented
Date: Fri, 21 Apr 2023 03:07:00 +0200 [thread overview]
Message-ID: <a4a4b86d-6ae0-958c-9771-fe82fc243c73@gmail.com> (raw)
In-Reply-To: <0de87674-1b35-8dc8-7d2b-8dacd6b015ff@gmail.com>
[-- Attachment #1.1: Type: text/plain, Size: 2282 bytes --]
On 4/21/23 02:45, Alejandro Colomar wrote:
> Hi Siddhesh,
>
> It seems the glibc manual doesn't cover REG_STARTEND. We're having
> some discussion about it, while we're improving the manual page, and
> we have some slight disagreement about what are the constraints for
> nmatch and pmatch when REG_STARTEND is specified.
>
> Since this is a BSD extension, not in POSIX, we can't refer to the
> standard. And since glibc doesn't document it, I can't know for
> sure your intention.
>
> I'm not sure how much we should rely on implementation details, and
> if those will hold forever, or _FORTIFY_SOURCE and the like are
> allowed to constrain some current details.
>
> The discussion is in this thread, if you want to read it entirely:
> <https://lore.kernel.org/linux-man/09bda4f5-ab6f-a369-ad36-0779dc3749b4@gmail.com/T/#m7dd7771072df3be97bc831f581dc7bfea684197d>
>
> The question is:
>
> If REG_STARTEND was specified _and_ REG_NOSUB was also specified,
> regexec(3) will read from pmatch[0] and will effectively ignore
> nmatch (the number of elements in pmatch[]), since it won't write
> to pmatch[] at all.
>
> Is the following call valid, or is it UB?
>
> regmatch_t pmatch = {
> .rm_so = string,
> .rm_eo = string + 42, // Assume this offset is valid
> };
>
> regexec(preg, string, 0, pmatch, REG_NOSUB | REG_STARTEND);
>
> How about this?
>
> regexec(preg, string, 999, pmatch, REG_NOSUB | REG_STARTEND);
>
>
> Current implementations will work, because nmatch is effectively
> ignored. But is it intended to be this way, or just an implementation
> detail?
Here's a related question:
regmatch_t pmatch = {
.rm_so = string,
.rm_eo = string + 42, // Assume this offset is valid
};
regexec(preg, string, 0, pmatch, REG_STARTEND);
Should regexec(3) write to the 1st element in pmatch[] because it knows
it exists (otherwise the call would be UB because it needs to read it)?
Or is passing 0 in nmatch effectively another way of performing
REG_NOSUB behavior without actually using the flag?
>
> Thanks!
>
> Alex
>
--
<http://www.alejandro-colomar.es/>
GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2023-04-21 1:07 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-21 0:45 Alejandro Colomar
2023-04-21 1:07 ` Alejandro Colomar [this message]
2023-04-21 1:15 ` наб
2023-04-21 1:28 ` Alejandro Colomar
2023-04-21 1:41 ` наб
2023-04-21 1:47 ` Alejandro Colomar
2023-04-21 11:59 ` Siddhesh Poyarekar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a4a4b86d-6ae0-958c-9771-fe82fc243c73@gmail.com \
--to=alx.manpages@gmail.com \
--cc=libc-alpha@sourceware.org \
--cc=nabijaczleweli@nabijaczleweli.xyz \
--cc=siddhesh@gotplt.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).