Sync up nameser with upstream(2014.03.05)
Bug: 13219633
Change-Id: I8ee4ddf270710e9eea415fa3db984af7719a8dd4
diff --git a/libc/dns/nameser/ns_samedomain.c b/libc/dns/nameser/ns_samedomain.c
index d35dfe1..0be0c28 100644
--- a/libc/dns/nameser/ns_samedomain.c
+++ b/libc/dns/nameser/ns_samedomain.c
@@ -1,4 +1,4 @@
-/* $NetBSD: ns_samedomain.c,v 1.2 2004/05/20 20:35:05 christos Exp $ */
+/* $NetBSD: ns_samedomain.c,v 1.8 2012/11/22 20:22:31 christos Exp $ */
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
@@ -20,9 +20,9 @@
#include <sys/cdefs.h>
#ifndef lint
#ifdef notdef
-static const char rcsid[] = "Id: ns_samedomain.c,v 1.1.2.2.4.2 2004/03/16 12:34:17 marka Exp";
+static const char rcsid[] = "Id: ns_samedomain.c,v 1.6 2005/04/27 04:56:40 sra Exp";
#else
-__RCSID("$NetBSD: ns_samedomain.c,v 1.2 2004/05/20 20:35:05 christos Exp $");
+__RCSID("$NetBSD: ns_samedomain.c,v 1.8 2012/11/22 20:22:31 christos Exp $");
#endif
#endif
@@ -31,16 +31,17 @@
#include <errno.h>
#include <string.h>
-#ifndef _LIBC
+#ifdef _LIBRESOLV
/*
- * int
- * ns_samedomain(a, b)
* Check whether a name belongs to a domain.
+ *
* Inputs:
* a - the domain whose ancestory is being verified
* b - the potential ancestor we're checking against
+ *
* Return:
* boolean - is a at or below b?
+ *
* Notes:
* Trailing dots are first removed from name and domain.
* Always compare complete subdomains, not only whether the
@@ -52,8 +53,8 @@
int
ns_samedomain(const char *a, const char *b) {
- size_t la, lb;
- int diff, i, escaped;
+ size_t la, lb, i;
+ int diff, escaped;
const char *cp;
la = strlen(a);
@@ -63,8 +64,8 @@
if (la != 0U && a[la - 1] == '.') {
escaped = 0;
/* Note this loop doesn't get executed if la==1. */
- for (i = la - 2; i >= 0; i--)
- if (a[i] == '\\') {
+ for (i = la - 1; i > 0; i--)
+ if (a[i - 1] == '\\') {
if (escaped)
escaped = 0;
else
@@ -79,8 +80,8 @@
if (lb != 0U && b[lb - 1] == '.') {
escaped = 0;
/* note this loop doesn't get executed if lb==1 */
- for (i = lb - 2; i >= 0; i--)
- if (b[i] == '\\') {
+ for (i = lb - 1; i > 0; i--)
+ if (b[i - 1] == '\\') {
if (escaped)
escaped = 0;
else
@@ -105,7 +106,7 @@
/* Ok, we know la > lb. */
- diff = la - lb;
+ diff = (int)(la - lb);
/*
* If 'a' is only 1 character longer than 'b', then it can't be
@@ -128,8 +129,8 @@
* and thus not a really a label separator.
*/
escaped = 0;
- for (i = diff - 2; i >= 0; i--)
- if (a[i] == '\\') {
+ for (i = diff - 1; i > 0; i--)
+ if (a[i - 1] == '\\') {
if (escaped)
escaped = 0;
else
@@ -145,8 +146,6 @@
}
/*
- * int
- * ns_subdomain(a, b)
* is "a" a subdomain of "b"?
*/
int
@@ -155,10 +154,10 @@
}
#endif
+#ifdef _LIBC
/*
- * int
- * ns_makecanon(src, dst, dstsize)
* make a canonical copy of domain name "src"
+ *
* notes:
* foo -> foo.
* foo. -> foo.
@@ -188,9 +187,8 @@
}
/*
- * int
- * ns_samename(a, b)
* determine whether domain name "a" is the same as domain name "b"
+ *
* return:
* -1 on error
* 0 if names differ
@@ -209,3 +207,4 @@
else
return (0);
}
+#endif