dns-domain: use PTR_SUB1() macro

This commit is contained in:
Yu Watanabe
2022-03-23 21:57:59 +09:00
parent 93e04eb43b
commit 007950dcd1
+5 -11
View File
@@ -168,24 +168,18 @@ int dns_label_unescape_suffix(const char *name, const char **label_terminal, cha
/* Skip current terminal character (and accept domain names ending it ".") */
if (*terminal == 0)
terminal--;
terminal = PTR_SUB1(terminal, name);
if (terminal >= name && *terminal == '.')
terminal--;
terminal = PTR_SUB1(terminal, name);
/* Point name to the last label, and terminal to the preceding terminal symbol (or make it a NULL pointer) */
for (;;) {
if (terminal < name) {
/* Reached the first label, so indicate that there are no more */
terminal = NULL;
break;
}
while (terminal) {
/* Find the start of the last label */
if (*terminal == '.') {
const char *y;
unsigned slashes = 0;
for (y = terminal - 1; y >= name && *y == '\\'; y--)
for (y = PTR_SUB1(terminal, name); y && *y == '\\'; y = PTR_SUB1(y, name))
slashes++;
if (slashes % 2 == 0) {
@@ -198,7 +192,7 @@ int dns_label_unescape_suffix(const char *name, const char **label_terminal, cha
}
}
terminal--;
terminal = PTR_SUB1(terminal, name);
}
r = dns_label_unescape(&name, dest, sz, 0);