From 3b2382648013fadf8c2acae9d391395bb3d98eb2 Mon Sep 17 00:00:00 2001 From: rfm Date: Tue, 30 May 2006 05:52:51 +0000 Subject: [PATCH] Fix for bug when conversion fails due to lack of buffer space. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@23007 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 7 +++++ Source/Additions/Unicode.m | 53 ++++++++++++++++++++++---------------- 2 files changed, 38 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index a18a5960a..cc9dd7d9f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2006-05-30 Richard Frith-Macdonald + + * Source/Additions/Unicode.m: Use 'goto' to jump to 'done' label on + failure to grow buffer, rather than 'break' ... because the GROW() + macro is not aways called where a break gets you to the right place. + Fixes bug spotted by David Ayers, and is also clearer code. + 2006-05-26 Richard Frith-Macdonald * Tools/objctidy.m: Crude utility to help importing code into diff --git a/Source/Additions/Unicode.m b/Source/Additions/Unicode.m index e68bebbe3..8810613d2 100644 --- a/Source/Additions/Unicode.m +++ b/Source/Additions/Unicode.m @@ -1174,7 +1174,7 @@ if (dst == 0) \ else if (zone == 0) \ { \ result = NO; /* No buffer growth possible ... fail. */ \ - break; \ + goto done; \ } \ else \ { \ @@ -1325,14 +1325,14 @@ GSToUnicode(unichar **dst, unsigned int *size, const unsigned char *src, if ((sle < 2) || (sle > 6)) { result = NO; - break; + goto done; } /* do we have enough bytes ? */ if ((spos + sle) > slen) { result = NO; - break; + goto done; } /* get the codepoint */ @@ -1345,7 +1345,7 @@ GSToUnicode(unichar **dst, unsigned int *size, const unsigned char *src, if (i < sle) { result = NO; - break; + goto done; } u = u & ~(0xffffffff << ((5 * sle) + 1)); spos += sle; @@ -1357,13 +1357,13 @@ GSToUnicode(unichar **dst, unsigned int *size, const unsigned char *src, || (u >= 0xfdd0 && u <= 0xfdef)) { result = NO; // Invalid character. - break; + goto done; } if ((u >= 0xd800) && (u <= 0xdfff)) { result = NO; // Unmatched half of surrogate pair. - break; + goto done; } } else @@ -1412,7 +1412,7 @@ GSToUnicode(unichar **dst, unsigned int *size, const unsigned char *src, if (c > 127) { result = NO; // Non-ascii data found in input. - break; + goto done; } if (dpos >= bsize) { @@ -1542,7 +1542,7 @@ tables: { NSLog(@"No iconv for encoding x%02x", enc); result = NO; - break; + goto done; } if (slen == 0) { @@ -1554,7 +1554,7 @@ tables: NSLog(@"No iconv for encoding %@ tried to use %s", GetEncodingName(enc), estr); result = NO; - break; + goto done; } inbuf = (unsigned char*)src; @@ -1587,7 +1587,7 @@ tables: else { result = NO; - break; + goto done; } } } while (!done || rval != 0); @@ -1599,6 +1599,8 @@ tables: #endif } +done: + /* * Post conversion ... set output values. */ @@ -1697,7 +1699,7 @@ if (dst == 0) \ else if (zone == 0) \ { \ result = NO; /* No buffer growth possible ... fail. */ \ - break; \ + goto done; \ } \ else \ { \ @@ -1878,6 +1880,11 @@ GSFromUnicode(unsigned char **dst, unsigned int *size, const unichar *src, bsize = *size; } + if (result == NO) + { + goto done; + } + #ifdef HAVE_ICONV if (strict == NO && enc != NSUTF8StringEncoding @@ -1910,7 +1917,7 @@ GSFromUnicode(unsigned char **dst, unsigned int *size, const unichar *src, if (strict) { result = NO; - break; + goto done; } continue; // Skip invalid character. } @@ -1923,7 +1930,7 @@ GSFromUnicode(unsigned char **dst, unsigned int *size, const unichar *src, if (strict) { result = NO; - break; + goto done; } continue; // At end. } @@ -1941,7 +1948,7 @@ GSFromUnicode(unsigned char **dst, unsigned int *size, const unichar *src, if (strict) { result = NO; - break; + goto done; } continue; // Skip bad half of surrogate pair. } @@ -2071,7 +2078,7 @@ bases: else { result = NO; - break; + goto done; } } } @@ -2197,7 +2204,7 @@ tables: */ result = NO; spos = slen; - break; + goto done; } } break; @@ -2238,7 +2245,7 @@ iconv_start: { NSLog(@"No iconv for encoding x%02x", enc); result = NO; - break; + goto done; } if (slen == 0) { @@ -2250,7 +2257,7 @@ iconv_start: NSLog(@"No iconv for encoding %@ tried to use %s", GetEncodingName(enc), estr); result = NO; - break; + goto done; } inbuf = (unsigned char*)src; @@ -2287,7 +2294,7 @@ iconv_start: if (strict == YES) { result = NO; - break; + goto done; } /* * If we are allowing lossy conversion, we replace any @@ -2304,7 +2311,7 @@ iconv_start: else { result = NO; - break; + goto done; } } else if (strict == YES) @@ -2315,7 +2322,7 @@ iconv_start: * so if we are doing strict conversions we must fail. */ result = NO; - break; + goto done; } } } while (!done || rval != 0); @@ -2324,10 +2331,12 @@ iconv_start: } #else result = NO; - break; + goto done; #endif } + done: + /* * Post conversion ... set output values. */