dcavalca / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone
Blob Blame History Raw
From 0e99eafa4f0854626974db4def3e8451133578e3 Mon Sep 17 00:00:00 2001
From: Jan Synacek <jsynacek@redhat.com>
Date: Tue, 2 Oct 2018 12:36:14 +0200
Subject: [PATCH] shorten hostname before checking for trailing dot

Shortening can lead to a hostname that has a trailing dot.
Therefore it should be done before checking from trailing dots.

(cherry picked from commit 46e1a2278116e2f5067c35127ccbd8589335f734)
Resolves: #1631625
---
 src/shared/util.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/shared/util.c b/src/shared/util.c
index c71e021cd7..4ba4693668 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -4641,6 +4641,8 @@ char* hostname_cleanup(char *s, bool lowercase) {
         char *p, *d;
         bool dot;
 
+        strshorten(s, HOST_NAME_MAX);
+
         for (p = s, d = s, dot = true; *p; p++) {
                 if (*p == '.') {
                         if (dot)
@@ -4660,8 +4662,6 @@ char* hostname_cleanup(char *s, bool lowercase) {
         else
                 *d = 0;
 
-        strshorten(s, HOST_NAME_MAX);
-
         return s;
 }