Bläddra i källkod

inet_aton doesn't overwrite the IP address unless it is valid.

tags/v0.9.3
Michael Brown 19 år sedan
förälder
incheckning
903ddd9878
1 ändrade filer med 7 tillägg och 5 borttagningar
  1. 7
    5
      src/core/misc.c

+ 7
- 5
src/core/misc.c Visa fil

@@ -146,9 +146,8 @@ int strcasecmp(const char *a, const char *b)
146 146
 /**************************************************************************
147 147
 INET_ATON - Convert an ascii x.x.x.x to binary form
148 148
 **************************************************************************/
149
-int inet_aton(const char *start, in_addr *i)
150
-{
151
-	const char *p = start;
149
+int inet_aton ( const char *cp, struct in_addr *inp ) {
150
+	const char *p = cp;
152 151
 	const char *digits_start;
153 152
 	unsigned long ip = 0;
154 153
 	unsigned long val;
@@ -160,8 +159,11 @@ int inet_aton(const char *start, in_addr *i)
160 159
 		if ( ( j < 3 ) && ( *(p++) != '.' ) ) return 0;
161 160
 		ip = (ip << 8) | val;
162 161
 	}
163
-	i->s_addr = htonl(ip);
164
-	return p - start;
162
+	if ( *p == '\0' ) {
163
+		inp->s_addr = htonl(ip);
164
+		return 1;
165
+	}
166
+	return 0;
165 167
 }
166 168
 
167 169
 unsigned long strtoul(const char *p, const char **endp, int base)

Laddar…
Avbryt
Spara