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

pkg: fix versionStrings out of bound #1115

Merged
merged 1 commit into from
Jun 27, 2023

Conversation

chenliTW
Copy link
Contributor

add check to length of versionStrings
fix: #1086

@chenliTW chenliTW requested a review from a team as a code owner June 23, 2023 12:30
@chenliTW chenliTW requested a review from tpapagian June 23, 2023 12:30
@chenliTW chenliTW force-pushed the pr/chenlitw/fix-kernelstr-OOB branch 3 times, most recently from 4b0df17 to 8a7956c Compare June 25, 2023 04:27
Copy link
Member

@mtardy mtardy left a comment

Choose a reason for hiding this comment

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

Thanks a lot for taking the time to submit your patch! It indeed fixes the issue.

However, the code is a little bit harder to understand: an error in the os.ReadFile implies that the len(versionStrings) == 0 will trigger the "error path" with the else statement. But it's correct! Thanks

Copy link
Contributor

@kkourt kkourt left a comment

Choose a reason for hiding this comment

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

Thanks for the patch!

Could you please fix the static warning?
You can just run goimports -w pkg/kernels/kernels.go and then fold the change into your patch, and push again.

I've run it on my machine, and this is the resulting diff (it's just a whitespace change) if you want to do it manualy:

index 1e689712..2df7c419 100644
--- a/pkg/kernels/kernels.go
+++ b/pkg/kernels/kernels.go
@@ -65,7 +65,7 @@ func GetKernelVersion(kernelVersion, procfs string) (int, string, error) {
                if versionSig, err := os.ReadFile(procfs + "/version_signature"); err == nil {
                        versionStrings = strings.Fields(string(versionSig))
                }
-               
+
                if len(versionStrings) > 0 {
                        version = int(KernelStringToNumeric(versionStrings[len(versionStrings)-1]))
                        verStr = versionStrings[len(versionStrings)-1]

add check to length of versionStrings

Signed-off-by: Li Chen <chenli3792@gmail.com>
@chenliTW chenliTW force-pushed the pr/chenlitw/fix-kernelstr-OOB branch from 8a7956c to 93c3488 Compare June 27, 2023 10:49
@netlify
Copy link

netlify bot commented Jun 27, 2023

Deploy Preview for tetragon ready!

Name Link
🔨 Latest commit 93c3488
🔍 Latest deploy log https://app.netlify.com/sites/tetragon/deploys/649abec5d17d480008388fa4
😎 Deploy Preview https://deploy-preview-1115--tetragon.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@mtardy mtardy requested a review from kkourt June 27, 2023 11:34
Copy link
Contributor

@kkourt kkourt left a comment

Choose a reason for hiding this comment

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

Thank you!

@kkourt kkourt merged commit e6576a4 into cilium:main Jun 27, 2023
@mtardy
Copy link
Member

mtardy commented Jun 27, 2023

Thanks a lot @chenliTW

@chenliTW
Copy link
Contributor Author

Thank you!

Thanks

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

Successfully merging this pull request may close these issues.

Index out of range if version_signature is empty but exist
3 participants