Package: gettext / 0.19.3-2

04-xgettext-fix-double-free Patch series | download
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
From: Daiki Ueno <ueno@gnu.org>
Subject: Fix double-free in singular/plural argument extraction
X-Debian-version: 0.19.3-2

--- a/gettext-tools/src/xgettext.c
+++ b/gettext-tools/src/xgettext.c
@@ -3099,9 +3099,9 @@
                 char *msgid = parser->parse (best_cp->msgid,
                                              &best_cp->msgid_pos,
                                              best_cp->msgid_escape);
-                free (best_cp->msgid);
                 if (best_cp->msgid_plural == best_cp->msgid)
                   best_cp->msgid_plural = msgid;
+                free (best_cp->msgid);
                 best_cp->msgid = msgid;
               }
             else
@@ -3110,26 +3110,7 @@
                 CONVERT_STRING (best_cp->msgid, lc_string);
               }
 
-            if (best_cp->msgid_comment != NULL)
-              {
-                refcounted_string_list_ty *msgid_comment =
-                  savable_comment_convert_encoding (best_cp->msgid_comment,
-                                                    &best_cp->msgid_pos);
-                drop_reference (best_cp->msgid_comment);
-                best_cp->msgid_comment = msgid_comment;
-              }
-
-            /* best_cp->msgctxt and best_cp->msgid are already in
-               UTF-8.  Prevent further conversion in remember_a_message.  */
-            encoding = xgettext_current_source_encoding;
-            xgettext_current_source_encoding = po_charset_utf8;
-            mp = remember_a_message (ap->mlp, best_cp->msgctxt, best_cp->msgid,
-                                     msgid_context,
-                                     &best_cp->msgid_pos,
-                                     NULL, best_cp->msgid_comment);
-            xgettext_current_source_encoding = encoding;
-
-            if (mp != NULL && best_cp->msgid_plural != NULL)
+            if (best_cp->msgid_plural)
               {
                 /* best_cp->msgid_plural may point to best_cp->msgid.
                    In that case, it is already interpreted and converted.  */
@@ -3152,14 +3133,41 @@
                       }
                   }
 
-                encoding = xgettext_current_source_encoding;
-                xgettext_current_source_encoding = po_charset_utf8;
-                remember_a_message_plural (mp, best_cp->msgid_plural,
-                                           msgid_plural_context,
-                                           &best_cp->msgid_plural_pos,
-                                           NULL);
-                xgettext_current_source_encoding = encoding;
+                /* If best_cp->msgid_plural equals to best_cp->msgid,
+                   the ownership will be transferred to
+                   remember_a_message before it is passed to
+                   remember_a_message_plural.
+
+                   Make a copy of the string in that case.  */
+                if (best_cp->msgid_plural == best_cp->msgid)
+                  best_cp->msgid_plural = xstrdup (best_cp->msgid);
+              }
+
+            if (best_cp->msgid_comment != NULL)
+              {
+                refcounted_string_list_ty *msgid_comment =
+                  savable_comment_convert_encoding (best_cp->msgid_comment,
+                                                    &best_cp->msgid_pos);
+                drop_reference (best_cp->msgid_comment);
+                best_cp->msgid_comment = msgid_comment;
               }
+
+            /* best_cp->msgctxt, best_cp->msgid, and best_cp->msgid_plural
+               are already in UTF-8.  Prevent further conversion in
+               remember_a_message.  */
+            encoding = xgettext_current_source_encoding;
+            xgettext_current_source_encoding = po_charset_utf8;
+            mp = remember_a_message (ap->mlp, best_cp->msgctxt, best_cp->msgid,
+                                     msgid_context,
+                                     &best_cp->msgid_pos,
+                                     NULL, best_cp->msgid_comment);
+            if (mp != NULL && best_cp->msgid_plural != NULL)
+              remember_a_message_plural (mp,
+                                         best_cp->msgid_plural,
+                                         msgid_plural_context,
+                                         &best_cp->msgid_plural_pos,
+                                         NULL);
+            xgettext_current_source_encoding = encoding;
           }
 
           if (best_cp->xcomments.nitems > 0)