Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
btwise
openssl
提交
b34d449c
O
openssl
项目概览
btwise
/
openssl
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
openssl
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b34d449c
编写于
10月 06, 2009
作者:
A
Andy Polyakov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Combat gcc 4.4.1 aliasing rules.
上级
04f9095d
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
67 addition
and
46 deletion
+67
-46
crypto/bio/b_sock.c
crypto/bio/b_sock.c
+67
-46
未找到文件。
crypto/bio/b_sock.c
浏览文件 @
b34d449c
...
...
@@ -588,14 +588,13 @@ static int get_ip(const char *str, unsigned char ip[4])
int
BIO_get_accept_socket
(
char
*
host
,
int
bind_mode
)
{
int
ret
=
0
;
union
{
struct
sockaddr
sa
;
struct
sockaddr_in
sa_in
;
#if OPENSSL_USE_IPV6
# define ossl_sock_family(s) s.ss_family
struct
sockaddr_storage
server
,
client
;
#else
# define ossl_sock_family(s) s.sa_family
struct
sockaddr
server
,
client
;
struct
sockaddr_in6
sa_in6
;
#endif
struct
sockaddr_in
*
sa_in
;
}
server
,
client
;
int
s
=
INVALID_SOCKET
,
cs
;
unsigned
char
ip
[
4
];
unsigned
short
port
;
...
...
@@ -666,11 +665,10 @@ int BIO_get_accept_socket(char *host, int bind_mode)
}
if
((
*
p_getaddrinfo
.
f
)(
h
,
p
,
&
hint
,
&
res
))
break
;
#if OPENSSL_USE_IPV6
memcpy
(
&
server
,
res
->
ai_addr
,
res
->
ai_addrlen
);
#else
server
=
*
res
->
ai_addr
;
#endif
memcpy
(
&
server
,
res
->
ai_addr
,
res
->
ai_addrlen
<=
sizeof
(
server
)
?
res
->
ai_addrlen
:
sizeof
(
server
));
(
*
p_freeaddrinfo
.
f
)(
res
);
goto
again
;
}
while
(
0
);
...
...
@@ -679,12 +677,11 @@ int BIO_get_accept_socket(char *host, int bind_mode)
if
(
!
BIO_get_port
(
p
,
&
port
))
goto
err
;
memset
((
char
*
)
&
server
,
0
,
sizeof
(
server
));
sa_in
=
(
struct
sockaddr_in
*
)
&
server
;
sa_in
->
sin_family
=
AF_INET
;
sa_in
->
sin_port
=
htons
(
port
);
server
.
sa_in
.
sin_family
=
AF_INET
;
server
.
sa_in
.
sin_port
=
htons
(
port
);
if
(
h
==
NULL
||
strcmp
(
h
,
"*"
)
==
0
)
s
a_in
->
sin_addr
.
s_addr
=
INADDR_ANY
;
s
erver
.
sa_in
.
sin_addr
.
s_addr
=
INADDR_ANY
;
else
{
if
(
!
BIO_get_host_ip
(
h
,
&
(
ip
[
0
])))
goto
err
;
...
...
@@ -693,11 +690,11 @@ int BIO_get_accept_socket(char *host, int bind_mode)
((
unsigned
long
)
ip
[
1
]
<<
16L
)
|
((
unsigned
long
)
ip
[
2
]
<<
8L
)
|
((
unsigned
long
)
ip
[
3
]);
s
a_in
->
sin_addr
.
s_addr
=
htonl
(
l
);
s
erver
.
sa_in
.
sin_addr
.
s_addr
=
htonl
(
l
);
}
again:
s
=
socket
(
ossl_sock_family
(
server
)
,
SOCK_STREAM
,
SOCKET_PROTOCOL
);
s
=
socket
(
server
.
sa
.
sa_family
,
SOCK_STREAM
,
SOCKET_PROTOCOL
);
if
(
s
==
INVALID_SOCKET
)
{
SYSerr
(
SYS_F_SOCKET
,
get_last_socket_error
());
...
...
@@ -715,7 +712,7 @@ again:
bind_mode
=
BIO_BIND_NORMAL
;
}
#endif
if
(
bind
(
s
,
(
struct
sockaddr
*
)
&
server
,
sizeof
(
server
))
==
-
1
)
if
(
bind
(
s
,
&
server
.
sa
,
sizeof
(
server
))
==
-
1
)
{
#ifdef SO_REUSEADDR
err_num
=
get_last_socket_error
();
...
...
@@ -726,29 +723,24 @@ again:
if
(
h
==
NULL
||
strcmp
(
h
,
"*"
)
==
0
)
{
#if OPENSSL_USE_IPV6
if
(
ossl_sock_family
(
client
)
==
AF_INET6
)
if
(
client
.
sa
.
sa_family
==
AF_INET6
)
{
struct
sockaddr_in6
*
sin6
=
(
struct
sockaddr_in6
*
)
&
client
;
memset
(
&
sin6
->
sin6_addr
,
0
,
sizeof
(
sin6
->
sin6_addr
));
sin6
->
sin6_addr
.
s6_addr
[
15
]
=
1
;
memset
(
&
client
.
sa_in6
.
sin6_addr
,
0
,
sizeof
(
client
.
sa_in6
.
sin6_addr
));
client
.
sa_in6
.
sin6_addr
.
s6_addr
[
15
]
=
1
;
}
else
#endif
if
(
ossl_sock_family
(
client
)
==
AF_INET
)
if
(
client
.
sa
.
sa_family
==
AF_INET
)
{
struct
sockaddr_in
*
sin4
=
(
struct
sockaddr_in
*
)
&
client
;
sin4
->
sin_addr
.
s_addr
=
htonl
(
0x7F000001
);
client
.
sa_in
.
sin_addr
.
s_addr
=
htonl
(
0x7F000001
);
}
else
goto
err
;
}
cs
=
socket
(
ossl_sock_family
(
client
)
,
SOCK_STREAM
,
SOCKET_PROTOCOL
);
cs
=
socket
(
client
.
sa
.
sa_family
,
SOCK_STREAM
,
SOCKET_PROTOCOL
);
if
(
cs
!=
INVALID_SOCKET
)
{
int
ii
;
ii
=
connect
(
cs
,(
struct
sockaddr
*
)
&
client
,
sizeof
(
client
));
ii
=
connect
(
cs
,
&
client
.
sa
,
sizeof
(
client
));
closesocket
(
cs
);
if
(
ii
==
INVALID_SOCKET
)
{
...
...
@@ -787,21 +779,51 @@ err:
int
BIO_accept
(
int
sock
,
char
**
addr
)
{
int
ret
=
INVALID_SOCKET
;
struct
sockaddr
from
;
struct
sockaddr_in
*
sa_in
;
unsigned
long
l
;
unsigned
short
port
;
int
len
;
char
*
p
;
memset
(
&
from
,
0
,
sizeof
(
from
));
len
=
sizeof
(
from
);
/* Note: under VMS with SOCKETSHR the fourth parameter is currently
* of type (int *) whereas under other systems it is (void *) if
* you don't have a cast it will choke the compiler: if you do
* have a cast then you can either go for (int *) or (void *).
struct
{
/*
* As for following union. Trouble is that there are platforms
* that have socklen_t and there are platforms that don't, on
* some platforms socklen_t is int and on some size_t. So what
* one can do? One can cook #ifdef spaghetti, which is nothing
* but masochistic. Or one can do union between int and size_t.
* One naturally does it primarily for 64-bit platforms where
* sizeof(int) != sizeof(size_t). But would it work? Note that
* if size_t member is initialized to 0, then later int member
* assignment naturally does the job on little-endian platforms
* regardless accept's expectations! What about big-endians?
* If accept expects int*, then it works, and if size_t*, then
* length value would appear as unreasonably large. But this
* won't prevent it from filling in the address structure. The
* trouble of course would be if accept returns more data than
* actual buffer can accomodate and overwrite stack... That's
* where early OPENSSL_assert comes into picture. Besides, the
* only 64-bit big-endian platform found so far that expects
* size_t* is HP-UX, where stack grows towards higher address.
* <appro>
*/
ret
=
accept
(
sock
,
&
from
,(
void
*
)
&
len
);
union
{
size_t
s
;
int
i
;
}
len
;
union
{
struct
sockaddr
sa
;
struct
sockaddr_in
sa_in
;
#if OPENSSL_USE_IPV6
struct
sockaddr_in6
sa_in6
;
#endif
}
from
;
}
sa
;
sa
.
len
.
s
=
0
;
sa
.
len
.
i
=
sizeof
(
sa
.
from
);
memset
(
&
sa
.
from
,
0
,
sizeof
(
sa
.
from
));
ret
=
accept
(
sock
,
&
sa
.
from
.
sa
,(
void
*
)
&
sa
.
len
);
if
(
sizeof
(
sa
.
len
.
i
)
!=
sizeof
(
sa
.
len
.
s
)
&&
sa
.
len
.
i
==
0
)
{
OPENSSL_assert
(
sa
.
len
.
s
<=
sizeof
(
sa
.
from
));
sa
.
len
.
i
=
(
unsigned
int
)
sa
.
len
.
s
;
}
if
(
ret
==
INVALID_SOCKET
)
{
if
(
BIO_sock_should_retry
(
ret
))
return
-
2
;
...
...
@@ -833,9 +855,9 @@ int BIO_accept(int sock, char **addr)
}
if
(
p_getnameinfo
.
p
==
(
void
*
)
-
1
)
break
;
if
((
*
p_getnameinfo
.
f
)(
&
from
,
sizeof
(
from
)
,
h
,
sizeof
(
h
),
s
,
sizeof
(
s
),
if
((
*
p_getnameinfo
.
f
)(
&
sa
.
from
.
sa
,
sa
.
len
.
i
,
h
,
sizeof
(
h
),
s
,
sizeof
(
s
),
NI_NUMERICHOST
|
NI_NUMERICSERV
))
break
;
nl
=
strlen
(
h
)
+
strlen
(
s
)
+
2
;
if
(
len
<
24
)
len
=
24
;
nl
=
strlen
(
h
)
+
strlen
(
s
)
+
2
;
p
=
*
addr
;
if
(
p
)
{
*
p
=
'\0'
;
p
=
OPENSSL_realloc
(
p
,
nl
);
}
else
{
p
=
OPENSSL_malloc
(
nl
);
}
...
...
@@ -849,10 +871,9 @@ int BIO_accept(int sock, char **addr)
goto
end
;
}
while
(
0
);
#endif
if
(
from
.
sa_family
!=
AF_INET
)
goto
end
;
sa_in
=
(
struct
sockaddr_in
*
)
&
from
;
l
=
ntohl
(
sa_in
->
sin_addr
.
s_addr
);
port
=
ntohs
(
sa_in
->
sin_port
);
if
(
sa
.
from
.
sa
.
sa_family
!=
AF_INET
)
goto
end
;
l
=
ntohl
(
sa
.
from
.
sa_in
.
sin_addr
.
s_addr
);
port
=
ntohs
(
sa
.
from
.
sa_in
.
sin_port
);
if
(
*
addr
==
NULL
)
{
if
((
p
=
OPENSSL_malloc
(
24
))
==
NULL
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录