Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
radsecproxy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Fabian Mauchle
radsecproxy
Commits
7348baca
Commit
7348baca
authored
Sep 13, 2016
by
Fabian Mauchle
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix tcp/tls accept race condition
parent
77223885
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
5 deletions
+14
-5
tcp.c
tcp.c
+8
-4
tls.c
tls.c
+6
-1
No files found.
tcp.c
View file @
7348baca
...
...
@@ -135,7 +135,7 @@ int tcpconnect(struct server *server, struct timeval *when, int timeout, char *t
/* returns 0 on timeout, -1 on error and num if ok */
int
tcpreadtimeout
(
int
s
,
unsigned
char
*
buf
,
int
num
,
int
timeout
)
{
int
ndesc
,
cnt
,
len
;
fd_set
readfds
,
writefds
;
fd_set
readfds
;
struct
timeval
timer
;
if
(
s
<
0
)
...
...
@@ -144,12 +144,11 @@ int tcpreadtimeout(int s, unsigned char *buf, int num, int timeout) {
for
(
len
=
0
;
len
<
num
;
len
+=
cnt
)
{
FD_ZERO
(
&
readfds
);
FD_SET
(
s
,
&
readfds
);
writefds
=
readfds
;
if
(
timeout
)
{
timer
.
tv_sec
=
timeout
;
timer
.
tv_usec
=
0
;
}
ndesc
=
select
(
s
+
1
,
&
readfds
,
&
writefds
,
NULL
,
timeout
?
&
timer
:
NULL
);
ndesc
=
select
(
s
+
1
,
&
readfds
,
NULL
,
NULL
,
timeout
?
&
timer
:
NULL
);
if
(
ndesc
<
1
)
return
ndesc
;
...
...
@@ -322,6 +321,7 @@ void *tcpservernew(void *arg) {
struct
client
*
client
;
s
=
*
(
int
*
)
arg
;
free
(
arg
);
if
(
getpeername
(
s
,
(
struct
sockaddr
*
)
&
from
,
&
fromlen
))
{
debug
(
DBG_DBG
,
"tcpservernew: getpeername failed, exiting"
);
goto
exit
;
...
...
@@ -350,6 +350,7 @@ exit:
void
*
tcplistener
(
void
*
arg
)
{
pthread_t
tcpserverth
;
int
s
,
*
sp
=
(
int
*
)
arg
;
int
*
s_arg
;
struct
sockaddr_storage
from
;
socklen_t
fromlen
=
sizeof
(
from
);
...
...
@@ -361,8 +362,11 @@ void *tcplistener(void *arg) {
debug
(
DBG_WARN
,
"accept failed"
);
continue
;
}
if
(
pthread_create
(
&
tcpserverth
,
&
pthread_attr
,
tcpservernew
,
(
void
*
)
&
s
))
{
s_arg
=
malloc
(
sizeof
(
int
));
*
s_arg
=
s
;
if
(
pthread_create
(
&
tcpserverth
,
&
pthread_attr
,
tcpservernew
,
(
void
*
)
s_arg
))
{
debug
(
DBG_ERR
,
"tcplistener: pthread_create failed"
);
free
(
s_arg
);
shutdown
(
s
,
SHUT_RDWR
);
close
(
s
);
continue
;
...
...
tls.c
View file @
7348baca
...
...
@@ -402,6 +402,7 @@ void *tlsservernew(void *arg) {
struct
tls
*
accepted_tls
=
NULL
;
s
=
*
(
int
*
)
arg
;
free
(
arg
);
if
(
getpeername
(
s
,
(
struct
sockaddr
*
)
&
from
,
&
fromlen
))
{
debug
(
DBG_DBG
,
"tlsservernew: getpeername failed, exiting"
);
goto
exit
;
...
...
@@ -463,6 +464,7 @@ exit:
void
*
tlslistener
(
void
*
arg
)
{
pthread_t
tlsserverth
;
int
s
,
*
sp
=
(
int
*
)
arg
;
int
*
s_arg
;
struct
sockaddr_storage
from
;
socklen_t
fromlen
=
sizeof
(
from
);
...
...
@@ -474,8 +476,11 @@ void *tlslistener(void *arg) {
debug
(
DBG_WARN
,
"accept failed"
);
continue
;
}
if
(
pthread_create
(
&
tlsserverth
,
&
pthread_attr
,
tlsservernew
,
(
void
*
)
&
s
))
{
s_arg
=
malloc
(
sizeof
(
int
));
*
s_arg
=
s
;
if
(
pthread_create
(
&
tlsserverth
,
&
pthread_attr
,
tlsservernew
,
(
void
*
)
s_arg
))
{
debug
(
DBG_ERR
,
"tlslistener: pthread_create failed"
);
free
(
s_arg
);
shutdown
(
s
,
SHUT_RDWR
);
close
(
s
);
continue
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment