summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2015-04-21 13:50:11 -0400
committerRich Felker <dalias@aerifal.cx>2015-04-21 13:54:58 -0400
commit873e0ec7fc4d466cfcdec16a7648cc18609ba702 (patch)
tree7914da6362c779c2597973a13b03dbd2800932ab
parenta6274a1971b7aa1d12fdce3d040f847539a71049 (diff)
downloadmusl-873e0ec7fc4d466cfcdec16a7648cc18609ba702.tar.gz
fix duplocale clobbering of new locale struct with memcpy of old
when the non-stub duplocale code was added as part of the locale framework in commit 0bc03091bb674ebb9fa6fe69e4aec1da3ac484f2, the old code to memcpy the old locale object to the new one was left behind. the conditional for the memcpy no longer makes sense, because the conditions are now always-true when it's reached, and the memcpy is wrong because it clobbers the new->messages_name pointer setup just above. since the messages_name and ctype_utf8 members have already been copied, all that remains is the cat[] array. these pointers are volatile, so using memcpy to copy them is formally wrong; use a for loop instead.
-rw-r--r--src/locale/duplocale.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/locale/duplocale.c b/src/locale/duplocale.c
index 13368707..b87c933e 100644
--- a/src/locale/duplocale.c
+++ b/src/locale/duplocale.c
@@ -14,7 +14,8 @@ locale_t __duplocale(locale_t old)
if (old->messages_name)
strcpy(new->messages_name, old->messages_name);
- if (new && old != LC_GLOBAL_LOCALE) memcpy(new, old, sizeof *new);
+ for (size_t i=0; i<sizeof new->cat/sizeof new->cat[0]; i++)
+ new->cat[i] = old->cat[i];
return new;
}