public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* regexec(3): REG_STARTEND is not documented
@ 2023-04-21  0:45 Alejandro Colomar
  2023-04-21  1:07 ` Alejandro Colomar
  2023-04-21 11:59 ` Siddhesh Poyarekar
  0 siblings, 2 replies; 7+ messages in thread
From: Alejandro Colomar @ 2023-04-21  0:45 UTC (permalink / raw)
  To: GNU C Library, Siddhesh Poyarekar; +Cc: наб


[-- Attachment #1.1: Type: text/plain, Size: 1657 bytes --]

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?

Thanks!

Alex

-- 
<http://www.alejandro-colomar.es/>
GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-04-21 11:59 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-21  0:45 regexec(3): REG_STARTEND is not documented Alejandro Colomar
2023-04-21  1:07 ` Alejandro Colomar
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

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).