From 26677f9bb3a482ca44869c898847f16dda2be01e Mon Sep 17 00:00:00 2001 From: jsing <> Date: Tue, 24 Jun 2014 17:42:54 +0000 Subject: Replace 48 lines of code with a single inet_pton() call. The previous handrolled version could not even make use of sscanf(), since that would not work with a certain antiquated compiler. It is worth noting that there is a tiny change in behaviour - previously calling BIO_get_host_ip() with something that looked like it might be a valid IP address (for example, "1." or even ".") would result in it returning failure rather than trying a BIO_gethostbyname() - now we'll always try a BIO_gethostbyname() if it was not a valid IPv4 address. ok beck@ miod@ deraadt@ --- src/lib/libssl/src/crypto/bio/b_sock.c | 51 ++-------------------------------- 1 file changed, 3 insertions(+), 48 deletions(-) (limited to 'src/lib/libssl') diff --git a/src/lib/libssl/src/crypto/bio/b_sock.c b/src/lib/libssl/src/crypto/bio/b_sock.c index 62d545a129..5f8b1e052f 100644 --- a/src/lib/libssl/src/crypto/bio/b_sock.c +++ b/src/lib/libssl/src/crypto/bio/b_sock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: b_sock.c,v 1.42 2014/06/24 17:30:00 jsing Exp $ */ +/* $OpenBSD: b_sock.c,v 1.43 2014/06/24 17:42:54 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -59,6 +59,7 @@ #include #include +#include #include #include @@ -72,8 +73,6 @@ #include "cryptlib.h" -static int get_ip(const char *str, unsigned char *ip); - int BIO_get_host_ip(const char *str, unsigned char *ip) { @@ -82,15 +81,7 @@ BIO_get_host_ip(const char *str, unsigned char *ip) int locked = 0; struct hostent *he; - i = get_ip(str, ip); - if (i < 0) { - BIOerr(BIO_F_BIO_GET_HOST_IP, BIO_R_INVALID_IP_ADDRESS); - goto err; - } - - /* If the string actually contained an IP address, we need not do - anything more */ - if (i > 0) + if (inet_pton(AF_INET, str, ip) == 1) return (1); /* do a gethostbyname */ @@ -228,42 +219,6 @@ BIO_socket_ioctl(int fd, long type, void *arg) return (i); } -/* The reason I have implemented this instead of using sscanf is because - * Visual C 1.52c gives an unresolved external when linking a DLL :-( */ -static int -get_ip(const char *str, unsigned char ip[4]) -{ - unsigned int tmp[4]; - int num = 0, c, ok = 0; - - tmp[0] = tmp[1] = tmp[2] = tmp[3] = 0; - - for (;;) { - c= *(str++); - if ((c >= '0') && (c <= '9')) { - ok = 1; - tmp[num] = tmp[num]*10 + c-'0'; - if (tmp[num] > 255) - return (0); - } else if (c == '.') { - if (!ok) - return (-1); - if (num == 3) - return (0); - num++; - ok = 0; - } else if (c == '\0' && (num == 3) && ok) - break; - else - return (0); - } - ip[0] = tmp[0]; - ip[1] = tmp[1]; - ip[2] = tmp[2]; - ip[3] = tmp[3]; - return (1); -} - int BIO_get_accept_socket(char *host, int bind_mode) { -- cgit v1.2.3-55-g6feb