-
Notifications
You must be signed in to change notification settings - Fork 8
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
BlkidProbe.get_value() fails with non-NUL terminated data #143
Comments
@berrange This is definitely a bug, but the documentation states the opposite about the null value
We are definitely doing the correct thing here but I need to investigate further whether we're not handling a case that we should be or whether this is a bug I need report upstream to blkid. |
I think the docs are a bit ambiguous. They say that 'len' includes the NUL terminator, but doesn't explicitly say there always will be a NUL terminator. Perhaps its also worth a bug report to util-linux first, to clarify their intended semantics for this. |
@berrange Can you give me a little bit more information on what the data is for |
One additional thing that I want to mention is that if the data you're getting back from that value is binary and contains a NULL byte partway through, that would also generate the error you're seeing above even if the binary data is indeed NULL-terminated. I will make a note to clarify that error message so it's a little bit clearer and mentions that other case. |
Ok, so I was actually wrong in saying it was a LUKS volume, as I forgot I hadn't encrypted this disk image yet. I'm actually pointing libblkid at a partiition containing an ext4 filesystem. If I single step
IOW, the data is clearly NOT NUL terminated. WIth some more probing I find this magic data is being set from a call https://github.com/util-linux/util-linux/blob/master/libblkid/src/superblocks/ext.c#L83 I notice that the I'm suspecting perhaps the Fortunately I don't actually need to access to the magic for my usage, so I can avoid the problem by simply omitting the flag that requests it. |
Thanks for the info and digging into this! So are you suggesting that we should open a bug with blkid about this inconsistency? I'm happy to do it or let you do it, whichever you prefer. |
So in the linked bug they have confirmed that some values are "raw" and nothing should be assumed about NUL terminators (or embedded NULs) |
Okay, in that case I think your suggestion to change the signature to return a byte slice is correct. I'll try to do this soon and we'll put out a minor release. |
@berrange Do you know if this affects other "value" methods in other parts of the infrastructure? If you're unsure I can just test it on LUKS2 volumes for all of the methods I find and see what breaks. |
I would expect the |
Okay, I'll run some tests. |
The
blkid_probe_get_value
method can return data without any NUL terminator, hence why its third parameter provides the length of the second parameter.The
BlkidProbe.get_value()
wrapper, however, is callingstd::ffi::CStr::from_bytes_with_nul
and this method is documented thus:IOW it is not valid to call this with a byte array that may not be NUL-terminated.
This problem can be demonstrated with the following example code
When calling this method, pointing it to a LUKS device, it always gets an errror:
because the "SBMAGIC" data is not NUL terminated.
IIUC, fixing this would require changing the signature of
get_value
so that the returned data is an sequence of bytes not a string.The text was updated successfully, but these errors were encountered: