Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
capnproto
Commits
bfa8a9aa
Commit
bfa8a9aa
authored
Feb 01, 2018
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix bug where DNS lookup would fail for very long hostnames.
parent
a21a2975
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
43 deletions
+49
-43
async-io-unix.c++
c++/src/kj/async-io-unix.c++
+25
-22
async-io-win32.c++
c++/src/kj/async-io-win32.c++
+24
-21
No files found.
c++/src/kj/async-io-unix.c++
View file @
bfa8a9aa
...
...
@@ -732,31 +732,34 @@ public:
addrTarget
=
&
result
.
addr
.
inet4
.
sin_addr
;
}
// addrPart is not necessarily NUL-terminated so we have to make a copy. :(
KJ_REQUIRE
(
addrPart
.
size
()
<
INET6_ADDRSTRLEN
-
1
,
"IP address too long."
,
addrPart
);
char
buffer
[
INET6_ADDRSTRLEN
];
memcpy
(
buffer
,
addrPart
.
begin
(),
addrPart
.
size
());
buffer
[
addrPart
.
size
()]
=
'\0'
;
// OK, parse it!
switch
(
inet_pton
(
af
,
buffer
,
addrTarget
))
{
case
1
:
{
// success.
if
(
!
result
.
parseAllowedBy
(
filter
))
{
KJ_FAIL_REQUIRE
(
"address family blocked by restrictPeers()"
);
return
Array
<
SocketAddress
>
();
}
if
(
addrPart
.
size
()
<
INET6_ADDRSTRLEN
-
1
)
{
// addrPart is not necessarily NUL-terminated so we have to make a copy. :(
char
buffer
[
INET6_ADDRSTRLEN
];
memcpy
(
buffer
,
addrPart
.
begin
(),
addrPart
.
size
());
buffer
[
addrPart
.
size
()]
=
'\0'
;
// OK, parse it!
switch
(
inet_pton
(
af
,
buffer
,
addrTarget
))
{
case
1
:
{
// success.
if
(
!
result
.
parseAllowedBy
(
filter
))
{
KJ_FAIL_REQUIRE
(
"address family blocked by restrictPeers()"
);
return
Array
<
SocketAddress
>
();
}
auto
array
=
kj
::
heapArrayBuilder
<
SocketAddress
>
(
1
);
array
.
add
(
result
);
return
array
.
finish
();
auto
array
=
kj
::
heapArrayBuilder
<
SocketAddress
>
(
1
);
array
.
add
(
result
);
return
array
.
finish
();
}
case
0
:
// It's apparently not a simple address... fall back to DNS.
break
;
default
:
KJ_FAIL_SYSCALL
(
"inet_pton"
,
errno
,
af
,
addrPart
);
}
case
0
:
// It's apparently not a simple address... fall back to DNS.
return
lookupHost
(
lowLevel
,
kj
::
heapString
(
addrPart
),
nullptr
,
port
,
filter
);
default
:
KJ_FAIL_SYSCALL
(
"inet_pton"
,
errno
,
af
,
addrPart
);
}
return
lookupHost
(
lowLevel
,
kj
::
heapString
(
addrPart
),
nullptr
,
port
,
filter
);
}
static
SocketAddress
getLocalAddress
(
int
sockfd
)
{
...
...
c++/src/kj/async-io-win32.c++
View file @
bfa8a9aa
...
...
@@ -634,31 +634,34 @@ public:
addrTarget
=
&
result
.
addr
.
inet4
.
sin_addr
;
}
// addrPart is not necessarily NUL-terminated so we have to make a copy. :(
char
buffer
[
64
];
KJ_REQUIRE
(
addrPart
.
size
()
<
sizeof
(
buffer
)
-
1
,
"IP address too long."
,
addrPart
);
memcpy
(
buffer
,
addrPart
.
begin
(),
addrPart
.
size
());
buffer
[
addrPart
.
size
()]
=
'\0'
;
// OK, parse it!
switch
(
InetPtonA
(
af
,
buffer
,
addrTarget
))
{
case
1
:
{
// success.
if
(
!
result
.
parseAllowedBy
(
filter
))
{
KJ_FAIL_REQUIRE
(
"address family blocked by restrictPeers()"
);
return
Array
<
SocketAddress
>
();
}
if
(
addrPart
.
size
()
<
sizeof
(
buffer
)
-
1
)
{
// addrPart is not necessarily NUL-terminated so we have to make a copy. :(
memcpy
(
buffer
,
addrPart
.
begin
(),
addrPart
.
size
());
buffer
[
addrPart
.
size
()]
=
'\0'
;
// OK, parse it!
switch
(
InetPtonA
(
af
,
buffer
,
addrTarget
))
{
case
1
:
{
// success.
if
(
!
result
.
parseAllowedBy
(
filter
))
{
KJ_FAIL_REQUIRE
(
"address family blocked by restrictPeers()"
);
return
Array
<
SocketAddress
>
();
}
auto
array
=
kj
::
heapArrayBuilder
<
SocketAddress
>
(
1
);
array
.
add
(
result
);
return
array
.
finish
();
auto
array
=
kj
::
heapArrayBuilder
<
SocketAddress
>
(
1
);
array
.
add
(
result
);
return
array
.
finish
();
}
case
0
:
// It's apparently not a simple address... fall back to DNS.
break
;
default
:
KJ_FAIL_WIN32
(
"InetPton"
,
WSAGetLastError
(),
af
,
addrPart
);
}
case
0
:
// It's apparently not a simple address... fall back to DNS.
return
lookupHost
(
lowLevel
,
kj
::
heapString
(
addrPart
),
nullptr
,
port
,
filter
);
default
:
KJ_FAIL_WIN32
(
"InetPton"
,
WSAGetLastError
(),
af
,
addrPart
);
}
return
lookupHost
(
lowLevel
,
kj
::
heapString
(
addrPart
),
nullptr
,
port
,
filter
);
}
static
SocketAddress
getLocalAddress
(
SOCKET
sockfd
)
{
...
...
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