git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2] cvsserver: avoid precedence problem between ! and %s

From
Junio C Hamano <gitster@pobox.com>
Date
May 21, 2025, 17:03 UTC
Message-ID
<xmqq1pshc2vs.fsf@gitster.g>
In-Reply-To
<xmqqh61ear4s.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
Show 12 quoted lines
> "Ondřej Pohořelský via GitGitGadget" <gitgitgadget@gmail.com>
> writes:
>
>> From: =?UTF-8?q?Ond=C5=99ej=20Poho=C5=99elsk=C3=BD?= <opohorel@redhat.com>
>>
>> With perl-5.41.4 and newer, git-cvsserver fails to build because of
>> possible precedence problem[0]
>
> What is the exact symptom?  As Perl is not a language to compile and
> run separately, "fails to build" does not look like what exactly is
> going on.  "gives a warning and then refuses to run"?  "gives a warning
> before running"?  Something else?

Stepping back a bit, the original that the new warning complains about is this:

-    if(! $refName=~/^[1-9][0-9]*(\.[1-9][0-9]*)*$/)

And the complaint is that due to operator binding precedence, this does

    (!$refname) =~ /pattern/

Unless the behaviour has changed as well as warning, which is highly unlikely, doesn't it mean that the code was wrong, with or without the warning, all along? The intent of the code was to see if the refname conformed to dotted decimal, and if it does not, the refname gets munged in the block guarded by that if (condition). But the condition was a total nonsense. !$refname would most likely to be an empty string (unless $refname contains '0' or an empty string), which would not match the /^[1-9][0-9]*(\.[1-9][0-9]*)*$/ pattern, so we probably have always munged the $refName in escapeRefName sub.

Which I do not see used anywhere in the program, though. There is a call to unescapeRefname method, but it seems to me that escapeRefName is never called.

What made you send a patch for this program? Do you or anybody you know use git-cvsserver? Unless I am reading the program incorrectly, despite the claim in front of that escapeRefName sub that we avoid sending a tag whose name is not something CVS would be happy with, we did not sanitize the refs and relied solely on the users' repository to use only safe characters in the refs to keep CVS clients happy, and the fact that this expression used as if() condition is totally broken does not really make any difference, since it is in an unused sub. I have to wonder if (1) it is a better fix to just remove the unused sub, and/or (2) perhaps nobody uses cvsserver to allow cvs clients to talk to a Git repository?

Show 6 quoted lines
>> Added parentheses avoid this issue.
>
> We phrase such "this is how the patch addresses the issue" statement
> in imperative, as if we are telling the codebase to become-like-so,
> e.g., "Enclose the pattern matching =~ in parentheses to force the
> right order of binding", or something like that.
Previous: Junio C HamanoNext: Ondrej Pohorelsky
Message 6 of 21 in “cvsserver: avoid precedence problem between ! and %s”
  1. cvsserver: avoid precedence problem between ! and %sOndřej Pohořelský via GitGitGadget, May 21, 2025
  2. Kristoffer HaugsbakkMay 21, 2025
  3. cvsserver: avoid precedence problem between ! and %sOndřej Pohořelský via GitGitGadget, May 21, 2025
  4. Junio C HamanoMay 21, 2025
  5. Junio C HamanoMay 21, 2025
  6. Junio C HamanoMay 21, 2025
  7. Ondrej PohorelskyMay 22, 2025
  8. Junio C HamanoMay 22, 2025
  9. Jeff KingMay 22, 2025
  10. Todd ZullingerMay 22, 2025
  11. Junio C HamanoMay 22, 2025
  12. Matthew OgilvieMay 23, 2025
  13. Junio C HamanoMay 23, 2025
  14. Ondrej PohorelskyMay 26, 2025
  15. Junio C HamanoMay 27, 2025
  16. cvsserver: avoid precedence problem between ! and %sOndřej Pohořelský via GitGitGadget, May 22, 2025
  17. cvsserver: remove unused escapeRefName functionOndřej Pohořelský via GitGitGadget, May 26, 2025
  18. Junio C HamanoMay 27, 2025
  19. Junio C HamanoMay 21, 2025
  20. brian m. carlsonMay 21, 2025
  21. Ondrej PohorelskyMay 22, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.