summaryrefslogtreecommitdiff
path: root/src/shared/dns-domain.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/dns-domain.c')
-rw-r--r--src/shared/dns-domain.c69
1 files changed, 19 insertions, 50 deletions
diff --git a/src/shared/dns-domain.c b/src/shared/dns-domain.c
index 8c807e0e23..de2fcca8b2 100644
--- a/src/shared/dns-domain.c
+++ b/src/shared/dns-domain.c
@@ -1,21 +1,5 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
/***
- This file is part of systemd.
-
- Copyright 2014 Lennart Poettering
-
- systemd is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation; either version 2.1 of the License, or
- (at your option) any later version.
-
- systemd is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#if HAVE_LIBIDN2
@@ -295,8 +279,7 @@ int dns_label_escape_new(const char *p, size_t l, char **ret) {
if (r < 0)
return r;
- *ret = s;
- s = NULL;
+ *ret = TAKE_PTR(s);
return r;
}
@@ -367,10 +350,7 @@ int dns_label_undo_idna(const char *encoded, size_t encoded_size, char *decoded,
if (encoded_size <= 0 || encoded_size > DNS_LABEL_MAX)
return -EINVAL;
- if (encoded_size < sizeof(IDNA_ACE_PREFIX)-1)
- return 0;
-
- if (memcmp(encoded, IDNA_ACE_PREFIX, sizeof(IDNA_ACE_PREFIX) -1) != 0)
+ if (!memory_startswith(encoded, encoded_size, IDNA_ACE_PREFIX))
return 0;
input = stringprep_utf8_to_ucs4(encoded, encoded_size, &input_size);
@@ -409,10 +389,9 @@ int dns_name_concat(const char *a, const char *b, char **_ret) {
if (a)
p = a;
- else if (b) {
- p = b;
- b = NULL;
- } else
+ else if (b)
+ p = TAKE_PTR(b);
+ else
goto finish;
for (;;) {
@@ -427,8 +406,7 @@ int dns_name_concat(const char *a, const char *b, char **_ret) {
if (b) {
/* Now continue with the second string, if there is one */
- p = b;
- b = NULL;
+ p = TAKE_PTR(b);
continue;
}
@@ -478,8 +456,7 @@ finish:
}
ret[n] = 0;
- *_ret = ret;
- ret = NULL;
+ *_ret = TAKE_PTR(ret);
}
return 0;
@@ -601,8 +578,7 @@ int dns_name_endswith(const char *name, const char *suffix) {
/* Not the same, let's jump back, and try with the next label again */
s = suffix;
- n = saved_n;
- saved_n = NULL;
+ n = TAKE_PTR(saved_n);
}
}
}
@@ -677,8 +653,8 @@ int dns_name_change_suffix(const char *name, const char *old_suffix, const char
/* Not the same, let's jump back, and try with the next label again */
s = old_suffix;
- n = saved_after;
- saved_after = saved_before = NULL;
+ n = TAKE_PTR(saved_after);
+ saved_before = NULL;
}
}
@@ -1113,20 +1089,14 @@ finish:
if (r < 0)
return r;
- if (_domain) {
- *_domain = domain;
- domain = NULL;
- }
+ if (_domain)
+ *_domain = TAKE_PTR(domain);
- if (_type) {
- *_type = type;
- type = NULL;
- }
+ if (_type)
+ *_type = TAKE_PTR(type);
- if (_name) {
- *_name = name;
- name = NULL;
- }
+ if (_name)
+ *_name = TAKE_PTR(name);
return 0;
}
@@ -1309,8 +1279,8 @@ int dns_name_apply_idna(const char *name, char **ret) {
}
}
- *ret = t;
- t = NULL;
+ *ret = TAKE_PTR(t);
+
return 1; /* *ret has been written */
}
@@ -1367,8 +1337,7 @@ int dns_name_apply_idna(const char *name, char **ret) {
return -ENOMEM;
buf[n] = 0;
- *ret = buf;
- buf = NULL;
+ *ret = TAKE_PTR(buf);
return 1;
#else