39 lines
1.3 KiB
Diff
39 lines
1.3 KiB
Diff
From 9157a663d9e845e23697f598994f53f67cfef799 Mon Sep 17 00:00:00 2001
|
|
From: Tymoteusz Blazejczyk <tymoteusz.blazejczyk@intel.com>
|
|
Date: Wed, 12 Jun 2019 10:30:32 +0200
|
|
Subject: [PATCH 68/83] Fixed the fread call in the savefile.c file
|
|
|
|
Currently it was an undefined behavior (UB).
|
|
It passes wrong parameters to the fread function call (1 byte, 4 elements).
|
|
It should be 4 bytes and 1 element because the `magic` variable is a single 32-bits integer (4 bytes).
|
|
|
|
```
|
|
bytes_read = fread(pointer, number_of_bytes, number_of_elements, file);
|
|
```
|
|
|
|
On some machines the `fread()` call returned 0 with no error from the `ferror()` call with
|
|
correct and valid PCAP files.
|
|
|
|
Reference: https://en.cppreference.com/w/c/io/fread
|
|
---
|
|
savefile.c | 2 +-
|
|
1 file changed, 1 insertion(+), 1 deletion(-)
|
|
|
|
diff --git a/savefile.c b/savefile.c
|
|
index 152c917..e6404e7 100644
|
|
--- a/savefile.c
|
|
+++ b/savefile.c
|
|
@@ -359,7 +359,7 @@ pcap_fopen_offline_with_tstamp_precision(FILE *fp, u_int precision,
|
|
* Windows Sniffer, and Microsoft Network Monitor) all have magic
|
|
* numbers that are unique in their first 4 bytes.
|
|
*/
|
|
- amt_read = fread((char *)&magic, 1, sizeof(magic), fp);
|
|
+ amt_read = fread(&magic, sizeof(magic), 1, fp);
|
|
if (amt_read != sizeof(magic)) {
|
|
if (ferror(fp)) {
|
|
pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
|
--
|
|
1.8.3.1
|
|
|
|
|