]> granicus.if.org Git - sudo/commitdiff
Fix printing of the remainder after a newline. Fixes "sudo -l" output
authorTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 16 Mar 2011 14:26:19 +0000 (10:26 -0400)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 16 Mar 2011 14:26:19 +0000 (10:26 -0400)
corruption that could occur in some cases.

--HG--
branch : 1.7

lbuf.c

diff --git a/lbuf.c b/lbuf.c
index d5adfdc1d705c207d5a56bdc0bceb0e995f325a0..bafea18f8c65be2f9f4b564e11ae37ff61def04f 100644 (file)
--- a/lbuf.c
+++ b/lbuf.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007-2010 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 2007-2011 Todd C. Miller <Todd.Miller@courtesan.com>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -280,12 +280,14 @@ lbuf_print(lbuf)
     struct lbuf *lbuf;
 {
     char *cp, *ep;
-    int len, contlen;
+    int len;
 
-    contlen = lbuf->continuation ? strlen(lbuf->continuation) : 0;
+    if (lbuf->buf == NULL || lbuf->len == 0)
+       goto done;
 
     /* For very small widths just give up... */
-    if (lbuf->cols <= lbuf->indent + contlen + 20) {
+    len = lbuf->continuation ? strlen(lbuf->continuation) : 0;
+    if (lbuf->cols <= lbuf->indent + len + 20) {
        lbuf->buf[lbuf->len] = '\0';
        lbuf->output(lbuf->buf);
        goto done;
@@ -297,9 +299,11 @@ lbuf_print(lbuf)
            lbuf->output("\n");
            cp++;
        } else {
-           ep = memchr(cp, '\n', lbuf->len - (cp - lbuf->buf));
-           len = ep ? (int)(ep - cp) : lbuf->len;
-           lbuf_println(lbuf, cp, len);
+           len = lbuf->len - (cp - lbuf->buf);
+           if ((ep = memchr(cp, '\n', len)) != NULL)
+               len = (int)(ep - cp);
+           if (len)
+               lbuf_println(lbuf, cp, len);
            cp = ep ? ep + 1 : NULL;
        }
     }