1ff962
From 34c649b3601383cd11dbc76221747ec16fd68e1b Mon Sep 17 00:00:00 2001
1ff962
From: Werner Koch <wk@gnupg.org>
1ff962
Date: Tue, 14 Jun 2022 11:33:27 +0200
1ff962
Subject: [PATCH GnuPG] g10: Fix garbled status messages in NOTATION_DATA
1ff962
1ff962
* g10/cpr.c (write_status_text_and_buffer): Fix off-by-one
1ff962
--
1ff962
1ff962
Depending on the escaping and line wrapping the computed remaining
1ff962
buffer length could be wrong.  Fixed by always using a break to
1ff962
terminate the escape detection loop.  Might have happened for all
1ff962
status lines which may wrap.
1ff962
1ff962
GnuPG-bug-id: T6027
1ff962
---
1ff962
 g10/cpr.c | 13 ++++---------
1ff962
 1 file changed, 4 insertions(+), 9 deletions(-)
1ff962
1ff962
diff --git a/g10/cpr.c b/g10/cpr.c
1ff962
index 9bfdd3c34..fa8005d6f 100644
1ff962
--- a/g10/cpr.c
1ff962
+++ b/g10/cpr.c
1ff962
@@ -372,20 +372,15 @@ write_status_text_and_buffer (int no, const char *string,
1ff962
             }
1ff962
           first = 0;
1ff962
         }
1ff962
-      for (esc=0, s=buffer, n=len; n && !esc; s++, n--)
1ff962
+      for (esc=0, s=buffer, n=len; n; s++, n--)
1ff962
         {
1ff962
           if (*s == '%' || *(const byte*)s <= lower_limit
1ff962
               || *(const byte*)s == 127 )
1ff962
             esc = 1;
1ff962
           if (wrap && ++count > wrap)
1ff962
-            {
1ff962
-              dowrap=1;
1ff962
-              break;
1ff962
-            }
1ff962
-        }
1ff962
-      if (esc)
1ff962
-        {
1ff962
-          s--; n++;
1ff962
+            dowrap=1;
1ff962
+          if (esc || dowrap)
1ff962
+            break;
1ff962
         }
1ff962
       if (s != buffer)
1ff962
         es_fwrite (buffer, s-buffer, 1, statusfp);
1ff962
-- 
1ff962
2.37.1
1ff962