[Python-checkins] r52117 - python/branches/release24-maint/Modules/unicodedata.c

andrew.kuchling python-checkins at python.org
Tue Oct 3 21:27:00 CEST 2006


Author: andrew.kuchling
Date: Tue Oct 3 21:27:00 2006
New Revision: 52117
Modified:
 python/branches/release24-maint/Modules/unicodedata.c
Log:
[Backport r50858 | neal.norwitz]
No functional change. Add comment and assert to describe why there
cannot be overflow which was reported by Klocwork. Discussed on
python-dev.
Modified: python/branches/release24-maint/Modules/unicodedata.c
==============================================================================
--- python/branches/release24-maint/Modules/unicodedata.c	(original)
+++ python/branches/release24-maint/Modules/unicodedata.c	Tue Oct 3 21:27:00 2006
@@ -230,6 +230,7 @@
 PyUnicodeObject *v;
 char decomp[256];
 int code, index, count, i;
+ unsigned int prefix_index;
 
 if (!PyArg_ParseTuple(args, "O!:decomposition",
 			 &PyUnicode_Type, &v))
@@ -257,9 +258,15 @@
 /* XXX: could allocate the PyString up front instead
 (strlen(prefix) + 5 * count + 1 bytes) */
 
+ /* Based on how index is calculated above and decomp_data is generated
+ from Tools/unicode/makeunicodedata.py, it should not be possible
+ to overflow decomp_prefix. */
+ prefix_index = decomp_data[index] & 255;
+ assert(prefix_index < (sizeof(decomp_prefix)/sizeof(*decomp_prefix)));
+
 /* copy prefix */
- i = strlen(decomp_prefix[decomp_data[index] & 255]);
- memcpy(decomp, decomp_prefix[decomp_data[index] & 255], i);
+ i = strlen(decomp_prefix[prefix_index]);
+ memcpy(decomp, decomp_prefix[prefix_index], i);
 
 while (count-- > 0) {
 if (i)


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /