]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
buffer::list::copy: complain about invalid strings
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Fri, 1 Oct 2010 18:09:30 +0000 (11:09 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Fri, 1 Oct 2010 21:12:19 +0000 (14:12 -0700)
Raise an exception when someone feeds us a "string" that has embedded
NULL characters.

Signed-off-by: Colin McCabe <colinm@hq.newdream.net>
src/include/buffer.h

index dea4cdad9a8017e5bc447c3f30912c3cbaeef05c..8bdbc8eccb03980775c942aa0f44771ad8268731 100644 (file)
@@ -87,15 +87,29 @@ class buffer {
 
 public:
   struct error : public std::exception{
-    const char *what() {
+    const char *what() const throw () {
       return "buffer::exception";
     }
   };
   struct bad_alloc : public error {
-    const char *what() { return "buffer::bad_alloc"; }
+    const char *what() const throw () {
+      return "buffer::bad_alloc";
+    }
   };
   struct end_of_buffer : public error {
-    const char *what() { return "buffer::end_of_buffer"; }
+    const char *what() const throw () {
+      return "buffer::end_of_buffer";
+    }
+  };
+  struct malformed_input : public error {
+    explicit malformed_input(const char *what) {
+      snprintf(buf, sizeof(buf), "buffer::malformed_input: %s", what);
+    }
+    const char *what() const throw () {
+      return buf;
+    }
+  private:
+    char buf[256];
   };
 
 
@@ -654,8 +668,11 @@ public:
            throw new end_of_buffer;
 
          unsigned howmuch = p->length() - p_off;
+         const char *c_str = p->c_str();
          if (len < howmuch) howmuch = len;
-         dest.append(p->c_str() + p_off, howmuch);
+         if (memchr(c_str + p_off, '\0', howmuch))
+           throw new malformed_input("embedded NULL in string!");
+         dest.append(c_str + p_off, howmuch);
 
          len -= howmuch;
          advance(howmuch);