]> sourceware.org Git - systemtap.git/commitdiff
Don't treat hashed numbers like strings
authorJosh Stone <jistone@redhat.com>
Wed, 27 Oct 2010 20:12:08 +0000 (13:12 -0700)
committerJosh Stone <jistone@redhat.com>
Wed, 27 Oct 2010 20:19:38 +0000 (13:19 -0700)
Valgrind noted that we were reading uninitialized memory in __GI_strlen,
and I tracked this down to our treating a number value as a char buffer,
leading to "parm_stream << [&number]".  Since it isn't a NULL-terminated
buffer, this runs away on the stack.

* hash.cxx (hash::add): Change all the numeric variants to a template,
  which lets operator<< figure the right thing for parm_stream, and then
  pass the raw value to mdfour.

hash.cxx

index a0714105d68c7283e6cb041c88818cd6a93d219d..7a5c660d18d4aba871b2c43f158381e1024e0b50 100644 (file)
--- a/hash.cxx
+++ b/hash.cxx
@@ -50,17 +50,11 @@ public:
   void start();
 
   void add(const unsigned char *buffer, size_t size);
-  void add(const int x) { add((const unsigned char *)&x, sizeof(x)); }
-  void add(const long x) { add((const unsigned char *)&x, sizeof(x)); }
-  void add(const long long x) { add((const unsigned char *)&x, sizeof(x)); }
-  void add(const unsigned int x) { add((const unsigned char *)&x, sizeof(x)); }
-  void add(const unsigned long x) { add((const unsigned char *)&x,
-                                       sizeof(x)); }
-  void add(const unsigned long long x) { add((const unsigned char *)&x,
-                                            sizeof(x)); }
+  template<typename T> void add(const T& x);
   void add(const char *s) { add((const unsigned char *)s, strlen(s)); }
   void add(const std::string& s) { add((const unsigned char *)s.c_str(),
                                       s.length()); }
+
   void add_file(const std::string& filename);
 
   void result(std::string& r);
@@ -83,6 +77,14 @@ hash::add(const unsigned char *buffer, size_t size)
 }
 
 
+template <typename T> void
+hash::add(const T& x)
+{
+  parm_stream << "," << x;
+  mdfour_update(&md4, (const unsigned char *)&x, sizeof(x));
+}
+
+
 void
 hash::add_file(const std::string& filename)
 {
This page took 0.027298 seconds and 5 git commands to generate.