]> The Tcpdump Group git mirrors - libpcap/commitdiff
Increment first, test for overflow afterwards.
authorGuy Harris <[email protected]>
Thu, 3 Oct 2019 22:05:35 +0000 (15:05 -0700)
committerGuy Harris <[email protected]>
Thu, 3 Oct 2019 22:05:35 +0000 (15:05 -0700)
Perhaps that'll keep the Windows compiler from thinking that you can't
ever overflow a size_t by adding 12 to it, or whatever the heck it
thinks.

rpcapd/daemon.c

index 4fa40e736b860b16b2dda30d8bab9b1207c731ee..18923d8102a48755380f198e648262ffa26124cf 100644 (file)
@@ -1575,13 +1575,16 @@ daemon_AuthUserPwd(char *username, char *password, char *errbuf)
  * Make sure that the reply length won't overflow 32 bits if we add the
  * specified amount to it.  If it won't, add that amount to it.
  */
  * Make sure that the reply length won't overflow 32 bits if we add the
  * specified amount to it.  If it won't, add that amount to it.
  */
-#define CHECK_AND_INCREASE_REPLY_LEN(itemlen) \
-       if (replylen + (itemlen) < replylen) { \
+#define CHECK_AND_INCREASE_REPLY_LEN(itemlen) { \
+       size_t replylen_before = replylen; \
+\
+       replylen += (uint32)(itemlen); \
+       if (replylen < replylen_before) { \
                pcap_strlcpy(errmsgbuf, "Reply length doesn't fit in 32 bits", \
                    sizeof (errmsgbuf)); \
                goto error; \
        } \
                pcap_strlcpy(errmsgbuf, "Reply length doesn't fit in 32 bits", \
                    sizeof (errmsgbuf)); \
                goto error; \
        } \
-       replylen += (uint32)itemlen;
+}
 
 static int
 daemon_msg_findallif_req(uint8 ver, struct daemon_slpars *pars, uint32 plen)
 
 static int
 daemon_msg_findallif_req(uint8 ver, struct daemon_slpars *pars, uint32 plen)