4cad4c
From 9b7aa39e7db5a6446d3c034741e64cda1a9dd200 Mon Sep 17 00:00:00 2001
4cad4c
From: Filipe Brandenburger <filbranden@google.com>
4cad4c
Date: Mon, 25 Jun 2018 18:07:48 -0700
4cad4c
Subject: [PATCH] resolvconf: fixes for the compatibility interface
4cad4c
4cad4c
Also use compat_main() when called as `resolvconf`, since the interface
4cad4c
is closer to that of `systemd-resolve`.
4cad4c
4cad4c
Use a heap allocated string to set arg_ifname, since a stack allocated
4cad4c
one would be lost after the function returns. (This last one broke the
4cad4c
case where an interface name was suffixed with a dot, such as in
4cad4c
`resolvconf -a tap0.dhcp`.)
4cad4c
4cad4c
Tested:
4cad4c
  $ build/resolvconf -a nonexistent.abc 
4cad4c
  Unknown interface 'nonexistent': No such device
4cad4c
4cad4c
Fixes #9423.
4cad4c
4cad4c
(cherry picked from commit 5a01b3f35d7b6182c78b6973db8d99bdabd4f9c3)
4cad4c
4cad4c
Resolves: #1835594
4cad4c
---
4cad4c
 src/resolve/resolvconf-compat.c | 4 +++-
4cad4c
 src/resolve/resolvectl.c        | 2 +-
4cad4c
 2 files changed, 4 insertions(+), 2 deletions(-)
4cad4c
4cad4c
diff --git a/src/resolve/resolvconf-compat.c b/src/resolve/resolvconf-compat.c
4cad4c
index d7e68003e6..0723458945 100644
4cad4c
--- a/src/resolve/resolvconf-compat.c
4cad4c
+++ b/src/resolve/resolvconf-compat.c
4cad4c
@@ -53,6 +53,8 @@ static int parse_nameserver(const char *string) {
4cad4c
 
4cad4c
                 if (strv_push(&arg_set_dns, word) < 0)
4cad4c
                         return log_oom();
4cad4c
+
4cad4c
+                word = NULL;
4cad4c
         }
4cad4c
 
4cad4c
         return 0;
4cad4c
@@ -202,7 +204,7 @@ int resolvconf_parse_argv(int argc, char *argv[]) {
4cad4c
 
4cad4c
         dot = strchr(argv[optind], '.');
4cad4c
         if (dot) {
4cad4c
-                iface = strndupa(argv[optind], dot - argv[optind]);
4cad4c
+                iface = strndup(argv[optind], dot - argv[optind]);
4cad4c
                 log_debug("Ignoring protocol specifier '%s'.", dot + 1);
4cad4c
         } else
4cad4c
                 iface = argv[optind];
4cad4c
diff --git a/src/resolve/resolvectl.c b/src/resolve/resolvectl.c
4cad4c
index cf1ec323a4..355e5c62b1 100644
4cad4c
--- a/src/resolve/resolvectl.c
4cad4c
+++ b/src/resolve/resolvectl.c
4cad4c
@@ -3090,7 +3090,7 @@ int main(int argc, char **argv) {
4cad4c
                 goto finish;
4cad4c
         }
4cad4c
 
4cad4c
-        if (streq(program_invocation_short_name, "systemd-resolve"))
4cad4c
+        if (STR_IN_SET(program_invocation_short_name, "systemd-resolve", "resolvconf"))
4cad4c
                 r = compat_main(argc, argv, bus);
4cad4c
         else
4cad4c
                 r = native_main(argc, argv, bus);