]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
Explicitly override only newlines
authorSamanta Navarro <ferivoz@riseup.net>
Mon, 30 Jan 2023 11:53:47 +0000 (11:53 +0000)
committerSerge Hallyn <serge@hallyn.com>
Wed, 1 Feb 2023 21:47:35 +0000 (15:47 -0600)
Override only newlines with '\0' to avoid undesired truncation of
actual line content.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
lib/port.c
libmisc/console.c

index 0bea2ef41e3f3769780292be0a8c3b4ea581d03b..90eb14987fdbdc0fecc49b049ba47c9a9b36889a 100644 (file)
@@ -130,8 +130,8 @@ static struct port *getportent (void)
       again:
 
        /*
-        * Get the next line and remove the last character, which
-        * is a '\n'.  Lines which begin with '#' are all ignored.
+        * Get the next line and remove optional trailing '\n'.
+        * Lines which begin with '#' are all ignored.
         */
 
        if (fgets (buf, (int) sizeof buf, ports) == 0) {
@@ -149,7 +149,7 @@ static struct port *getportent (void)
         * TTY devices.
         */
 
-       buf[strlen (buf) - 1] = 0;
+       buf[strcspn (buf, "\n")] = 0;
 
        port.pt_names = ttys;
        for (cp = buf, j = 0; j < PORT_TTY; j++) {
index bc024eba682384b59bdecc5dd3e13c5c3ef93aa9..63d3ceb31b5a3191540ad17a0156b1b1bac85ed5 100644 (file)
@@ -71,7 +71,8 @@ static bool is_listed (const char *cfgin, const char *tty, bool def)
         */
 
        while (fgets (buf, (int) sizeof (buf), fp) != NULL) {
-               buf[strlen (buf) - 1] = '\0';
+               /* Remove optional trailing '\n'. */
+               buf[strcspn (buf, "\n")] = '\0';
                if (strcmp (buf, tty) == 0) {
                        (void) fclose (fp);
                        return true;