[Bro] binpac const string size patch (fwd)
jmzhou.ml at gmail.com
jmzhou.ml at gmail.com
Thu Jun 7 21:48:04 PDT 2007
Oooops, sent the wrong patch. Here is the correct one. Sorry about that.
---------- Forwarded message ----------
Date: Thu, 7 Jun 2007 14:10:44 -0700 (PDT)
From: jmzhou.ml at gmail.com
Reply-To: Jingmin Zhou <zhouji at cs.ucdavis.edu>
To: bro at bro-ids.org
Subject: binpac const string size patch
Hi,
Here is a patch to fix length calculation of a const string. The problem:
if you define a const string such as "Whatever\x00" in binpac, the size of
the string becomes 8 instead of 9!
Happy hacking!
Jimmy
____________________________________________________________
The future is not set. There is no fate but what we make
for ourselves. - Terminator II, Judgment Day
------------------------------------------------------------
-------------- next part --------------
--- bro-1.2.1.orig/src/binpac/pac_type.cc 2007-05-24 13:59:24.000000000 -0700
+++ bro-1.2.1/src/binpac/pac_type.cc 2007-06-07 12:56:52.000000000 -0700
@@ -840,7 +871,13 @@
int ss = StaticSize(env);
if ( ss >= 0 )
{
- return strfmt("%d", ss);
+ if (STRING == tot())
+ {
+ StringType* sthis = (StringType*) this;
+ return sthis->GetStaticSize();
+ }
+ else
+ return strfmt("%d", ss);
}
else
{
--- bro-1.2.1.orig/src/binpac/pac_strtype.cc 2007-05-24 13:59:23.000000000 -0700
+++ bro-1.2.1/src/binpac/pac_strtype.cc 2007-06-07 12:55:38.000000000 -0700
@@ -243,12 +243,17 @@
}
}
+string StringType::GetStaticSize(Env* env)
+ {
+ return strfmt ("sizeof (%s) -1", str_->c_str());
+ }
+
string StringType::GenStringSize(Output* out_cc, Env* env,
const DataPtr& data)
{
int static_size = StaticSize(env);
if ( static_size >= 0 )
- return strfmt("%d", static_size);
+ return GenStaticSize (env);
GenDynamicSize(out_cc, env, data);
return env->RValue(string_length_var());
}
--- bro-1.2.1.orig/src/binpac/pac_strtype.h 2007-05-24 13:59:30.000000000 -0700
+++ bro-1.2.1/src/binpac/pac_strtype.h 2007-06-07 12:55:30.000000000 -0700
@@ -29,6 +29,7 @@
void DoMarkIncrementalInput();
int StaticSize(Env* env) const;
+ string GetStaticSize() const;
bool IsPointerType() const { return false; }
More information about the Bro
mailing list