mirror of
https://github.com/moparisthebest/socat
synced 2024-12-21 22:48:48 -05:00
fixed sporadic data loss on pid reuse
This commit is contained in:
parent
976d6f0b75
commit
49c0505298
5
CHANGES
5
CHANGES
@ -44,6 +44,11 @@ corrections:
|
||||
only expected broken messages, not corrupted stack (glibc 2.11.1,
|
||||
Ubuntu 10.4)
|
||||
|
||||
an internal store for child pids was susceptible to pid reuse which
|
||||
could lead to sporadic data loss when both fork option and exec address
|
||||
were used. Thanks to Tetsuya Sodo for reporting this problem and
|
||||
sending a patch
|
||||
|
||||
####################### V 1.7.1.3:
|
||||
|
||||
security:
|
||||
|
12
xio.h
12
xio.h
@ -1,5 +1,5 @@
|
||||
/* source: xio.h */
|
||||
/* Copyright Gerhard Rieger 2001-2009 */
|
||||
/* Copyright Gerhard Rieger 2001-2011 */
|
||||
/* Published under the GNU General Public License V.2, see file COPYING */
|
||||
|
||||
#ifndef __xio_h_included
|
||||
@ -402,10 +402,12 @@ extern int xioopenhelp(FILE *of, int level);
|
||||
|
||||
/* must be outside function for use by childdied handler */
|
||||
extern xiofile_t *sock1, *sock2;
|
||||
extern pid_t diedunknown1; /* child died before it is registered */
|
||||
extern pid_t diedunknown2;
|
||||
extern pid_t diedunknown3;
|
||||
extern pid_t diedunknown4;
|
||||
#define NUMUNKNOWN 4
|
||||
extern pid_t diedunknown[NUMUNKNOWN]; /* child died before it is registered */
|
||||
#define diedunknown1 (diedunknown[0])
|
||||
#define diedunknown2 (diedunknown[1])
|
||||
#define diedunknown3 (diedunknown[2])
|
||||
#define diedunknown4 (diedunknown[3])
|
||||
|
||||
extern int xiosetsigchild(xiofile_t *xfd, int (*callback)(struct single *));
|
||||
extern int xiosetchilddied(void);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* source: xioinitialize.c */
|
||||
/* Copyright Gerhard Rieger 2001-2008 */
|
||||
/* Copyright Gerhard Rieger 2001-2011 */
|
||||
/* Published under the GNU General Public License V.2, see file COPYING */
|
||||
|
||||
/* this file contains the source for the initialize function */
|
||||
@ -172,7 +172,11 @@ static int xio_nokill(xiofile_t *sock) {
|
||||
returns 0 on success or != 0 if an error occurred */
|
||||
int xio_forked_inchild(void) {
|
||||
int result = 0;
|
||||
int i;
|
||||
|
||||
for (i=0; i<NUMUNKNOWN; ++i) {
|
||||
diedunknown[i] = 0;
|
||||
}
|
||||
xiodroplocks();
|
||||
#if WITH_FIPS
|
||||
if (xio_reset_fips_mode() != 0) {
|
||||
|
25
xiosigchld.c
25
xiosigchld.c
@ -1,5 +1,5 @@
|
||||
/* source: xiosigchld.c */
|
||||
/* Copyright Gerhard Rieger 2001-2008 */
|
||||
/* Copyright Gerhard Rieger 2001-2011 */
|
||||
/* Published under the GNU General Public License V.2, see file COPYING */
|
||||
|
||||
/* this is the source of the extended child signal handler */
|
||||
@ -10,10 +10,8 @@
|
||||
|
||||
|
||||
/*!! with socat, at most 4 exec children exist */
|
||||
pid_t diedunknown1; /* child died before it is registered */
|
||||
pid_t diedunknown2;
|
||||
pid_t diedunknown3;
|
||||
pid_t diedunknown4;
|
||||
pid_t diedunknown[NUMUNKNOWN]; /* children that died before they were registered */
|
||||
size_t nextunknown;
|
||||
|
||||
|
||||
/* register for a xio filedescriptor a callback (handler).
|
||||
@ -114,19 +112,12 @@ void childdied(int signum) {
|
||||
}
|
||||
if (i == XIO_MAXSOCK) {
|
||||
Info2("childdied(%d): cannot identify child %d", signum, pid);
|
||||
if (diedunknown1 == 0) {
|
||||
diedunknown1 = pid;
|
||||
Debug("saving pid in diedunknown1");
|
||||
} else if (diedunknown2 == 0) {
|
||||
diedunknown2 = pid;
|
||||
Debug("saving pid in diedunknown2");
|
||||
} else if (diedunknown3 == 0) {
|
||||
diedunknown3 = pid;
|
||||
Debug("saving pid in diedunknown3");
|
||||
} else {
|
||||
diedunknown4 = pid;
|
||||
Debug("saving pid in diedunknown4");
|
||||
if (nextunknown == NUMUNKNOWN) {
|
||||
nextunknown = 0;
|
||||
}
|
||||
diedunknown[nextunknown++] = pid;
|
||||
Debug1("saving pid in diedunknown%u",
|
||||
nextunknown/*sic, for compatibility*/);
|
||||
}
|
||||
|
||||
if (WIFEXITED(status)) {
|
||||
|
Loading…
Reference in New Issue
Block a user