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

Bug in is_nm_handling() #487

Closed
RN97 opened this issue Sep 16, 2024 · 2 comments
Closed

Bug in is_nm_handling() #487

RN97 opened this issue Sep 16, 2024 · 2 comments

Comments

@RN97
Copy link
Contributor

RN97 commented Sep 16, 2024

Hey,

I recently found a bug in the is_nm_handling() function in the grep statement.

is_nm_handling ()
 {
      LANG=C nmcli -t --fields device,state dev status 2>/dev/null | grep -q "^\(${1}:connected\)\|\(${1}:connecting.*\)$"
 }

From the above, you will notice that the "^" anchor is applied to the "connected" case and does not apply to the "connecting" case in the grep due to the way the brackets () are placed. This can cause the grep statement to incorrectly return a match.

For ex: When trying to check for eth0 using is_nm_handling(), "bondeth0:connecting" would also match the grep and return incorrectly.

rn97@mac:~$ echo bondeth0:connecting | grep "^\(eth0:connected\)\|\(eth0:connecting.*\)$"
bondeth0:connecting
rn97@mac:~$

Here is my proposed fix for this issue.

is_nm_handling ()
 {
-    LANG=C nmcli -t --fields device,state dev status 2>/dev/null | grep -q "^\(${1}:connected\)\|\(${1}:connecting.*\)$"
+    LANG=C nmcli -t --fields device,state dev status 2>/dev/null | grep -q "^\(${1}:connected\|${1}:connecting.*\)$"
 }

Thanks

@lnykryn
Copy link
Member

lnykryn commented Sep 16, 2024

Yeah, the current regexp does not look correct. Can you submit the change as a pull request?

@RN97
Copy link
Contributor Author

RN97 commented Sep 18, 2024

Created a pull request for the above issue.

#488

@lnykryn lnykryn closed this as completed Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants