-
Notifications
You must be signed in to change notification settings - Fork 57
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
multiboot2: Follow C behavior for string parsing #172
Conversation
FYI, in Rust 1.69 a new method was stabilized for converting nul-terminated strings. However, it returns a different type of error for non-terminated strings. Thus, I think using it in the (Functionally, it seems to also terminate on the string on the first NUL character too.) The following seems to work too, but is probably a breaking change due to the crate's API changes: |
Hi @A0lson , |
Can you please tell me a real-world example where this causes a problem? If a Multiboot2 bootloader puts |
Here's an example that fails in
This is not entirely hypothetical either. For example, when the "tboot" module boots an ELF-based kernel (such as Xen), it has to replace the Multiboot2 command-line string with that of the first module (holding the Xen kernel). In the case where the new command-line is shorter than the existing one, it simply relies on C-style termination and doesn't shorten the Multiboot2 tag. Of course, this may be arguable... To me, the Multiboot2 spec is clear that strings end on the NUL byte (and that it must be present). Even their example C code relies on this and doesn't care about the length of the Tag. (Even though libc is capable of dealing with non-terminated strings). While I would generally hope that protocol specifications would be language agnostic, the Multiboot specs seem to be strongly focused on the C language. Although the spec is somewhat quiet on what (if anything) may come after a NUL byte, their example code and current practical implementations (Grub, Xen, etc.) are all C-based and rely on typical NUL-terminated C string behavior. Thus, for interoperability, I think the |
Hi. Sorry, it took a while. You are right, we should follow the spec and not try to be feature-creep and support every obscure variant of wrong string encodings. |
The various strings in the Multiboot2 spec are specified as C-style zero-terminated strings. Previously, if the multiboot2 crate is handed a string with non-NUL characters present between the terminating NUL (within the tag), they were returned as well. This revision instead terminates the strings on the first NUL character, as would be typical in C handling. Although unterminated strings in Multiboot2 are technically an error, current unterminated string behavior is maintained.
The various strings in the Multiboot2 spec are specified as C-style zero-terminated strings.
Previously, if the multiboot2 crate is handed a string with non-NUL characters present between the terminating NUL (within the tag), they were returned as well.
This revision instead terminates the strings on the first NUL character, as would be typical in C handling. Although unterminated strings in Multiboot2 are technically an error, current unterminated string behavior is maintained.