]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Fix endless loop.
authorBruno Haible <bruno@clisp.org>
Sun, 11 Jul 2004 13:20:03 +0000 (13:20 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:11:52 +0000 (12:11 +0200)
gettext-runtime/src/ChangeLog
gettext-runtime/src/gettext.c
gettext-runtime/src/ngettext.c
gettext-tools/tests/ChangeLog
gettext-tools/tests/tstgettext.c

index 692ad6d4ec2d7ac3e02c04494e82e6ecddc3970e..8633980c3f3d0dd37329d4bfc4783653c354c404 100644 (file)
@@ -1,3 +1,10 @@
+2004-07-10  Bruno Haible  <bruno@clisp.org>
+
+       * gettext.c (expand_escape): Don't go into an endless loop when the
+       first backslash is not followed by one of the expected characters.
+       * ngettext.c (expand_escape): Likewise.
+       Reported by Arkadiusz Miśkiewicz <arekm@pld-linux.org>.
+
 2004-07-10  Bruno Haible  <bruno@clisp.org>
 
        * gettext.c (expand_escape): Support also \a and \v.
index 6e3360f03f3e01364748f800d847592c49f57bda..24c4593940d25f81d73f54f08008a78fb41d5745 100644 (file)
@@ -287,16 +287,19 @@ expand_escape (const char *str)
   char *retval, *rp;
   const char *cp = str;
 
-  do
+  for (;;)
     {
       while (cp[0] != '\0' && cp[0] != '\\')
        ++cp;
+      if (cp[0] == '\0')
+       return str;
+      /* Found a backslash.  */
+      if (cp[1] == '\0')
+       return str;
+      if (strchr ("abcfnrtv\\01234567", cp[1]) != NULL)
+       break;
+      ++cp;
     }
-  while (cp[0] != '\0' && cp[1] != '\0'
-        && strchr ("abcfnrtv\\01234567", cp[1]) == NULL);
-
-  if (cp[0] == '\0')
-    return str;
 
   retval = (char *) xmalloc (strlen (str));
 
@@ -305,6 +308,7 @@ expand_escape (const char *str)
 
   do
     {
+      /* Here cp[0] == '\\'.  */
       switch (*++cp)
        {
        case 'a':               /* alert */
index f1747412409983d7add67c9733802427db275760..f82908e5257b630944d8a907b4e9d9f24dbfef17 100644 (file)
@@ -253,16 +253,19 @@ expand_escape (const char *str)
   char *retval, *rp;
   const char *cp = str;
 
-  do
+  for (;;)
     {
       while (cp[0] != '\0' && cp[0] != '\\')
        ++cp;
+      if (cp[0] == '\0')
+       return str;
+      /* Found a backslash.  */
+      if (cp[1] == '\0')
+       return str;
+      if (strchr ("abcfnrtv\\01234567", cp[1]) != NULL)
+       break;
+      ++cp;
     }
-  while (cp[0] != '\0' && cp[1] != '\0'
-        && strchr ("abfnrtv\\01234567", cp[1]) == NULL);
-
-  if (cp[0] == '\0')
-    return str;
 
   retval = (char *) xmalloc (strlen (str));
 
@@ -271,6 +274,7 @@ expand_escape (const char *str)
 
   do
     {
+      /* Here cp[0] == '\\'.  */
       switch (*++cp)
        {
        case 'a':               /* alert */
index d6a9f8524e8a467a1e0e3e379e1ea6cb20e10b1c..acbdb48757a648737b5283603a17e718b646fdc4 100644 (file)
@@ -1,3 +1,9 @@
+2004-07-10  Bruno Haible  <bruno@clisp.org>
+
+       * tstgettext.c (expand_escape): Don't go into an endless loop when the
+       first backslash is not followed by one of the expected characters.
+       Reported by Arkadiusz Miśkiewicz <arekm@pld-linux.org>.
+
 2004-07-10  Bruno Haible  <bruno@clisp.org>
 
        * tstgettext.c (expand_escape): Support also \a and \v.
index fb93c925d4166386c142abaef40170a8d0f08dd8..15bbbbf8907850a63c3f83a1c9babec41074a16e 100644 (file)
@@ -312,16 +312,19 @@ expand_escape (const char *str)
   char *retval, *rp;
   const char *cp = str;
 
-  do
+  for (;;)
     {
       while (cp[0] != '\0' && cp[0] != '\\')
        ++cp;
+      if (cp[0] == '\0')
+       return str;
+      /* Found a backslash.  */
+      if (cp[1] == '\0')
+       return str;
+      if (strchr ("abcfnrtv\\01234567", cp[1]) != NULL)
+       break;
+      ++cp;
     }
-  while (cp[0] != '\0' && cp[1] != '\0'
-        && strchr ("abcfnrtv\\01234567", cp[1]) == NULL);
-
-  if (cp[0] == '\0')
-    return str;
 
   retval = (char *) xmalloc (strlen (str));
 
@@ -330,6 +333,7 @@ expand_escape (const char *str)
 
   do
     {
+      /* Here cp[0] == '\\'.  */
       switch (*++cp)
        {
        case 'a':               /* alert */