]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib: improve sanity checks in stream_set_endp()
authorAvneesh Sachdev <avneesh@opensourcerouting.org>
Sun, 6 May 2012 00:42:43 +0000 (17:42 -0700)
committerDavid Lamparter <equinox@opensourcerouting.org>
Thu, 25 Oct 2012 17:15:58 +0000 (10:15 -0700)
  * lib/stream.c: (stream_set_endp) Add checks to make sure that the
    supplied 'endp' is within the 'size' of the stream, and that the
    current read pointer 'getp' is not beyond the specified 'endp'.

lib/stream.c

index b226a25ea544ad8601979b8cfd9a35b2dbf77ae9..ee2920e64796a8d655c3e7974c81b2e0d2466f6c 100644 (file)
@@ -219,13 +219,23 @@ stream_set_endp (struct stream *s, size_t pos)
 {
   STREAM_VERIFY_SANE(s);
 
-  if (!GETP_VALID (s, pos))
+  if (!ENDP_VALID(s, pos))
     {
       STREAM_BOUND_WARN (s, "set endp");
-      pos = s->endp;
+      return;
+    }
+
+  /*
+   * Make sure the current read pointer is not beyond the new endp.
+   */
+  if (s->getp > pos)
+    {
+      STREAM_BOUND_WARN(s, "set endp");
+      return;
     }
 
   s->endp = pos;
+  STREAM_VERIFY_SANE(s);
 }
 
 /* Forward pointer. */