From: Bruno Haible Date: Sun, 11 Jul 2004 13:20:03 +0000 (+0000) Subject: Fix endless loop. X-Git-Tag: v0.14.2~252 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a4d584d29dac38d83e8dfc653316fc15f2167f9c;p=thirdparty%2Fgettext.git Fix endless loop. --- diff --git a/gettext-runtime/src/ChangeLog b/gettext-runtime/src/ChangeLog index 692ad6d4e..8633980c3 100644 --- a/gettext-runtime/src/ChangeLog +++ b/gettext-runtime/src/ChangeLog @@ -1,3 +1,10 @@ +2004-07-10 Bruno Haible + + * 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 . + 2004-07-10 Bruno Haible * gettext.c (expand_escape): Support also \a and \v. diff --git a/gettext-runtime/src/gettext.c b/gettext-runtime/src/gettext.c index 6e3360f03..24c459394 100644 --- a/gettext-runtime/src/gettext.c +++ b/gettext-runtime/src/gettext.c @@ -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 */ diff --git a/gettext-runtime/src/ngettext.c b/gettext-runtime/src/ngettext.c index f17474124..f82908e52 100644 --- a/gettext-runtime/src/ngettext.c +++ b/gettext-runtime/src/ngettext.c @@ -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 */ diff --git a/gettext-tools/tests/ChangeLog b/gettext-tools/tests/ChangeLog index d6a9f8524..acbdb4875 100644 --- a/gettext-tools/tests/ChangeLog +++ b/gettext-tools/tests/ChangeLog @@ -1,3 +1,9 @@ +2004-07-10 Bruno Haible + + * 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 . + 2004-07-10 Bruno Haible * tstgettext.c (expand_escape): Support also \a and \v. diff --git a/gettext-tools/tests/tstgettext.c b/gettext-tools/tests/tstgettext.c index fb93c925d..15bbbbf89 100644 --- a/gettext-tools/tests/tstgettext.c +++ b/gettext-tools/tests/tstgettext.c @@ -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 */