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

fix(fcoe-uefi): exit early on empty vlan #2379

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pvalena
Copy link
Contributor

@pvalena pvalena commented Jun 7, 2023

Exit early in case get_fcoe_boot_vlan exits with error or just an empty string, instead of producing invalid config entry.

Changes

Just handling a corner-case when vlan is empty; this should skip to another vlan if present.

Checklist

  • I have tested it locally
  • I have reviewed and updated any documentation if relevant
  • I am providing new code and test(s) for it

@github-actions github-actions bot added fcoe-uefi Issues related to the fcoe-uefi module modules Issue tracker for all modules labels Jun 7, 2023
@pvalena pvalena marked this pull request as draft June 7, 2023 20:46
@pvalena
Copy link
Contributor Author

pvalena commented Jun 7, 2023

I have tested the snippet, but I'm unable to test in dracut, as I lack the HW / setup.

@pvalena pvalena marked this pull request as ready for review June 7, 2023 20:49
@LaszloGombos
Copy link
Collaborator

CC @mwilck

@stale
Copy link

stale bot commented Jul 14, 2023

This issue is being marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. If this is still an issue in the latest release of Dracut and you would like to keep it open please comment on this issue within the next 7 days. Thank you for your contributions.

@stale stale bot added the stale communication is stuck label Jul 14, 2023
@stale stale bot closed this Aug 9, 2023
@mwilck
Copy link
Contributor

mwilck commented Aug 10, 2023

The code in question is obviously broken. But the fix is broken, too. Instead of combining several if statements and a case statement, the handling of $vlan should be done in a single case clause.

@LaszloGombos, sorry I saw this too late. Please reopen. I have no permission to do this.

@lnykryn lnykryn reopened this Aug 10, 2023
@stale stale bot removed the stale communication is stuck label Aug 10, 2023
@mwilck
Copy link
Contributor

mwilck commented Aug 10, 2023

@pvalena, could you update the PR as indicated above?

@pvalena
Copy link
Contributor Author

pvalena commented Aug 10, 2023

@pvalena, could you update the PR as indicated above?

Will do. Not sure why I didn't cover it in the case...

@pvalena
Copy link
Contributor Author

pvalena commented Sep 6, 2023

@mwilck PTAL.

@mwilck
Copy link
Contributor

mwilck commented Sep 6, 2023

Thanks! Can you elmininate the if statement entirely, please?

@pvalena
Copy link
Contributor Author

pvalena commented Sep 6, 2023

Sure thing... this should have identical behaviour.

@LaszloGombos
Copy link
Collaborator

@pvalena please check the lint error. Thanks !

@pvalena
Copy link
Contributor Author

pvalena commented Sep 6, 2023

Just shfmt whitespace change... fixed.

Copy link
Contributor

@mwilck mwilck left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

Copy link
Member

@aafeijoo-suse aafeijoo-suse left a comment

Choose a reason for hiding this comment

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

Can get_fcoe_boot_vlan return 1

while :; do
type=$(getbyte) || return 1
subtype=$(getbyte) || return 1
len=$(getword) || return 1

after printing some value?

0314)
# VLAN
printf "%d" "$(getword)"
;;

i.e., in the next loop iteration. If the answer is "no", the patch is ok.

@mwilck
Copy link
Contributor

mwilck commented Sep 22, 2023

Can get_fcoe_boot_vlan return 1

@aafeijoo-suse, I don't understand the question. Neither the current code nor the patched code check the return value of get_fcoe_boot_vlan(), so the case that you are concerned about has never been taken into account. The empty string is not a valid VLAN identifier and as such, exiting early is justified.

I can't see that Pavel's patch would cause a regression.

If your intention is to improve this code further, you might as well stumble upon the [0-9]*) clause in the case statement, which is unclean because it would accept something like 5foo, which is not a valid VLAN number.

@aafeijoo-suse
Copy link
Member

Can get_fcoe_boot_vlan return 1

@aafeijoo-suse, I don't understand the question. Neither the current code nor the patched code check the return value of get_fcoe_boot_vlan(), so the case that you are concerned about has never been taken into account. The empty string is not a valid VLAN identifier and as such, exiting early is justified.

I just read what he tries to solve in the commit message: "Exit early in case get_fcoe_boot_vlan exits with error or just an empty string".
Of course, he is already improving the current code.

@mwilck
Copy link
Contributor

mwilck commented Sep 22, 2023

I guess we could write

    vlan=$(get_fcoe_boot_vlan "$1") || return 1
    case $vlan in
    ...

I feel uncomfortable wrt the return value of assignments in general, but this should work.

@aafeijoo-suse, would you be fine with that?

@aafeijoo-suse
Copy link
Member

I guess we could write

    vlan=$(get_fcoe_boot_vlan "$1") || return 1
    case $vlan in
    ...

I feel uncomfortable wrt the return value of assignments in general, but this should work.

@aafeijoo-suse, would you be fine with that?

Sure. Or just changing the commit message would be enough :)

@mwilck
Copy link
Contributor

mwilck commented Sep 22, 2023

@pvalena would you change the code as indicated above?

@pvalena
Copy link
Contributor Author

pvalena commented Sep 24, 2023

Sure, let's enhance it further. Sorry about the forgotten commit message :) will clear things up.

@LaszloGombos LaszloGombos added this to the dracut-061 milestone Oct 30, 2023
Exit early in case get_fcoe_boot_vlan exits with error or just an empty string,
instead of producing invalid config entry.
@pvalena
Copy link
Contributor Author

pvalena commented Oct 31, 2023

Rebased, fixed as suggested. Sorry it has taken so long :).

Copy link
Member

@aafeijoo-suse aafeijoo-suse left a comment

Choose a reason for hiding this comment

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

Rebased, fixed as suggested. Sorry it has taken so long :).

No problem, it would have been enough to amend the commit message.

Copy link
Contributor

@mwilck mwilck left a comment

Choose a reason for hiding this comment

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

LGTM

pvalena added a commit to pvalena/dracut-rhel9 that referenced this pull request Nov 14, 2023
Exit early in case get_fcoe_boot_vlan exits with error or just an empty string,
instead of producing invalid config entry.

(Cherry-picked commit: 45fc8df1cf3fdf9726efda4d26c7cccb9e6aedd2
  PR: dracutdevs/dracut#2379)

Resolves: RHEL-14251
pvalena added a commit to redhat-plumbers/dracut-rhel9 that referenced this pull request Nov 14, 2023
Exit early in case get_fcoe_boot_vlan exits with error or just an empty string,
instead of producing invalid config entry.

(Cherry-picked commit: 45fc8df1cf3fdf9726efda4d26c7cccb9e6aedd2
  PR: dracutdevs/dracut#2379)

Resolves: RHEL-14251
@aafeijoo-suse aafeijoo-suse removed this from the dracut-061 milestone Nov 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Our bugs fcoe-uefi Issues related to the fcoe-uefi module modules Issue tracker for all modules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants