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
This commit is contained in:
rfm 2006-05-30 05:52:51 +00:00
parent 019fcaa463
commit 3b23826480
2 changed files with 38 additions and 22 deletions

View file

@ -1,3 +1,10 @@
2006-05-30 Richard Frith-Macdonald <rfm@gnu.org>
* 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 <rfm@gnu.org> 2006-05-26 Richard Frith-Macdonald <rfm@gnu.org>
* Tools/objctidy.m: Crude utility to help importing code into * Tools/objctidy.m: Crude utility to help importing code into

View file

@ -1174,7 +1174,7 @@ if (dst == 0) \
else if (zone == 0) \ else if (zone == 0) \
{ \ { \
result = NO; /* No buffer growth possible ... fail. */ \ result = NO; /* No buffer growth possible ... fail. */ \
break; \ goto done; \
} \ } \
else \ else \
{ \ { \
@ -1325,14 +1325,14 @@ GSToUnicode(unichar **dst, unsigned int *size, const unsigned char *src,
if ((sle < 2) || (sle > 6)) if ((sle < 2) || (sle > 6))
{ {
result = NO; result = NO;
break; goto done;
} }
/* do we have enough bytes ? */ /* do we have enough bytes ? */
if ((spos + sle) > slen) if ((spos + sle) > slen)
{ {
result = NO; result = NO;
break; goto done;
} }
/* get the codepoint */ /* get the codepoint */
@ -1345,7 +1345,7 @@ GSToUnicode(unichar **dst, unsigned int *size, const unsigned char *src,
if (i < sle) if (i < sle)
{ {
result = NO; result = NO;
break; goto done;
} }
u = u & ~(0xffffffff << ((5 * sle) + 1)); u = u & ~(0xffffffff << ((5 * sle) + 1));
spos += sle; spos += sle;
@ -1357,13 +1357,13 @@ GSToUnicode(unichar **dst, unsigned int *size, const unsigned char *src,
|| (u >= 0xfdd0 && u <= 0xfdef)) || (u >= 0xfdd0 && u <= 0xfdef))
{ {
result = NO; // Invalid character. result = NO; // Invalid character.
break; goto done;
} }
if ((u >= 0xd800) && (u <= 0xdfff)) if ((u >= 0xd800) && (u <= 0xdfff))
{ {
result = NO; // Unmatched half of surrogate pair. result = NO; // Unmatched half of surrogate pair.
break; goto done;
} }
} }
else else
@ -1412,7 +1412,7 @@ GSToUnicode(unichar **dst, unsigned int *size, const unsigned char *src,
if (c > 127) if (c > 127)
{ {
result = NO; // Non-ascii data found in input. result = NO; // Non-ascii data found in input.
break; goto done;
} }
if (dpos >= bsize) if (dpos >= bsize)
{ {
@ -1542,7 +1542,7 @@ tables:
{ {
NSLog(@"No iconv for encoding x%02x", enc); NSLog(@"No iconv for encoding x%02x", enc);
result = NO; result = NO;
break; goto done;
} }
if (slen == 0) if (slen == 0)
{ {
@ -1554,7 +1554,7 @@ tables:
NSLog(@"No iconv for encoding %@ tried to use %s", NSLog(@"No iconv for encoding %@ tried to use %s",
GetEncodingName(enc), estr); GetEncodingName(enc), estr);
result = NO; result = NO;
break; goto done;
} }
inbuf = (unsigned char*)src; inbuf = (unsigned char*)src;
@ -1587,7 +1587,7 @@ tables:
else else
{ {
result = NO; result = NO;
break; goto done;
} }
} }
} while (!done || rval != 0); } while (!done || rval != 0);
@ -1599,6 +1599,8 @@ tables:
#endif #endif
} }
done:
/* /*
* Post conversion ... set output values. * Post conversion ... set output values.
*/ */
@ -1697,7 +1699,7 @@ if (dst == 0) \
else if (zone == 0) \ else if (zone == 0) \
{ \ { \
result = NO; /* No buffer growth possible ... fail. */ \ result = NO; /* No buffer growth possible ... fail. */ \
break; \ goto done; \
} \ } \
else \ else \
{ \ { \
@ -1878,6 +1880,11 @@ GSFromUnicode(unsigned char **dst, unsigned int *size, const unichar *src,
bsize = *size; bsize = *size;
} }
if (result == NO)
{
goto done;
}
#ifdef HAVE_ICONV #ifdef HAVE_ICONV
if (strict == NO if (strict == NO
&& enc != NSUTF8StringEncoding && enc != NSUTF8StringEncoding
@ -1910,7 +1917,7 @@ GSFromUnicode(unsigned char **dst, unsigned int *size, const unichar *src,
if (strict) if (strict)
{ {
result = NO; result = NO;
break; goto done;
} }
continue; // Skip invalid character. continue; // Skip invalid character.
} }
@ -1923,7 +1930,7 @@ GSFromUnicode(unsigned char **dst, unsigned int *size, const unichar *src,
if (strict) if (strict)
{ {
result = NO; result = NO;
break; goto done;
} }
continue; // At end. continue; // At end.
} }
@ -1941,7 +1948,7 @@ GSFromUnicode(unsigned char **dst, unsigned int *size, const unichar *src,
if (strict) if (strict)
{ {
result = NO; result = NO;
break; goto done;
} }
continue; // Skip bad half of surrogate pair. continue; // Skip bad half of surrogate pair.
} }
@ -2071,7 +2078,7 @@ bases:
else else
{ {
result = NO; result = NO;
break; goto done;
} }
} }
} }
@ -2197,7 +2204,7 @@ tables:
*/ */
result = NO; result = NO;
spos = slen; spos = slen;
break; goto done;
} }
} }
break; break;
@ -2238,7 +2245,7 @@ iconv_start:
{ {
NSLog(@"No iconv for encoding x%02x", enc); NSLog(@"No iconv for encoding x%02x", enc);
result = NO; result = NO;
break; goto done;
} }
if (slen == 0) if (slen == 0)
{ {
@ -2250,7 +2257,7 @@ iconv_start:
NSLog(@"No iconv for encoding %@ tried to use %s", NSLog(@"No iconv for encoding %@ tried to use %s",
GetEncodingName(enc), estr); GetEncodingName(enc), estr);
result = NO; result = NO;
break; goto done;
} }
inbuf = (unsigned char*)src; inbuf = (unsigned char*)src;
@ -2287,7 +2294,7 @@ iconv_start:
if (strict == YES) if (strict == YES)
{ {
result = NO; result = NO;
break; goto done;
} }
/* /*
* If we are allowing lossy conversion, we replace any * If we are allowing lossy conversion, we replace any
@ -2304,7 +2311,7 @@ iconv_start:
else else
{ {
result = NO; result = NO;
break; goto done;
} }
} }
else if (strict == YES) else if (strict == YES)
@ -2315,7 +2322,7 @@ iconv_start:
* so if we are doing strict conversions we must fail. * so if we are doing strict conversions we must fail.
*/ */
result = NO; result = NO;
break; goto done;
} }
} }
} while (!done || rval != 0); } while (!done || rval != 0);
@ -2324,10 +2331,12 @@ iconv_start:
} }
#else #else
result = NO; result = NO;
break; goto done;
#endif #endif
} }
done:
/* /*
* Post conversion ... set output values. * Post conversion ... set output values.
*/ */