-
Notifications
You must be signed in to change notification settings - Fork 60
crypto: Add a function to check for label and subsystem validity #1133
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1084,6 +1084,14 @@ class CryptoTestSetLabelUuid(CryptoTestCase): | |||||||||||||||||||||||||
| test_uuid = "4d7086c4-a4d3-432f-819e-73da03870df9" | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| def _test_set_label(self): | ||||||||||||||||||||||||||
| succ = BlockDev.crypto_luks_check_label(self.label, self.subsystem) | ||||||||||||||||||||||||||
| self.assertTrue(succ) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| with self.assertRaisesRegex(GLib.GError, "Label for LUKS must be at most 47 characters long"): | ||||||||||||||||||||||||||
| BlockDev.crypto_luks_check_label(label="a" * 48) | ||||||||||||||||||||||||||
| with self.assertRaisesRegex(GLib.GError, "Subsystem for LUKS must be at most 47 characters long"): | ||||||||||||||||||||||||||
| BlockDev.crypto_luks_check_label(subsystem="a" * 48) | ||||||||||||||||||||||||||
|
Comment on lines
+1090
to
+1093
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The tests for the new function are good, but they are missing a check for the boundary condition. A string of length 48 should be invalid. Please add tests for strings of exactly 48 characters for both
Suggested change
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| succ = BlockDev.crypto_luks_set_label(self.loop_devs[0], self.label, self.subsystem) | ||||||||||||||||||||||||||
| self.assertTrue(succ) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The length checks for both
labelandsubsystemare incorrect. According to thecryptsetupsource, the on-disk format for these fields is a 48-byte character array, which includes the null terminator. This means the maximum string length is 47 characters.The current checks (
> 48) allow strings of 48 characters, which would lead to a buffer overflow when used bycryptsetup.The checks should be changed to
> 47, and the error messages should be updated to reflect the correct maximum length.