gettext: fix for 64-bit systems

On the surface, this patch looks as if it only fixes a compile warning:
the canonicalize_file_name() and win2unixpath() functions are used
without having them declared. Everything still compiles fine, and
cursory testing in most setups shows that everything is fine.

Except that it is not.

When GCC sees that canonicalize_file_name() is used without a
declaration, it will assume implicitly that the return value is an int.
A 32-bit one, to be precise. So when those two functions return a
pointer (a 64-bit one), the most significant 32 bits are simply cut off.
Except they are not cut off: they are left in the state as before.

This developer encountered this issue in the form of a segmentation
fault when running with the FLG_LDR_TOP_DOWN enabled [*1*], because the
machine register holding the return value still held a 0xffffffff from
the return address.

Footnote *1*:
https://technet.microsoft.com/en-us/library/cc779664%28v=ws.10%29.aspx

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
Johannes Schindelin
2016-02-04 17:54:24 +01:00
parent 02ed890b54
commit 265a07e70c
2 changed files with 54 additions and 22 deletions

View File

@@ -20,16 +20,21 @@ GnuWin32: http://gnuwin32.sourceforge.net/
Great thanks to GnuWin32 maintainer Kees Zeelenberg.
--
[jes: fixed for 64-bit]
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
MINGW-PATCHES/README-relocatex-libintl.txt | 23 ++
gettext-runtime/intl/Makefile.in | 9 +
gettext-runtime/intl/bindtextdom.c | 22 ++
gettext-runtime/intl/canonicalize.c | 329 +++++++++++++++++++++++++++++
gettext-runtime/intl/relocatex.c | 295 ++++++++++++++++++++++++++
gettext-runtime/intl/canonicalize.c | 343 +++++++++++++++++++++++++++++
gettext-runtime/intl/canonicalize.h | 18 ++
gettext-runtime/intl/relocatex.c | 284 ++++++++++++++++++++++++
gettext-runtime/intl/relocatex.h | 41 ++++
6 files changed, 719 insertions(+)
7 files changed, 740 insertions(+)
create mode 100644 MINGW-PATCHES/README-relocatex-libintl.txt
create mode 100644 gettext-runtime/intl/canonicalize.c
create mode 100644 gettext-runtime/intl/canonicalize.h
create mode 100644 gettext-runtime/intl/relocatex.c
create mode 100644 gettext-runtime/intl/relocatex.h
@@ -154,10 +159,10 @@ index 2e7ada4..bd0cddd 100644
/* Specify the character encoding in which the messages from the
diff --git a/gettext-runtime/intl/canonicalize.c b/gettext-runtime/intl/canonicalize.c
new file mode 100644
index 0000000..532eb5a
index 0000000..ae2aa93
--- /dev/null
+++ b/gettext-runtime/intl/canonicalize.c
@@ -0,0 +1,329 @@
@@ -0,0 +1,343 @@
+/* Return the canonical absolute name of a given file.
+ Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
@@ -191,6 +196,7 @@ index 0000000..532eb5a
+# include <windows.h>
+//# include <gw32.h>
+#endif /* __WIN32__ */
+#include "canonicalize.h"
+
+#ifndef MAXSYMLINKS
+# define MAXSYMLINKS 20
@@ -217,6 +223,19 @@ index 0000000..532eb5a
+# define ISDIRSEP(C) ((C) == '/')
+#endif
+
+#ifdef __WIN32__
+char *win2unixpath (char *FileName)
+{
+ char *s = FileName;
+ while (*s) {
+ if (*s == '\\')
+ *s = '/';
+ *s++;
+ }
+ return FileName;
+}
+#endif
+
+/* Return the canonical absolute name of file NAME. A canonical name
+ does not contain any `.', `..' components nor any repeated path
+ separators ('/') or symlinks. All path components must exist. If
@@ -487,12 +506,36 @@ index 0000000..532eb5a
+{
+ return canonicalize (name, NULL);
+}
diff --git a/gettext-runtime/intl/canonicalize.h b/gettext-runtime/intl/canonicalize.h
new file mode 100644
index 0000000..ea707bf
--- /dev/null
+++ b/gettext-runtime/intl/canonicalize.h
@@ -0,0 +1,18 @@
+#ifndef __CANONICALIZE_H__
+#define __CANONICALIZE_H__ 1
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+char *canonicalize_file_name (const char *name);
+
+#ifdef __WIN32__
+char *win2unixpath (char *path);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CANONICALIZE_H__ */
diff --git a/gettext-runtime/intl/relocatex.c b/gettext-runtime/intl/relocatex.c
new file mode 100644
index 0000000..8e91a88
index 0000000..a2b7438
--- /dev/null
+++ b/gettext-runtime/intl/relocatex.c
@@ -0,0 +1,295 @@
@@ -0,0 +1,284 @@
+/* Provide relocatable packages.
+ Copyright (C) 2003 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2003.
@@ -522,7 +565,7 @@ index 0000000..8e91a88
+#include <unistd.h>
+/* #include <path.h> */
+#include "relocatex.h"
+//#include "canonicalize.h"
+#include "canonicalize.h"
+/* #include <gw32.h> */
+
+
@@ -552,17 +595,6 @@ index 0000000..8e91a88
+ to them must start with a slash. */
+
+
+char *win2unixpath (char *FileName)
+{
+ char *s = FileName;
+ while (*s) {
+ if (*s == '\\')
+ *s = '/';
+ *s++;
+ }
+ return FileName;
+}
+
+int win2posixpath (const char *winpath, char *posixpath)
+{
+ strcpy (posixpath, winpath);

View File

@@ -5,7 +5,7 @@ _realname=gettext
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.19.6
pkgrel=2
pkgrel=3
arch=('any')
pkgdesc="GNU internationalization library (mingw-w64)"
depends=("${MINGW_PACKAGE_PREFIX}-expat"
@@ -31,7 +31,7 @@ source=("http://ftp.gnu.org/pub/gnu/${_realname}/${_realname}-${pkgver}.tar.gz"{
121-keep-posix-path.patch)
md5sums=('6d1447f8c5c45c329371ef4bfe7d79a5'
'SKIP'
'397d7d6d4abd15a70edb3c9f2bab4cd2'
'30339a9e550ade812e96eb1c4d1264a8'
'6fc5459e5afa3f9df7602fcd1d09355b'
'0f754bf438368854ef63886715a3b023'
'27852a388b8cf38188dc392c244230ff'