g10: Fix garbled status messages in NOTATION_DATA
authorWerner Koch <wk@gnupg.org>
Tue, 14 Jun 2022 09:33:27 +0000 (11:33 +0200)
committerDaniel Kahn Gillmor <dkg@fifthhorseman.net>
Fri, 1 Jul 2022 16:06:43 +0000 (17:06 +0100)
* g10/cpr.c (write_status_text_and_buffer): Fix off-by-one
--

Depending on the escaping and line wrapping the computed remaining
buffer length could be wrong.  Fixed by always using a break to
terminate the escape detection loop.  Might have happened for all
status lines which may wrap.

GnuPG-bug-id: T6027
(cherry picked from commit 34c649b3601383cd11dbc76221747ec16fd68e1b)

Gbp-Pq: Topic from-master
Gbp-Pq: Name g10-Fix-garbled-status-messages-in-NOTATION_DATA.patch

g10/cpr.c

index d40e0a7a96625429bad4655e5bb1edbb9011d6ef..6a88e9df392ea8bc5b2b6dc86081eb299a9469cf 100644 (file)
--- a/g10/cpr.c
+++ b/g10/cpr.c
@@ -304,20 +304,15 @@ write_status_text_and_buffer (int no, const char *string,
             }
           first = 0;
         }
-      for (esc=0, s=buffer, n=len; n && !esc; s++, n--)
+      for (esc=0, s=buffer, n=len; n; s++, n--)
         {
           if (*s == '%' || *(const byte*)s <= lower_limit
               || *(const byte*)s == 127 )
             esc = 1;
           if (wrap && ++count > wrap)
-            {
-              dowrap=1;
-              break;
-            }
-        }
-      if (esc)
-        {
-          s--; n++;
+            dowrap=1;
+          if (esc || dowrap)
+            break;
         }
       if (s != buffer)
         es_fwrite (buffer, s-buffer, 1, statusfp);