From 928baf4b66c7de17457942c74aee30cc2ce9e612 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 22 Sep 2011 13:56:16 -0500 Subject: [PATCH] Fix lack of NUL-termination in to_upper/to_lower BIF's return val. --- scripts/base/frameworks/logging/main.bro | 9 ++------- src/strings.bif | 4 ++-- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/scripts/base/frameworks/logging/main.bro b/scripts/base/frameworks/logging/main.bro index 8d51286f23..9bd71bd850 100644 --- a/scripts/base/frameworks/logging/main.bro +++ b/scripts/base/frameworks/logging/main.bro @@ -192,10 +192,7 @@ function default_path_func(id: ID, path: string, rec: any) : string output = cat(output, "_", module_parts[3]); if ( 4 in module_parts && module_parts[4] != "" ) output = cat(output, sub_bytes(module_parts[4],1,1), "_", sub_bytes(module_parts[4], 2, |module_parts[4]|)); - # TODO: There seems to be some problem with the split function - # not putting \0 at the end of the string. fmt will make - # a better internal string. - return fmt("%s", to_lower(output)); + return to_lower(output); } # Example: Notice::POLICY_LOG -> "notice_policy" @@ -206,9 +203,7 @@ function default_path_func(id: ID, path: string, rec: any) : string } else { - # In case there is a logging stream in the global namespace. - # TODO: same bug as above with split and lack of terminating \0 - return fmt("%s", to_lower(id_str)); + return to_lower(id_str); } } diff --git a/src/strings.bif b/src/strings.bif index 3945569f15..1bd8f146a9 100644 --- a/src/strings.bif +++ b/src/strings.bif @@ -493,7 +493,7 @@ function to_lower%(str: string%): string *ls++ = s[i]; } - return new StringVal(new BroString(1, byte_vec(lower_s), n)); + return new StringVal(n, lower_s); %} function to_upper%(str: string%): string @@ -511,7 +511,7 @@ function to_upper%(str: string%): string *us++ = s[i]; } - return new StringVal(new BroString(1, byte_vec(upper_s), n)); + return new StringVal(n, upper_s); %} function clean%(str: string%): string