Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Macro file comment loading "regression" #1659

Closed
pmatilai opened this issue Apr 27, 2021 · 9 comments · Fixed by #1661
Closed

Macro file comment loading "regression" #1659

pmatilai opened this issue Apr 27, 2021 · 9 comments · Fixed by #1661
Labels

Comments

@pmatilai
Copy link
Member

PR #1606 (commit 75275a8) changed macro file loading in a subtle way. Prior to that, the both macros in the following would be loaded. Now, anything coming after the comment gets silently discarded:

%xmacro1 foo
# %{
%xmacro2 bar

[pmatilai🎩︎lumikko rpm]$ ./rpm --showrc|grep xmac
-13: xmacro1 foo
[pmatilai🎩︎lumikko rpm]$

There are two ways to see this: either the contents of comment lines should be completely ignored, or this should emit an error about an unterminated macro. In spec, macros are expanded in comments too so the latter would be more consistent with that, but in macro files we're not expanding anything ever which suggests the former should be the right behavior. Thoughts? @mlschroe , others...

@pmatilai pmatilai added the bug label Apr 27, 2021
@mlschroe
Copy link
Contributor

That also happens without the patch. I think you need

%xmacro1 foo
# %{

%xmacro2 bar

I.e. an empty line that used to terminate the body.

@mlschroe
Copy link
Contributor

If you don't mind rdcl() reaching an even higher level of ugliness, an easy fix
is to add

        if (p == buf) {
            while (*p && isblank(*p))
                p++;
            if (*p != '%') {
                *q = '\0';              /* trim trailing \r, \n */
                break;
            }    
        }

right before the for (; p < q; p++) { loop.

This only does the "add continuation lines" magic for real macro definitions.

A different thing to consider is if we want to revert the "empty line ends macro definition"
change, just to make runaway macros not wreck havoc.

@pmatilai
Copy link
Member Author

That also happens without the patch.

Oh, sorry. I thought I had a minimal reproducer but it was in a bit of a haste (https://bugzilla.redhat.com/show_bug.cgi?id=1953910 is the original case) so I missed the some further subtleties. It indeed relates to the empty newlines, the real reproducer being:

%xmacro1 foo
# %{
%xmacro2 bar

%xmacro3 zzz

...and whether xmacro3 gets defined depends on whether the patch is applied or not. And with this it all actually fits together in how the heck does that patch change the behavior in the original case 😅

@pmatilai
Copy link
Member Author

If you don't mind rdcl() reaching an even higher level of ugliness, an easy fix is to add
[...]

Doesn't seem that bad to me, considering the company it's in. Perhaps a comment of the case would be in order. Care to submit a PR?

I rather like the new behavior otherwise.

@DemiMarie
Copy link
Contributor

Personally, I would prefer to emit an error here.

@pmatilai
Copy link
Member Author

No you wouldn't. Nobody expects contents of a #-commented line to affect anything coming after it, it's just absurd. It's absurd in specs too as indicated by the endless bugs and tickets filed on the behavior over the years, but at least there we have an excuse or two, and other options (%dnl).

@DemiMarie
Copy link
Contributor

No you wouldn't. Nobody expects contents of a #-commented line to affect anything coming after it, it's just absurd. It's absurd in specs too as indicated by the endless bugs and tickets filed on the behavior over the years, but at least there we have an excuse or two, and other options (%dnl).

Silently discarding everything after the comment is certainly wrong, but I agree that comment lines should not be parsed.

pmatilai added a commit to pmatilai/rpm that referenced this issue Apr 28, 2021
…1659)

Previously %{ and similar in macro file comment line would cause the
line continuation logic to trigger and silently eat macro definitions
up to the next empty line. Since 75275a8
we permit empty lines inside macro definitions, which would cause the
whole remaining file to be silently skipped (RhBug:1953910)

Only ever parse macro file lines starting with %, and add a test for
the case.

Actual patch by Michael Schroeder, testcase by undersigned.

Fixes: rpm-software-management#1659
@pmatilai
Copy link
Member Author

@mlschroe , I went ahead and created a PR from this with a testcase, hope you don't mind.

pmatilai added a commit that referenced this issue Apr 29, 2021
Previously %{ and similar in macro file comment line would cause the
line continuation logic to trigger and silently eat macro definitions
up to the next empty line. Since 75275a8
we permit empty lines inside macro definitions, which would cause the
whole remaining file to be silently skipped (RhBug:1953910)

Only ever parse macro file lines starting with %, and add a test for
the case.

Actual patch by Michael Schroeder, testcase by undersigned.

Fixes: #1659
@pmatilai
Copy link
Member Author

Oh and BTW, thanks @mlschroe for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants