[commit] r2381 - Fix egregious object overwriting bug in sqUnixLocale.c.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[commit] r2381 - Fix egregious object overwriting bug in sqUnixLocale.c.

commits-3
 
Author: eliot
Date: 2011-04-27 11:17:24 -0700 (Wed, 27 Apr 2011)
New Revision: 2381

Modified:
   branches/Cog/platforms/unix/plugins/LocalePlugin/sqUnixLocale.c
Log:
Fix egregious object overwriting bug in sqUnixLocale.c.


Modified: branches/Cog/platforms/unix/plugins/LocalePlugin/sqUnixLocale.c
===================================================================
--- branches/Cog/platforms/unix/plugins/LocalePlugin/sqUnixLocale.c 2011-04-27 00:58:52 UTC (rev 2380)
+++ branches/Cog/platforms/unix/plugins/LocalePlugin/sqUnixLocale.c 2011-04-27 18:17:24 UTC (rev 2381)
@@ -608,11 +608,21 @@
   return localeConv->p_cs_precedes;
 }
 
+/* For Cog do *not* copy the trailing null sicne the VM checks for attempts to
+ * overwrite the end of an object, and copying the trailing null into a string
+ * does precisely this.
+ */
+#define safestrcpy(str,source) do { \
+ char *src = (source); \
+ int len = strlen(src); \
+ strncpy(str,src,len); \
+} while (0)
+
 /* Store the currency symbol into the given string.
  */
 void sqLocGetCurrencySymbolInto(char *str)
 {
-  strcpy(str, localeConv->currency_symbol);
+  safestrcpy(str, localeConv->currency_symbol);
 }
 
 sqInt sqLocCurrencySymbolSize(void)
@@ -637,7 +647,7 @@
  */
 void sqLocGetDigitGroupingSymbolInto(char *str)
 {
-  strcpy(str, localeConv->thousands_sep);
+  safestrcpy(str, localeConv->thousands_sep);
 }
 
 
@@ -645,7 +655,7 @@
  */
 void sqLocGetDecimalSymbolInto(char *str)
 {
-  strcpy(str, localeConv->decimal_point);
+  safestrcpy(str, localeConv->decimal_point);
 }
 
 
@@ -698,7 +708,7 @@
 */
 void sqLocGetLongDateFormatInto(char *str)
 {
-  strcpy(str, nl_langinfo(D_FMT));
+  safestrcpy(str, nl_langinfo(D_FMT));
 }
 
 /* Answer the number of characters in the short date format.
@@ -712,7 +722,7 @@
  */
 void sqLocGetShortDateFormatInto(char *str)
 {
-  strcpy(str, nl_langinfo(D_FMT));
+  safestrcpy(str, nl_langinfo(D_FMT));
 }
 
 /* Answer the number of characters in the time format.
@@ -726,7 +736,7 @@
  */
 void sqLocGetTimeFormatInto(char *str)
 {
-  strcpy(str, nl_langinfo(T_FMT));
+  safestrcpy(str, nl_langinfo(T_FMT));
 }
 
 
@@ -741,11 +751,11 @@
 
 void sqLocGetCountryInto(char * str)
 {
-  strcpy(str, getCountry());
+  safestrcpy(str, getCountry());
 }
 
 void sqLocGetLanguageInto(char * str)
 {
-  strcpy(str, getLanguage());
+  safestrcpy(str, getLanguage());
 }