mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Fix unsafe and inefficient uses of copy_string
Add a new overload to `copy_string` that takes the input characters plus size. The new overload avoids inefficient scanning of the input for the null terminator in cases where we know the size beforehand. Furthermore, this overload *must* be used when dealing with input character sequences that may have no null terminator, e.g., when the input is from a `std::string_view` object.
This commit is contained in:
parent
4eb1b71d1b
commit
cebb85b1e8
25 changed files with 85 additions and 56 deletions
|
@ -434,15 +434,14 @@ static std::vector<std::string> get_script_signature_files() {
|
|||
std::vector<std::string> rval;
|
||||
|
||||
// Parse rule files defined on the script level.
|
||||
char* script_signature_files = util::copy_string(id::find_val("signature_files")->AsString()->CheckString());
|
||||
auto script_signature_files = id::find_val("signature_files")->AsStringVal()->ToStdString();
|
||||
|
||||
char* tmp = script_signature_files;
|
||||
char* tmp = script_signature_files.data();
|
||||
char* s;
|
||||
while ( (s = strsep(&tmp, " \t")) )
|
||||
if ( *s )
|
||||
rval.emplace_back(s);
|
||||
|
||||
delete[] script_signature_files;
|
||||
return rval;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue