tvb: check_offset_length() can calculate remaining length, use it.

svn path=/trunk/; revision=51081
This commit is contained in:
Jakub Zawadzki 2013-08-01 16:54:22 +00:00
parent 565211c938
commit 10e40c1638
1 changed files with 7 additions and 11 deletions

View File

@ -1510,16 +1510,15 @@ gint
tvb_find_guint8(tvbuff_t *tvb, const gint offset, const gint maxlength, const guint8 needle)
{
const guint8 *result;
guint abs_offset, junk_length;
guint abs_offset;
guint tvbufflen;
guint limit;
DISSECTOR_ASSERT(tvb && tvb->initialized);
check_offset_length(tvb, offset, 0, &abs_offset, &junk_length);
check_offset_length(tvb, offset, -1, &abs_offset, &tvbufflen);
/* Only search to end of tvbuff, w/o throwing exception. */
tvbufflen = tvb_length_remaining(tvb, abs_offset);
if (maxlength == -1) {
/* No maximum length specified; search to end of tvbuff. */
limit = tvbufflen;
@ -1566,16 +1565,15 @@ gint
tvb_pbrk_guint8(tvbuff_t *tvb, const gint offset, const gint maxlength, const guint8 *needles, guchar *found_needle)
{
const guint8 *result;
guint abs_offset, junk_length;
guint abs_offset;
guint tvbufflen;
guint limit;
DISSECTOR_ASSERT(tvb && tvb->initialized);
check_offset_length(tvb, offset, 0, &abs_offset, &junk_length);
check_offset_length(tvb, offset, -1, &abs_offset, &tvbufflen);
/* Only search to end of tvbuff, w/o throwing exception. */
tvbufflen = tvb_length_remaining(tvb, abs_offset);
if (maxlength == -1) {
/* No maximum length specified; search to end of tvbuff. */
limit = tvbufflen;
@ -2396,11 +2394,12 @@ static gint
_tvb_get_nstringz(tvbuff_t *tvb, const gint offset, const guint bufsize, guint8* buffer, gint *bytes_copied)
{
gint stringlen;
guint abs_offset, junk_length;
guint abs_offset;
gint limit, len;
gboolean decreased_max = FALSE;
check_offset_length(tvb, offset, 0, &abs_offset, &junk_length);
/* Only read to end of tvbuff, w/o throwing exception. */
check_offset_length(tvb, offset, -1, &abs_offset, &len);
/* There must at least be room for the terminating NUL. */
DISSECTOR_ASSERT(bufsize != 0);
@ -2412,9 +2411,6 @@ _tvb_get_nstringz(tvbuff_t *tvb, const gint offset, const guint bufsize, guint8*
return 0;
}
/* Only read to end of tvbuff, w/o throwing exception. */
len = tvb_length_remaining(tvb, abs_offset);
/* check_offset_length() won't throw an exception if we're
* looking at the byte immediately after the end of the tvbuff. */
if (len == 0) {