Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

misc: Fixed ssh_is_ipaddr_v4() on Windows.

  • Loading branch information...
commit eea1df3574db36036aa68c098bc29996a241808d 1 parent 9baa491
@gladiac gladiac authored
Showing with 8 additions and 4 deletions.
  1. +5 −0 src/misc.c
  2. +3 −4 tests/unittests/torture_isipaddr.c
View
5 src/misc.c
@@ -158,6 +158,11 @@ int ssh_is_ipaddr_v4(const char *str) {
int sslen = sizeof(ss);
int rc = SOCKET_ERROR;
+ /* WSAStringToAddressA thinks that 0.0.0 is a valid IP */
+ if (strlen < 7) {
+ return 0;
+ }
+
rc = WSAStringToAddressA((LPSTR) str,
AF_INET,
NULL,
View
7 tests/unittests/torture_isipaddr.c
@@ -23,6 +23,7 @@ static void torture_ssh_is_ipaddr(void **state) {
assert_int_equal(ssh_is_ipaddr("fe80:0000:0000:0000:0202:b3ff:fe1e:8329"),1);
assert_int_equal(ssh_is_ipaddr("fe80:0:0:0:202:b3ff:fe1e:8329"),1);
assert_int_equal(ssh_is_ipaddr("fe80::202:b3ff:fe1e:8329"),1);
+ assert_int_equal(ssh_is_ipaddr("::1"),1);
assert_int_equal(ssh_is_ipaddr("::ffff:192.0.2.128"),1);
@@ -32,15 +33,13 @@ static void torture_ssh_is_ipaddr(void **state) {
assert_int_equal(ssh_is_ipaddr("0a.0.0.0.0"),0);
assert_int_equal(ssh_is_ipaddr(""),0);
assert_int_equal(ssh_is_ipaddr("0.0.0."),0);
-#ifndef _WIN32
- /* These are valid ip address on Windows */
- assert_int_equal(ssh_is_ipaddr("0.0.0"),0);
assert_int_equal(ssh_is_ipaddr("0.0"),0);
assert_int_equal(ssh_is_ipaddr("0"),0);
-#endif
assert_int_equal(ssh_is_ipaddr("2001:0db8:85a3:0000:0000:8a2e:0370:7334:1002"), 0);
assert_int_equal(ssh_is_ipaddr("fe80:x:202:b3ff:fe1e:8329"), 0);
+ assert_int_equal(ssh_is_ipaddr("fe80:x:202:b3ff:fe1e:8329"), 0);
+ assert_int_equal(ssh_is_ipaddr(":1"), 0);
}
int torture_run_tests(void) {
Please sign in to comment.
Something went wrong with that request. Please try again.