Prechádzať zdrojové kódy

oops... NCDStringIndex_GetBin() requires that the string contains no nulls, but ncd_get_string_id() does not verify
that. This triggers assertion failures e.g. when process_manager::start() is called with a template name which
contains nulls.

Fix it by allowing calling NCDStringIndex_GetBin() and NCDStringIndex_LookupBin() with strings that do have nulls,
but make NCDStringIndex_GetBin() fail when trying to add a new string with nulls.

ambrop7 13 rokov pred
rodič
commit
4420e952c5
1 zmenil súbory, kde vykonal 5 pridanie a 3 odobranie
  1. 5 3
      ncd/NCDStringIndex.c

+ 5 - 3
ncd/NCDStringIndex.c

@@ -81,7 +81,6 @@ static const char *static_strings[] = {
 static NCD_string_id_t do_get (NCDStringIndex *o, const char *str, size_t str_len)
 {
     ASSERT(str)
-    ASSERT(!memchr(str, '\0', str_len))
     
     NCDStringIndex_hash_key key = {str, str_len};
     NCDStringIndex__HashRef ref = NCDStringIndex__Hash_Lookup(&o->hash, o->entries, key);
@@ -93,6 +92,11 @@ static NCD_string_id_t do_get (NCDStringIndex *o, const char *str, size_t str_le
         return ref.link;
     }
     
+    if (memchr(str, '\0', str_len)) {
+        BLog(BLOG_ERROR, "cannot store strings with nulls");
+        return -1;
+    }
+    
     if (o->entries_size == o->entries_capacity) {
         if (!Array_DoubleUp(o)) {
             BLog(BLOG_ERROR, "Array_DoubleUp failed");
@@ -180,7 +184,6 @@ NCD_string_id_t NCDStringIndex_LookupBin (NCDStringIndex *o, const char *str, si
 {
     DebugObject_Access(&o->d_obj);
     ASSERT(str)
-    ASSERT(!memchr(str, '\0', str_len))
     
     NCDStringIndex_hash_key key = {str, str_len};
     NCDStringIndex__HashRef ref = NCDStringIndex__Hash_Lookup(&o->hash, o->entries, key);
@@ -203,7 +206,6 @@ NCD_string_id_t NCDStringIndex_GetBin (NCDStringIndex *o, const char *str, size_
 {
     DebugObject_Access(&o->d_obj);
     ASSERT(str)
-    ASSERT(!memchr(str, '\0', str_len))
     
     return do_get(o, str, str_len);
 }