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

systemd: simplify parser and fix infinite loop #24825

Merged

Conversation

giuseppe
Copy link
Member

This commit simplifies the systemd parser logic, and it solves an infinite loop when using a continuation line.

Closes: #24810

Does this PR introduce a user-facing change?

Solves an infinite loop when parsing quadlet files with a continuation line

@openshift-ci openshift-ci bot added release-note approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Dec 12, 2024
@giuseppe giuseppe force-pushed the simplify-systemd-parser branch from 6435f3a to f88a2fe Compare December 12, 2024 14:25
@giuseppe giuseppe force-pushed the simplify-systemd-parser branch 2 times, most recently from d7b6d7c to 7b72ddb Compare December 12, 2024 14:28
Copy link
Contributor

@ygalblum ygalblum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this solution is better not only by removing the extra loop, but also more easy to read than the code that kept looking at the entire file as a single string.
I did have some comments.
In addition, do you mind adding an e2e test that mimic the issue that started this discussion?

var line string
line, data = nextLine(data, 0)
for lineNr, line := range lines {
p.lineNr = lineNr + 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you're already changing the assignment to p.lineNr, I can see that it's only used for a print in parseLine. Maybe it's just simpler to pass the line as a parameter instead of maintaining it all the time

@giuseppe giuseppe force-pushed the simplify-systemd-parser branch 2 times, most recently from e01e43a to bb61a1b Compare December 12, 2024 15:42
@giuseppe giuseppe marked this pull request as draft December 12, 2024 15:45
@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 12, 2024
@giuseppe giuseppe force-pushed the simplify-systemd-parser branch from bb61a1b to 036e01b Compare December 12, 2024 15:58
@giuseppe giuseppe marked this pull request as ready for review December 12, 2024 15:58
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 12, 2024
@giuseppe giuseppe force-pushed the simplify-systemd-parser branch from 036e01b to a26a2ff Compare December 12, 2024 16:06
@giuseppe
Copy link
Member Author

@ygalblum thanks for the review. Addressed the comments and pushed a new version

This commit simplifies the systemd parser logic, and it solves an
infinite loop when using a continuation line.

Closes: containers#24810

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
@giuseppe giuseppe force-pushed the simplify-systemd-parser branch from a26a2ff to 64e94ef Compare December 12, 2024 19:45
Copy link
Contributor

@ygalblum ygalblum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

openshift-ci bot commented Dec 12, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: giuseppe, ygalblum

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK none of the files are ever parsed until you explicitly list them in the quadlet_test.go file as test case so this is a NOP I think.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, sorry I missed it.
You need to add it to the test list in quadlet_test.go. It should go in the first long table (the ones expected to succeed without dependecies)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

follow-up PR here: #24841

@rhatdan
Copy link
Member

rhatdan commented Dec 13, 2024

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Dec 13, 2024
@openshift-merge-bot openshift-merge-bot bot merged commit 3cffc6b into containers:main Dec 13, 2024
80 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. release-note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Trailing backslash causes infinite loop in quadlet generator
4 participants