summaryrefslogtreecommitdiff
path: root/wcsmbs/wcsmbsload.c
diff options
context:
space:
mode:
Diffstat (limited to 'wcsmbs/wcsmbsload.c')
-rw-r--r--wcsmbs/wcsmbsload.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/wcsmbs/wcsmbsload.c b/wcsmbs/wcsmbsload.c
index 02cf94bab8..39611b7636 100644
--- a/wcsmbs/wcsmbsload.c
+++ b/wcsmbs/wcsmbsload.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998-2018 Free Software Foundation, Inc.
+/* Copyright (C) 1998-2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
@@ -14,12 +14,13 @@
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
- <http://www.gnu.org/licenses/>. */
+ <https://www.gnu.org/licenses/>. */
#include <ctype.h>
#include <langinfo.h>
#include <limits.h>
#include <stdlib.h>
+#include <stdio.h>
#include <string.h>
#include <locale/localeinfo.h>
@@ -223,12 +224,25 @@ __wcsmbs_clone_conv (struct gconv_fcts *copy)
/* Copy the data. */
*copy = *orig;
- /* Now increment the usage counters.
- Note: This assumes copy->*_nsteps == 1. */
+ /* Now increment the usage counters. Note: This assumes
+ copy->*_nsteps == 1. The current locale holds a reference, so it
+ is still there after acquiring the lock. */
+
+ __libc_lock_lock (__gconv_lock);
+
+ bool overflow = false;
if (copy->towc->__shlib_handle != NULL)
- ++copy->towc->__counter;
+ overflow |= __builtin_add_overflow (copy->towc->__counter, 1,
+ &copy->towc->__counter);
if (copy->tomb->__shlib_handle != NULL)
- ++copy->tomb->__counter;
+ overflow |= __builtin_add_overflow (copy->tomb->__counter, 1,
+ &copy->tomb->__counter);
+
+ __libc_lock_unlock (__gconv_lock);
+
+ if (overflow)
+ __libc_fatal ("\
+Fatal glibc error: gconv module reference counter overflow\n");
}