Skip to content

Commit a0a049c

Browse files
committed
rpcap: verify control socket status during reception
Signed-off-by: Kevin Boulain <[email protected]> Signed-off-by: Gabriel Ganne <[email protected]>
1 parent 7f14bee commit a0a049c

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

configure

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,7 @@ infodir
718718
docdir
719719
oldincludedir
720720
includedir
721+
runstatedir
721722
localstatedir
722723
sharedstatedir
723724
sysconfdir
@@ -816,6 +817,7 @@ datadir='${datarootdir}'
816817
sysconfdir='${prefix}/etc'
817818
sharedstatedir='${prefix}/com'
818819
localstatedir='${prefix}/var'
820+
runstatedir='${localstatedir}/run'
819821
includedir='${prefix}/include'
820822
oldincludedir='/usr/include'
821823
docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
@@ -1068,6 +1070,15 @@ do
10681070
| -silent | --silent | --silen | --sile | --sil)
10691071
silent=yes ;;
10701072

1073+
-runstatedir | --runstatedir | --runstatedi | --runstated \
1074+
| --runstate | --runstat | --runsta | --runst | --runs \
1075+
| --run | --ru | --r)
1076+
ac_prev=runstatedir ;;
1077+
-runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
1078+
| --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
1079+
| --run=* | --ru=* | --r=*)
1080+
runstatedir=$ac_optarg ;;
1081+
10711082
-sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
10721083
ac_prev=sbindir ;;
10731084
-sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
@@ -1205,7 +1216,7 @@ fi
12051216
for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \
12061217
datadir sysconfdir sharedstatedir localstatedir includedir \
12071218
oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
1208-
libdir localedir mandir
1219+
libdir localedir mandir runstatedir
12091220
do
12101221
eval ac_val=\$$ac_var
12111222
# Remove trailing slashes.
@@ -1358,6 +1369,7 @@ Fine tuning of the installation directories:
13581369
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
13591370
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
13601371
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
1372+
--runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run]
13611373
--libdir=DIR object code libraries [EPREFIX/lib]
13621374
--includedir=DIR C header files [PREFIX/include]
13631375
--oldincludedir=DIR C header files for non-gcc [/usr/include]
@@ -4619,7 +4631,7 @@ else
46194631
We can't simply define LARGE_OFF_T to be 9223372036854775807,
46204632
since some C++ compilers masquerading as C compilers
46214633
incorrectly reject 9223372036854775807. */
4622-
#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
4634+
#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
46234635
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
46244636
&& LARGE_OFF_T % 2147483647 == 1)
46254637
? 1 : -1];
@@ -4665,7 +4677,7 @@ else
46654677
We can't simply define LARGE_OFF_T to be 9223372036854775807,
46664678
since some C++ compilers masquerading as C compilers
46674679
incorrectly reject 9223372036854775807. */
4668-
#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
4680+
#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
46694681
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
46704682
&& LARGE_OFF_T % 2147483647 == 1)
46714683
? 1 : -1];
@@ -4689,7 +4701,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
46894701
We can't simply define LARGE_OFF_T to be 9223372036854775807,
46904702
since some C++ compilers masquerading as C compilers
46914703
incorrectly reject 9223372036854775807. */
4692-
#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
4704+
#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
46934705
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
46944706
&& LARGE_OFF_T % 2147483647 == 1)
46954707
? 1 : -1];
@@ -4734,7 +4746,7 @@ else
47344746
We can't simply define LARGE_OFF_T to be 9223372036854775807,
47354747
since some C++ compilers masquerading as C compilers
47364748
incorrectly reject 9223372036854775807. */
4737-
#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
4749+
#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
47384750
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
47394751
&& LARGE_OFF_T % 2147483647 == 1)
47404752
? 1 : -1];
@@ -4758,7 +4770,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
47584770
We can't simply define LARGE_OFF_T to be 9223372036854775807,
47594771
since some C++ compilers masquerading as C compilers
47604772
incorrectly reject 9223372036854775807. */
4761-
#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
4773+
#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
47624774
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
47634775
&& LARGE_OFF_T % 2147483647 == 1)
47644776
? 1 : -1];

pcap-rpcap.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,12 @@ static int pcap_read_nocb_remote(pcap_t *p, struct pcap_pkthdr *pkt_header, u_ch
416416
/*
417417
* 'fp->rmt_sockdata' has always to be set before calling the select(),
418418
* since it is cleared by the select()
419+
*
420+
* While not strictly necessary, it's best to include the control socket.
421+
* It allows us to check for a connection drop as the data socket may use UDP
422+
* and as such, is without any mean to report back any error to the client.
419423
*/
424+
FD_SET(pr->rmt_sockctrl, &rfds);
420425
FD_SET(pr->rmt_sockdata, &rfds);
421426

422427
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
@@ -439,8 +444,22 @@ static int pcap_read_nocb_remote(pcap_t *p, struct pcap_pkthdr *pkt_header, u_ch
439444
}
440445
}
441446

447+
/*
448+
* In the rpcap protocol, once the capture starts, the control socket isn't
449+
* used anymore until the capture ends.
450+
* However, it's the only way to check for connection errors
451+
* as the data socket may uses UDP.
452+
*/
453+
if (FD_ISSET(pr->rmt_sockctrl, &rfds)) {
454+
uint8 byte;
455+
const int nread = sock_recv(pr->rmt_sockctrl, pr->ctrl_ssl, &byte, sizeof(byte),
456+
SOCK_MSG_PEEK | SOCK_EOF_IS_ERROR, p->errbuf, PCAP_ERRBUF_SIZE);
457+
if (nread == -1)
458+
return -1;
459+
}
460+
442461
/* There is no data waiting, so return '0' */
443-
if (retval == 0)
462+
if (!FD_ISSET(pr->rmt_sockdata, &rfds))
444463
return 0;
445464

446465
/*

0 commit comments

Comments
 (0)