Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main
Synchronet
Commits
6ae0d084
Commit
6ae0d084
authored
22 years ago
by
rswindell
Browse files
Options
Downloads
Patches
Plain Diff
Eliminated use of getaddrinfo() in ftp_login_session (causing segfault
on some Linux installations).
parent
c3cbd93c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/sbbs3/install/ftpio.c
+48
-42
48 additions, 42 deletions
src/sbbs3/install/ftpio.c
with
48 additions
and
42 deletions
src/sbbs3/install/ftpio.c
+
48
−
42
View file @
6ae0d084
...
...
@@ -550,63 +550,69 @@ cmd(FTP_t ftp, const char *fmt, ...)
return
i
;
}
static
u_long
resolve_ip
(
char
*
addr
)
{
HOSTENT
*
host
;
char
*
p
;
if
(
*
addr
==
0
)
return
(
INADDR_NONE
);
for
(
p
=
addr
;
*
p
;
p
++
)
if
(
*
p
!=
'.'
&&
!
isdigit
(
*
p
))
break
;
if
(
!
(
*
p
))
return
(
inet_addr
(
addr
));
if
((
host
=
gethostbyname
(
addr
))
==
NULL
)
return
(
INADDR_NONE
);
return
(
*
((
ulong
*
)
host
->
h_addr_list
[
0
]));
}
static
int
ftp_login_session
(
FTP_t
ftp
,
char
*
host
,
char
*
user
,
char
*
passwd
,
int
port
,
int
verbose
)
{
char
pbuf
[
10
];
struct
addrinfo
hints
,
*
res
,
*
res0
;
struct
sockaddr
addr
;
u_long
ip_addr
;
int
err
;
int
s
;
int
i
;
if
(
ftp
->
con_state
!=
init
)
{
ftp_close
(
ftp
);
ftp
->
error
=
-
1
;
return
FAILURE
;
}
ftp_close
(
ftp
);
ftp
->
error
=
-
1
;
return
FAILURE
;
}
if
(
!
user
)
user
=
"ftp"
;
user
=
"ftp"
;
if
(
!
passwd
)
passwd
=
"setup@"
;
passwd
=
"setup@"
;
if
(
!
port
)
port
=
21
;
snprintf
(
pbuf
,
sizeof
(
pbuf
),
"%d"
,
port
);
memset
(
&
hints
,
0
,
sizeof
(
hints
));
hints
.
ai_family
=
AF_INET
;
hints
.
ai_socktype
=
SOCK_STREAM
;
hints
.
ai_protocol
=
0
;
err
=
getaddrinfo
(
host
,
pbuf
,
&
hints
,
&
res0
);
if
(
err
)
{
ftp
->
error
=
0
;
return
FAILURE
;
}
s
=
-
1
;
for
(
res
=
res0
;
res
;
res
=
res
->
ai_next
)
{
ftp
->
addrtype
=
res
->
ai_family
;
port
=
21
;
if
((
s
=
socket
(
res
->
ai_family
,
res
->
ai_socktype
,
res
->
ai_protocol
))
<
0
)
continue
;
if
((
ip_addr
=
resolve_ip
(
host
))
==
INADDR_NONE
)
return
FAILURE
;
if
(
connect
(
s
,
res
->
ai_addr
,
res
->
ai_addrlen
)
<
0
)
{
(
void
)
close
(
s
);
s
=
-
1
;
continue
;
if
((
s
=
socket
(
AF_INET
,
SOCK_STREAM
,
IPPROTO_IP
))
<
0
)
{
ftp
->
error
=
errno
;
return
FAILURE
;
}
break
;
}
freeaddrinfo
(
res0
);
if
(
s
<
0
)
{
ftp
->
error
=
errno
;
return
FAILURE
;
}
memset
(
&
addr
,
0
,
sizeof
(
addr
));
addr
.
sin_addr
.
s_addr
=
ip_addr
;
addr
.
sin_family
=
AF_INET
;
addr
.
sin_port
=
htons
(
port
);
if
(
connect
(
s
,
&
addr
,
sizeof
(
addr
))
<
0
)
{
ftp
->
error
=
errno
;
close
(
s
);
return
FAILURE
;
}
ftp
->
fd_ctrl
=
s
;
ftp
->
con_state
=
isopen
;
...
...
@@ -614,12 +620,12 @@ ftp_login_session(FTP_t ftp, char *host,
i
=
cmd
(
ftp
,
"USER %s"
,
user
);
if
(
i
>=
300
&&
i
<
400
)
i
=
cmd
(
ftp
,
"PASS %s"
,
passwd
);
i
=
cmd
(
ftp
,
"PASS %s"
,
passwd
);
if
(
i
>=
299
||
i
<
0
)
{
ftp_close
(
ftp
);
if
(
i
>
0
)
ftp
->
error
=
i
;
return
FAILURE
;
ftp_close
(
ftp
);
if
(
i
>
0
)
ftp
->
error
=
i
;
return
FAILURE
;
}
return
SUCCESS
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment