Prevent inproper use of negative value
authorJaap Keuter <jaap.keuter@xs4all.nl>
Tue, 16 Feb 2016 23:08:07 +0000 (00:08 +0100)
committerMichael Mann <mmann78@netscape.net>
Fri, 19 Feb 2016 03:23:07 +0000 (03:23 +0000)
Coverity rightfully complains about inproper use of negative value.
maxlength special value '-1' should be handled appropriately.

Change-Id: Ie1818121e39fa668094d012980016444ca868e6e
Reviewed-on: https://code.wireshark.org/review/13978
Reviewed-by: João Valverde <j@v6e.pt>
Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
epan/tvbuff.c

index 12378e644139135f1353a2fed555990465614c2d..8cf6a0e8b596414bcc04b72b49477696e1fd0ab0 100644 (file)
@@ -1870,10 +1870,10 @@ tvb_find_guint8(tvbuff_t *tvb, const gint offset, const gint maxlength, const gu
                THROW(exception);
 
        /* Only search to end of tvbuff, w/o throwing exception. */
-       if (limit > (guint) maxlength) {
+       if (maxlength >= 0 && limit > (guint) maxlength) {
                /* Maximum length doesn't go past end of tvbuff; search
                   to that value. */
-               limit = maxlength;
+               limit = (guint) maxlength;
        }
 
        /* If we have real data, perform our search now. */