Treat "123.45.67.891" as invalid

This commit is contained in:
0x1eef 2023-08-25 20:05:43 -03:00
parent 918d43e4e9
commit 9baa5f9fe4
2 changed files with 6 additions and 5 deletions

View file

@ -4,8 +4,8 @@
#include <isinetaddr.h>
#include <errno.h>
static
int inrange(char buf[4])
static int
inrange(char buf[4])
{
char *err;
long r;
@ -20,7 +20,6 @@ isinetaddr(const char *str)
char buf[4];
int i = 0, j = 0, k = 0;
size_t len = (str == NULL ? 0 : strnlen(str, 16));
for (size_t l = 0; l < len; l++) {
if (str[l] == '.') {
if (inrange(buf)) {
@ -43,6 +42,6 @@ isinetaddr(const char *str)
return 0;
}
}
return j == 3 && i <= 12 ? 1 : 0;
return j == 3 && i <= 12 && inrange(buf);
}

View file

@ -7,10 +7,12 @@ const char *valid[] = {
"192.168.1.1",
"0.0.0.0",
"255.255.255.255",
"123.45.67.89"
"123.45.67.89",
"123.45.67.255",
};
const char *invalid[] = {
"123.45.67.891",
"192.168.500.1",
".192.168.1.1",
"192..168.1.1",