aboutsummaryrefslogtreecommitdiffstats
path: root/main/gnupg/CVE-2022-34903.patch
blob: 20bb9a23713aebb3e5d8b4ca1406c18235611f81 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
g10: Fix garbled status messages in NOTATION_DATA

* 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

diff --git a/g10/cpr.c b/g10/cpr.c
index d502e8b52..bc4b715ed 100644
--- a/g10/cpr.c
+++ b/g10/cpr.c
@@ -328,20 +328,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);