ソースを参照

Make AmlName components private, disallow empty names in from_components

This should more explicitly check that we're not creating empty AmlNames,
which is breaking various assumptions in the namespace implementation
during fuzzing, but the source of the empty names is proving tricky to
track down.
Isaac Woods 4 年 前
コミット
e8a6c050b4
2 ファイル変更9 行追加4 行削除
  1. 3 3
      aml/src/name_object.rs
  2. 6 1
      aml/src/namespace.rs

+ 3 - 3
aml/src/name_object.rs

@@ -79,14 +79,14 @@ where
     let root_name_string = opcode(ROOT_CHAR).then(name_path()).map(|((), ref name_path)| {
         let mut name = alloc::vec![NameComponent::Root];
         name.extend_from_slice(name_path);
-        Ok(AmlName(name))
+        Ok(AmlName::from_components(name))
     });
 
     let prefix_path =
         take_while(opcode(PREFIX_CHAR)).then(name_path()).map(|(num_prefix_chars, ref name_path)| {
             let mut name = alloc::vec![NameComponent::Prefix; num_prefix_chars];
             name.extend_from_slice(name_path);
-            Ok(AmlName(name))
+            Ok(AmlName::from_components(name))
         });
 
     // TODO: combinator to select a parser based on a peeked byte?
@@ -105,7 +105,7 @@ where
                         return Err(AmlError::EmptyNamesAreInvalid);
                     }
 
-                    Ok(AmlName(path))
+                    Ok(AmlName::from_components(path))
                 })
                 .parse(input, context),
         }

+ 6 - 1
aml/src/namespace.rs

@@ -370,7 +370,7 @@ impl fmt::Debug for Namespace {
 }
 
 #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
-pub struct AmlName(pub(crate) Vec<NameComponent>);
+pub struct AmlName(Vec<NameComponent>);
 
 impl AmlName {
     pub fn root() -> AmlName {
@@ -381,6 +381,11 @@ impl AmlName {
         AmlName(alloc::vec![NameComponent::Segment(seg)])
     }
 
+    pub fn from_components(components: Vec<NameComponent>) -> AmlName {
+        assert!(components.len() > 0);
+        AmlName(components)
+    }
+
     /// Convert a string representation of an AML name into an `AmlName`.
     pub fn from_str(mut string: &str) -> Result<AmlName, AmlError> {
         if string.len() == 0 {