-/* $OpenBSD: asr_private.h,v 1.47 2018/04/28 15:16:49 schwarze Exp $ */
+/* $OpenBSD: asr_private.h,v 1.48 2022/11/17 17:39:41 florian Exp $ */
/*
* Copyright (c) 2012 Eric Faurot <eric@openbsd.org>
*
int _asr_sockaddr_from_str(struct sockaddr *, int, const char *);
ssize_t _asr_dname_from_fqdn(const char *, char *, size_t);
ssize_t _asr_addr_as_fqdn(const char *, int, char *, size_t);
+int hnok_lenient(const char *);
/* asr.c */
void _asr_resolver_done(void *);
-/* $OpenBSD: asr_utils.c,v 1.18 2017/09/23 20:55:06 jca Exp $ */
+/* $OpenBSD: asr_utils.c,v 1.19 2022/11/17 17:39:41 florian Exp $ */
/*
* Copyright (c) 2009-2012 Eric Faurot <eric@faurot.net>
*
}
return (0);
}
+
+int
+hnok_lenient(const char *dn)
+{
+ int pch = '\0', ch = *dn++;
+
+ while (ch != '\0') {
+ /* can't start with . or - */
+ if (pch == '\0' && (ch == '.' || ch == '-'))
+ return 0;
+ if (pch == '.' && ch == '.')
+ return 0;
+ if (!(isalpha((unsigned char)ch) || isdigit((unsigned char)ch) ||
+ ch == '.' || ch == '-' || ch == '_'))
+ return 0;
+ pch = ch; ch = *dn++;
+ }
+ return 1;
+}
-/* $OpenBSD: getaddrinfo_async.c,v 1.57 2021/01/26 12:27:28 florian Exp $ */
+/* $OpenBSD: getaddrinfo_async.c,v 1.58 2022/11/17 17:39:41 florian Exp $ */
/*
* Copyright (c) 2012 Eric Faurot <eric@openbsd.org>
*
async_set_state(as, ASR_STATE_HALT);
break;
}
-
+
ai = &as->as.ai.hints;
if (ai->ai_addrlen ||
break;
}
+ /* make sure there are no funny characters in hostname */
+ if (!hnok_lenient(as->as.ai.hostname)) {
+ ar->ar_gai_errno = EAI_FAIL;
+ async_set_state(as, ASR_STATE_HALT);
+ break;
+ }
+
async_set_state(as, ASR_STATE_NEXT_DB);
break;
-/* $OpenBSD: gethostnamadr_async.c,v 1.45 2019/06/27 05:26:37 martijn Exp $ */
+/* $OpenBSD: gethostnamadr_async.c,v 1.46 2022/11/17 17:39:41 florian Exp $ */
/*
* Copyright (c) 2012 Eric Faurot <eric@openbsd.org>
*
}
async_set_state(as, ASR_STATE_HALT);
break;
+ } else {
+ if (!hnok_lenient(as->as.hostnamadr.name)) {
+ ar->ar_gai_errno = EAI_FAIL;
+ async_set_state(as, ASR_STATE_HALT);
+ }
}
}
async_set_state(as, ASR_STATE_NEXT_DB);