Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-winehq
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
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-winehq
Commits
bed1525f
Commit
bed1525f
authored
Mar 12, 2015
by
Qian Hong
Committed by
Alexandre Julliard
Mar 13, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ws2_32: Improved error handling in gethostname when name length is insufficient.
parent
5061e350
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
6 deletions
+59
-6
socket.c
dlls/ws2_32/socket.c
+25
-6
sock.c
dlls/ws2_32/tests/sock.c
+34
-0
No files found.
dlls/ws2_32/socket.c
View file @
bed1525f
...
...
@@ -6056,16 +6056,35 @@ struct WS_servent* WINAPI WS_getservbyport(int port, const char *proto)
*/
int
WINAPI
WS_gethostname
(
char
*
name
,
int
namelen
)
{
char
buf
[
256
];
int
len
;
TRACE
(
"name %p, len %d
\n
"
,
name
,
namelen
);
if
(
gethostname
(
name
,
namelen
)
==
0
)
if
(
!
name
)
{
TRACE
(
"<- '%s'
\n
"
,
name
);
return
0
;
SetLastError
(
WSAEFAULT
);
return
SOCKET_ERROR
;
}
SetLastError
((
errno
==
EINVAL
)
?
WSAEFAULT
:
wsaErrno
());
TRACE
(
"<- ERROR !
\n
"
);
return
SOCKET_ERROR
;
if
(
gethostname
(
buf
,
sizeof
(
buf
))
!=
0
)
{
SetLastError
(
wsaErrno
());
return
SOCKET_ERROR
;
}
TRACE
(
"<- '%s'
\n
"
,
buf
);
len
=
strlen
(
buf
);
if
(
len
>
15
)
WARN
(
"Windows supports NetBIOS name length up to 15 bytes!
\n
"
);
if
(
namelen
<=
len
)
{
SetLastError
(
WSAEFAULT
);
WARN
(
"<- not enough space for hostname, required %d, got %d!
\n
"
,
len
+
1
,
namelen
);
return
SOCKET_ERROR
;
}
strcpy
(
name
,
buf
);
return
0
;
}
...
...
dlls/ws2_32/tests/sock.c
View file @
bed1525f
...
...
@@ -4215,6 +4215,39 @@ static void test_gethostbyname_hack(void)
* resolve nonexistent host names to addresses of the ISP's spam pages. */
}
static
void
test_gethostname
(
void
)
{
struct
hostent
*
he
;
char
name
[
256
];
int
ret
,
len
;
WSASetLastError
(
0xdeadbeef
);
ret
=
gethostname
(
NULL
,
256
);
ok
(
ret
==
-
1
,
"gethostname() returned %d
\n
"
,
ret
);
ok
(
WSAGetLastError
()
==
WSAEFAULT
,
"gethostname with null buffer "
"failed with %d, expected %d
\n
"
,
WSAGetLastError
(),
WSAEFAULT
);
ret
=
gethostname
(
name
,
sizeof
(
name
));
ok
(
ret
==
0
,
"gethostname() call failed: %d
\n
"
,
WSAGetLastError
());
he
=
gethostbyname
(
name
);
ok
(
he
!=
NULL
,
"gethostbyname(
\"
%s
\"
) failed: %d
\n
"
,
name
,
WSAGetLastError
());
len
=
strlen
(
name
);
WSASetLastError
(
0xdeadbeef
);
strcpy
(
name
,
"deadbeef"
);
ret
=
gethostname
(
name
,
len
);
ok
(
ret
==
-
1
,
"gethostname() returned %d
\n
"
,
ret
);
ok
(
!
strcmp
(
name
,
"deadbeef"
),
"name changed unexpected!
\n
"
);
ok
(
WSAGetLastError
()
==
WSAEFAULT
,
"gethostname with insufficient length "
"failed with %d, expected %d
\n
"
,
WSAGetLastError
(),
WSAEFAULT
);
len
++
;
ret
=
gethostname
(
name
,
len
);
ok
(
ret
==
0
,
"gethostname() call failed: %d
\n
"
,
WSAGetLastError
());
he
=
gethostbyname
(
name
);
ok
(
he
!=
NULL
,
"gethostbyname(
\"
%s
\"
) failed: %d
\n
"
,
name
,
WSAGetLastError
());
}
static
void
test_inet_addr
(
void
)
{
u_long
addr
;
...
...
@@ -8437,6 +8470,7 @@ START_TEST( sock )
test_ioctlsocket
();
test_dns
();
test_gethostbyname_hack
();
test_gethostname
();
test_WSASendMsg
();
test_WSASendTo
();
...
...
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