Bladeren bron

Merge pull request #153 from rust-osdev/dev5

multiboot2: builder: add terminating null-bytes to tags that hold a string
Philipp Schuster 1 jaar geleden
bovenliggende
commit
7ba23b68bd
3 gewijzigde bestanden met toevoegingen van 12 en 3 verwijderingen
  1. 4 1
      multiboot2/src/boot_loader_name.rs
  2. 4 1
      multiboot2/src/command_line.rs
  3. 4 1
      multiboot2/src/module.rs

+ 4 - 1
multiboot2/src/boot_loader_name.rs

@@ -25,7 +25,10 @@ impl BootLoaderNameTag {
     #[cfg(feature = "builder")]
     pub fn new(name: &str) -> Box<Self> {
         let mut bytes: Vec<_> = name.bytes().collect();
-        bytes.push(0);
+        if !bytes.ends_with(&[0]) {
+            // terminating null-byte
+            bytes.push(0);
+        }
         boxed_dst_tag(TagType::BootLoaderName, &bytes)
     }
 

+ 4 - 1
multiboot2/src/command_line.rs

@@ -32,7 +32,10 @@ impl CommandLineTag {
     #[cfg(feature = "builder")]
     pub fn new(command_line: &str) -> Box<Self> {
         let mut bytes: Vec<_> = command_line.bytes().collect();
-        bytes.push(0);
+        if !bytes.ends_with(&[0]) {
+            // terminating null-byte
+            bytes.push(0);
+        }
         boxed_dst_tag(TagType::Cmdline, &bytes)
     }
 

+ 4 - 1
multiboot2/src/module.rs

@@ -30,7 +30,10 @@ impl ModuleTag {
     #[cfg(feature = "builder")]
     pub fn new(start: u32, end: u32, cmdline: &str) -> Box<Self> {
         let mut cmdline_bytes: Vec<_> = cmdline.bytes().collect();
-        cmdline_bytes.push(0);
+        if !cmdline_bytes.ends_with(&[0]) {
+            // terminating null-byte
+            cmdline_bytes.push(0);
+        }
         let start_bytes = start.to_le_bytes();
         let end_bytes = end.to_le_bytes();
         let mut content_bytes = [start_bytes, end_bytes].concat();