Make various max packet sizes unsigned, and clean up from that.

Make some packet size variables unsigned.

Leave some others signed, because they're read with sscanf(), and
sscanf() handles string-to-unsigned conversions in the same crazy way
strtouX() routines do, wherein a leading sign is *not* an error.
Instead, cast them to unsigned after we make sure they're not negative.
This commit is contained in:
Guy Harris 2021-01-19 19:02:01 -08:00
parent 6db087ae4b
commit 64f1d09ef3
7 changed files with 13 additions and 13 deletions

View File

@ -367,14 +367,14 @@ parse_cosine_packet(FILE_T fh, wtap_rec *rec, Buffer *buf,
*err_info = g_strdup("cosine: packet header has a negative packet length");
return FALSE;
}
if (pkt_len > WTAP_MAX_PACKET_SIZE_STANDARD) {
if ((guint)pkt_len > WTAP_MAX_PACKET_SIZE_STANDARD) {
/*
* Probably a corrupt capture file; don't blow up trying
* to allocate space for an immensely-large packet.
*/
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("cosine: File has %u-byte packet, bigger than maximum of %u",
pkt_len, WTAP_MAX_PACKET_SIZE_STANDARD);
(guint)pkt_len, WTAP_MAX_PACKET_SIZE_STANDARD);
return FALSE;
}

View File

@ -175,7 +175,7 @@ read_eyesdn_rec(FILE_T fh, wtap_rec *rec, Buffer *buf, int *err,
guint8 hdr[EYESDN_HDR_LENGTH];
time_t secs;
int usecs;
int pkt_len;
guint pkt_len;
guint8 channel, direction;
guint8 *pd;

View File

@ -25,7 +25,7 @@ static gboolean hcidump_read_packet(FILE_T fh, wtap_rec *rec,
Buffer *buf, int *err, gchar **err_info)
{
struct dump_hdr dh;
int packet_size;
guint packet_size;
if (!wtap_read_bytes_or_eof(fh, &dh, DUMP_HDR_SIZE, err, err_info))
return FALSE;

View File

@ -731,7 +731,7 @@ iseries_parse_packet (wtap * wth, FILE_T fh, wtap_rec *rec,
* Check the length first, just in case it's *so* big that, after
* adding the Ethernet header length, it overflows.
*/
if (pkt_len > WTAP_MAX_PACKET_SIZE_STANDARD - 14)
if ((guint)pkt_len > WTAP_MAX_PACKET_SIZE_STANDARD - 14)
{
/*
* Probably a corrupt capture file; don't blow up trying

View File

@ -277,14 +277,14 @@ parse_netscreen_packet(FILE_T fh, wtap_rec *rec, Buffer* buf,
*err_info = g_strdup("netscreen: packet header has a negative packet length");
return FALSE;
}
if (pkt_len > WTAP_MAX_PACKET_SIZE_STANDARD) {
if ((guint)pkt_len > WTAP_MAX_PACKET_SIZE_STANDARD) {
/*
* Probably a corrupt capture file; don't blow up trying
* to allocate space for an immensely-large packet.
*/
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("netscreen: File has %u-byte packet, bigger than maximum of %u",
pkt_len, WTAP_MAX_PACKET_SIZE_STANDARD);
(guint)pkt_len, WTAP_MAX_PACKET_SIZE_STANDARD);
return FALSE;
}

View File

@ -298,14 +298,14 @@ parse_toshiba_packet(FILE_T fh, wtap_rec *rec, Buffer *buf,
*err_info = g_strdup("toshiba: packet header has a negative packet length");
return FALSE;
}
if (pkt_len > WTAP_MAX_PACKET_SIZE_STANDARD) {
if ((guint)pkt_len > WTAP_MAX_PACKET_SIZE_STANDARD) {
/*
* Probably a corrupt capture file; don't blow up trying
* to allocate space for an immensely-large packet.
*/
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("toshiba: File has %u-byte packet, bigger than maximum of %u",
pkt_len, WTAP_MAX_PACKET_SIZE_STANDARD);
(guint)pkt_len, WTAP_MAX_PACKET_SIZE_STANDARD);
return FALSE;
}

View File

@ -426,10 +426,10 @@ extern "C" {
* greater than 262144 if we don't have to, as software reading those
* files might allocate a buffer much larger than necessary, wasting memory.
*/
#define WTAP_MAX_PACKET_SIZE_STANDARD 262144
#define WTAP_MAX_PACKET_SIZE_USBPCAP (128*1024*1024)
#define WTAP_MAX_PACKET_SIZE_EBHSCR (8*1024*1024)
#define WTAP_MAX_PACKET_SIZE_DBUS (128*1024*1024)
#define WTAP_MAX_PACKET_SIZE_STANDARD 262144U
#define WTAP_MAX_PACKET_SIZE_USBPCAP (128U*1024U*1024U)
#define WTAP_MAX_PACKET_SIZE_EBHSCR (8U*1024U*1024U)
#define WTAP_MAX_PACKET_SIZE_DBUS (128U*1024U*1024U)
/*
* "Pseudo-headers" are used to supply to the clients of wiretap