Imported Upstream version 1.5.0 upstream upstream/1.5.0
authorBoram Park <boram1288.park@samsung.com>
Tue, 29 Jul 2014 06:51:01 +0000 (15:51 +0900)
committerBoram Park <boram1288.park@samsung.com>
Tue, 29 Jul 2014 06:51:01 +0000 (15:51 +0900)
50 files changed:
.gitignore [deleted file]
README
configure.ac
doc/.gitignore [deleted file]
include/X11/fonts/.gitignore [deleted file]
include/X11/fonts/fntfil.h
include/X11/fonts/fontmisc.h
src/FreeType/ftfuncs.c
src/FreeType/xttcap.c
src/Makefile.am
src/bitmap/Makefile.am
src/bitmap/bitmap.c
src/bitmap/bitmapfunc.c
src/bitmap/bitscale.c
src/builtins/builtin.h
src/builtins/dir.c
src/builtins/file.c
src/builtins/fpe.c
src/fc/fsconvert.c
src/fc/fserve.c
src/fc/fserve.h
src/fc/fsio.h
src/fontfile/bufio.c
src/fontfile/catalogue.c
src/fontfile/dirfile.c
src/fontfile/fontdir.c
src/fontfile/fontfile.c
src/fontfile/renderers.c
src/stubs/Makefile.am
src/stubs/cauthgen.c
src/stubs/csignal.c
src/stubs/delfntcid.c
src/stubs/errorf.c
src/stubs/fatalerror.c [deleted file]
src/stubs/findoldfnt.c
src/stubs/getcres.c
src/stubs/getdefptsize.c
src/stubs/getnewfntcid.c
src/stubs/gettime.c
src/stubs/initfshdl.c
src/stubs/regfpefunc.c
src/stubs/rmfshdl.c
src/stubs/servclient.c
src/stubs/setfntauth.c
src/stubs/stfntcfnt.c
src/stubs/stubs.h
src/stubs/stubsinit.c [new file with mode: 0644]
src/util/atom.c
src/util/miscutil.c
src/util/patcache.c

diff --git a/.gitignore b/.gitignore
deleted file mode 100644 (file)
index 183f4b6..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-#
-#              X.Org module default exclusion patterns
-#              The next section if for module specific patterns
-#
-#      Do not edit the following section
-#      GNU Build System (Autotools)
-aclocal.m4
-autom4te.cache/
-autoscan.log
-ChangeLog
-compile
-config.guess
-config.h
-config.h.in
-config.log
-config-ml.in
-config.py
-config.status
-config.status.lineno
-config.sub
-configure
-configure.scan
-depcomp
-.deps/
-INSTALL
-install-sh
-.libs/
-libtool
-libtool.m4
-ltmain.sh
-lt~obsolete.m4
-ltoptions.m4
-ltsugar.m4
-ltversion.m4
-Makefile
-Makefile.in
-mdate-sh
-missing
-mkinstalldirs
-*.pc
-py-compile
-stamp-h?
-symlink-tree
-texinfo.tex
-ylwrap
-
-#      Do not edit the following section
-#      Edit Compile Debug Document Distribute
-*~
-*.[0-9]
-*.[0-9]x
-*.bak
-*.bin
-core
-*.dll
-*.exe
-*-ISO*.bdf
-*-JIS*.bdf
-*-KOI8*.bdf
-*.kld
-*.ko
-*.ko.cmd
-*.lai
-*.l[oa]
-*.[oa]
-*.obj
-*.patch
-*.so
-*.pcf.gz
-*.pdb
-*.tar.bz2
-*.tar.gz
-#
-#              Add & Override patterns for libXfont 
-#
-#              Edit the following section as needed
-# For example, !report.pc overrides *.pc. See 'man gitignore'
-# 
diff --git a/README b/README
index 97a9e8a..c95c3cf 100644 (file)
--- a/README
+++ b/README
@@ -5,6 +5,65 @@ X Font Server (xfs), and some font utilities (bdftopcf for instance),
 but should not be used by normal X11 clients.  X11 clients access fonts
 via either the new API's in libXft, or the legacy API's in libX11.
 
+libXfont supports a number of compression and font formats, and the
+configure script takes various options to enable or disable them:
+
+ -- Compression types:
+
+    gzip - always enabled, no option to disable, requires libz
+
+    bzip2 - disabled by default, enable via --with-bzip2, requires libbz2
+
+ -- Font formats:
+
+    builtins - copies of the "fixed" & "cursor" fonts required by the
+            X protocol are built into the library so the X server always
+            has the fonts it requires to start up.   Accessed via the
+            special 'built-ins' entry in the X server font path.
+            Enabled by default, disable via --disable-builtins.
+
+    freetype - handles scalable font formats including OpenType, FreeType,
+            and PostScript formats.  Requires FreeType2 library.
+            Can also be used to handle bdf & bitmap pcf font formats.
+            Enabled by default, disable via --disable-freetype.
+
+    bdf bitmap fonts - text file format for distributing fonts, described
+            in http://www.x.org/docs/BDF/bdf.pdf specification.  Normally
+            not used by the X server at runtime, as the fonts distributed
+            by X.Org in bdf format are compiled with bdftopcf when
+            installing/packaging them.
+            Enabled by default, disable via --disable-bdfformat.
+
+    pcf bitmap fonts - standard bitmap font format since X11R5 in 1991,
+            used for all bitmap fonts installed from X.Org packages.
+            Compiled format is architecture independent.
+            As noted above, usually produced by bdftopcf.
+            Enabled by default, disable via --disable-pcfformat.
+
+    snf bitmap fonts - standard bitmap font format prior to X11R5 in 1991,
+            remains only for backwards compatibility.  Unlike pcf, snf files
+            are architecture specific, and contain less font information
+            than pcf files.  snf fonts are deprecated and support for them
+            may be removed in future libXfont releases.
+            Disabled by default, enable via --disable-snfformat.
+
+ -- Font services:
+
+    xfs font servers - allows retreiving fonts as a client of an xfs server.
+            Enabled by default, disable via --disable-fc (font client).
+
+            If enabled, you can also use the standard libxtrans flags to
+            configure which transports can be used to connect to xfs:
+              --enable-unix-transport Enable UNIX domain socket transport
+              --enable-tcp-transport  Enable TCP socket transport (IPv4)
+              --enable-ipv6           Enable IPv6 support for tcp-transport
+              --enable-local-transport Enable os-specific local transport
+            (Change --enable to --disable to force disabling support.)
+            The default setting is to enable all of the transports the
+            configure script can find OS support for.
+
+--------------------------------------------------------------------------
+
 Please submit bugs & patches to the Xorg bugzilla:
 
        https://bugs.freedesktop.org/enter_bug.cgi?product=xorg
index 01e7b6e..471b266 100644 (file)
@@ -21,7 +21,7 @@
 
 # Initialize Autoconf
 AC_PREREQ([2.60])
-AC_INIT([libXfont], [1.4.7],
+AC_INIT([libXfont], [1.5.0],
        [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], [libXfont])
 AC_CONFIG_SRCDIR([Makefile.am])
 AC_CONFIG_HEADERS([config.h include/X11/fonts/fontconf.h])
@@ -64,15 +64,20 @@ PKG_PROG_PKG_CONFIG
 XFONT_FONTFILE=no
 
 #
-# Scalable fonts in files:
-#      FreeType
-#      Bitstream Speedo rasterizer
+# FreeType for all scalable (OpenType, TrueType, PostScript) and
+# some bitmap formats (BDF & PCF)
 #
-AC_ARG_ENABLE(freetype, [ --disable-freetype],[XFONT_FREETYPE=$enableval],[XFONT_FREETYPE=yes])
+AC_ARG_ENABLE(freetype,
+       AS_HELP_STRING([--disable-freetype],
+               [Build freetype backend (default: enabled)]),
+       [XFONT_FREETYPE=$enableval],[XFONT_FREETYPE=yes])
 AM_CONDITIONAL(XFONT_FREETYPE, [test x$XFONT_FREETYPE = xyes])
 if test x$XFONT_FREETYPE = xyes; then
        AC_DEFINE(XFONT_FREETYPE,1,[Support FreeType rasterizer for nearly all font file formats])
-       AC_ARG_WITH(freetype-config, [  --with-freetype-config=PROG   Use FreeType configuration program PROG], freetype_config=$withval, freetype_config=auto)
+       AC_ARG_WITH(freetype-config,
+               AS_HELP_STRING([--with-freetype-config=PROG],
+                       [Use FreeType configuration program PROG]),
+               [freetype_config=$withval], [freetype_config=auto])
 
        if test "$freetype_config" = "auto" ; then
                PKG_CHECK_MODULES(FREETYPE, freetype2,
@@ -118,7 +123,7 @@ AC_CHECK_LIB(z, gzopen, [Z_LIBS=-lz], AC_MSG_ERROR([*** zlib is required]))
 
 AC_ARG_WITH(bzip2,
        AS_HELP_STRING([--with-bzip2],
-                       [Support bzip2 compressed bitmap fonts]),
+         [Use libbz2 to support bzip2 compressed bitmap fonts (default: no)]),
        [], [with_bzip2=no])
 if test "x$with_bzip2" = xyes; then
        AC_CHECK_LIB(bz2, BZ2_bzopen, [Z_LIBS="$Z_LIBS -lbz2"],
@@ -128,28 +133,43 @@ fi
 AM_CONDITIONAL(X_BZIP2_FONT_COMPRESSION, [test "x$with_bzip2" = xyes ])
 AC_SUBST(Z_LIBS)
 
-AC_ARG_ENABLE(builtins, [ --disable-builtins ], [XFONT_BUILTINS=$enableval], [XFONT_BUILTINS=yes])
+AC_ARG_ENABLE(builtins,
+       AS_HELP_STRING([--disable-builtins],
+               [Support builtin fonts (default: enabled)]),
+       [XFONT_BUILTINS=$enableval], [XFONT_BUILTINS=yes])
 AM_CONDITIONAL(XFONT_BUILTINS, [test "x$XFONT_BUILTINS" = xyes ])
 if test "x$XFONT_BUILTINS" = xyes; then
        AC_DEFINE(XFONT_BUILTINS,1,[Support built-in fonts])
        XFONT_BITMAP=yes
 fi
 
-AC_ARG_ENABLE(pcfformat, [ --disable-pcfformat ], [XFONT_PCFFORMAT=$enableval], [XFONT_PCFFORMAT=yes])
+AC_ARG_ENABLE(pcfformat,
+       AS_HELP_STRING([--disable-pcfformat],
+               [Support PCF format bitmap fonts (default: enabled)]),
+       [XFONT_PCFFORMAT=$enableval], [XFONT_PCFFORMAT=yes])
 AM_CONDITIONAL(XFONT_PCFFORMAT, [test "x$XFONT_PCFFORMAT" = xyes])
 if test "x$XFONT_PCFFORMAT" = xyes; then
        AC_DEFINE(XFONT_PCFFORMAT,1,[Support pcf format bitmap font files])
        XFONT_BITMAP=yes
 fi
 
-AC_ARG_ENABLE(bdfformat, [ --disable-bdfformat ], [XFONT_BDFFORMAT=$enableval], [XFONT_BDFFORMAT=yes])
+AM_CONDITIONAL(XFONT_PCF_OR_BUILTIN,
+       [test "x$XFONT_PCFFORMAT" = xyes -o "x$XFONT_BUILTINS" = xyes])
+
+AC_ARG_ENABLE(bdfformat,
+       AS_HELP_STRING([--disable-bdfformat],
+               [Support BDF format bitmap fonts (default: enabled)]),
+       [XFONT_BDFFORMAT=$enableval], [XFONT_BDFFORMAT=yes])
 AM_CONDITIONAL(XFONT_BDFFORMAT, [test "x$XFONT_BDFFORMAT" = xyes])
 if test "x$XFONT_BDFFORMAT" = xyes; then
        AC_DEFINE(XFONT_BDFFORMAT,1,[Support bdf format bitmap font files])
        XFONT_BITMAP=yes
 fi
 
-AC_ARG_ENABLE(snfformat, [ --disable-snfformat ], [XFONT_SNFFORMAT=$enableval], [XFONT_SNFFORMAT=yes])
+AC_ARG_ENABLE(snfformat,
+       AS_HELP_STRING([--enable-snfformat],
+               [Support SNF format bitmap fonts (default: disabled)]),
+       [XFONT_SNFFORMAT=$enableval], [XFONT_SNFFORMAT=no])
 AM_CONDITIONAL(XFONT_SNFFORMAT, [test "x$XFONT_SNFFORMAT" = xyes])
 if test "x$XFONT_SNFFORMAT" = xyes; then
        AC_DEFINE(XFONT_SNFFORMAT,1,[Support snf format bitmap font files])
@@ -171,7 +191,10 @@ fi
 # Support connection to font servers?
 #
 
-AC_ARG_ENABLE(fc, [ --disable-fc ],[XFONT_FC=$enableval],[XFONT_FC=yes])
+AC_ARG_ENABLE(fc,
+       AS_HELP_STRING([--disable-fc],
+               [Support connections to xfs servers (default: enabled)]),
+       [XFONT_FC=$enableval],[XFONT_FC=yes])
 AM_CONDITIONAL(XFONT_FC, [test "x$XFONT_FC" = xyes])
 if test "x$XFONT_FC" = xyes; then
        AC_DEFINE(XFONT_FC,1,[Support the X Font Services Protocol])
@@ -181,7 +204,7 @@ fi
 AC_CHECK_LIB(m, hypot, [MATH_LIBS=-lm
 AC_SUBST(MATH_LIBS)], AC_MSG_ERROR([*** libm is required]))
 
-PKG_CHECK_MODULES(XFONT, xproto xtrans fontsproto fontenc)
+PKG_CHECK_MODULES(XFONT, [xproto xtrans fontsproto >= 2.1.3 fontenc])
 
 # Transport selection macro from xtrans.m4
 XTRANS_CONNECTION_FLAGS
diff --git a/doc/.gitignore b/doc/.gitignore
deleted file mode 100644 (file)
index 6fa5c31..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-*.html
-*.ps
-*.pdf
-*.txt
diff --git a/include/X11/fonts/.gitignore b/include/X11/fonts/.gitignore
deleted file mode 100644 (file)
index b571690..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-#              Add & Override for this directory and it's subdirectories
-fontconf.h
index a32df63..24be79a 100644 (file)
@@ -72,12 +72,12 @@ typedef struct _FontRenderer            *FontRendererPtr;
 #define FontAliasFile      "fonts.alias"
 #define FontScalableFile    "fonts.scale"
 
-extern int FontFileNameCheck ( char *name );
+extern int FontFileNameCheck ( const char *name );
 extern int FontFileInitFPE ( FontPathElementPtr fpe );
 extern int FontFileResetFPE ( FontPathElementPtr fpe );
 extern int FontFileFreeFPE ( FontPathElementPtr fpe );
 extern int FontFileOpenFont ( pointer client, FontPathElementPtr fpe,
-                             Mask flags, char *name, int namelen,
+                             Mask flags, const char *name, int namelen,
                              fsBitmapFormat format, fsBitmapFormatMask fmask,
                              XID id, FontPtr *pFont, char **aliasName,
                              FontPtr non_cachable_font );
@@ -87,14 +87,14 @@ extern int FontFileOpenBitmap ( FontPathElementPtr fpe, FontPtr *pFont,
                                fsBitmapFormat format,
                                fsBitmapFormatMask fmask );
 extern int FontFileListFonts ( pointer client, FontPathElementPtr fpe,
-                              char *pat, int len, int max,
+                              const char *pat, int len, int max,
                               FontNamesPtr names );
 extern int FontFileStartListFonts ( pointer client, FontPathElementPtr fpe,
-                                   char *pat, int len, int max,
+                                   const char *pat, int len, int max,
                                    pointer *privatep, int mark_aliases );
 extern int FontFileStartListFontsWithInfo ( pointer client,
                                            FontPathElementPtr fpe,
-                                           char *pat, int len, int max,
+                                           const char *pat, int len, int max,
                                            pointer *privatep );
 extern int FontFileListNextFontWithInfo ( pointer client,
                                          FontPathElementPtr fpe,
@@ -103,7 +103,7 @@ extern int FontFileListNextFontWithInfo ( pointer client,
                                          int *numFonts, pointer private );
 extern int FontFileStartListFontsAndAliases ( pointer client,
                                              FontPathElementPtr fpe,
-                                             char *pat, int len, int max,
+                                             const char *pat, int len, int max,
                                              pointer *privatep );
 extern int FontFileListNextFontOrAlias ( pointer client,
                                         FontPathElementPtr fpe,
@@ -173,7 +173,7 @@ extern int FontFileMatchBitmapSource ( FontPathElementPtr fpe,
                                       fsBitmapFormatMask fmask,
                                       Bool noSpecificSize );
 
-extern int FontFileReadDirectory ( char *directory, FontDirectoryPtr *pdir );
+extern int FontFileReadDirectory ( const char *directory, FontDirectoryPtr *pdir );
 extern Bool FontFileDirectoryChanged ( FontDirectoryPtr dir );
 
 #endif /* _FONTFILE_H_ */
index 73a8247..d3926a7 100644 (file)
@@ -91,7 +91,7 @@ RepadBitmap (
 
 extern void CopyISOLatin1Lowered(
     char * /*dest*/,
-    char * /*source*/,
+    const char * /*source*/,
     int /*length*/
 );
 
index 44e5e02..a4969d1 100644 (file)
@@ -1069,6 +1069,8 @@ FT_Do_SBit_Metrics( FT_Face ft_face, FT_Size ft_size, FT_ULong strike_index,
 #endif
 }
 
+#pragma GCC diagnostic ignored "-Wbad-function-cast"
+
 int
 FreeTypeRasteriseGlyph(unsigned idx, int flags, CharInfoPtr tgp,
                       FTInstancePtr instance, int hasMetrics)
@@ -1865,7 +1867,7 @@ FreeTypeAddProperties(FTFontPtr font, FontScalablePtr vals, FontInfoPtr info,
     i++;
 
     info->props[i].name  = MakeAtom("RASTERIZER_NAME", 15, TRUE);
-    info->props[i].value = MakeAtom("FreeType", 10, TRUE);
+    info->props[i].value = MakeAtom("FreeType", 8, TRUE);
     info->isStringProp[i] = 1;
     i++;
 
index 104dc89..cee752e 100644 (file)
@@ -621,7 +621,6 @@ SPropRecValList_add_by_font_cap(SDynPropRecValList *pThisList,
                     int len = term-p-1;
                     char *value;
 
-                    len = term-p-1;
                     value=malloc(len+1);
                     memcpy(value, p+1, len);
                     value[len]='\0';
index cd09ab9..33fd135 100644 (file)
@@ -65,4 +65,4 @@ libXfont_la_LIBADD = \
 
 libXfont_la_SOURCES = dummy.c
 
-libXfont_la_LDFLAGS = -version-number 1:4:1
+libXfont_la_LDFLAGS = -version-number 1:4:1 -no-undefined
index 99682d9..0f2d10a 100644 (file)
@@ -6,14 +6,24 @@ AM_CFLAGS = $(XFONT_CFLAGS) $(OS_CFLAGS) $(CWARNFLAGS)
 noinst_LTLIBRARIES = libbitmap.la
 
 libbitmap_la_SOURCES =                 \
-       bdfread.c               \
-       bdfutils.c              \
        bitmap.c                \
        bitmapfunc.c            \
        bitmaputil.c            \
        bitscale.c              \
-       fontink.c               \
-       pcfread.c               \
-       pcfwrite.c              \
-       snfread.c               \
-       snfstr.h
+       fontink.c
+
+if XFONT_BDFFORMAT
+libbitmap_la_SOURCES += bdfread.c bdfutils.c
+endif
+
+if XFONT_PCF_OR_BUILTIN
+libbitmap_la_SOURCES += pcfread.c
+endif
+
+if XFONT_PCFFORMAT
+libbitmap_la_SOURCES += pcfwrite.c
+endif
+
+if XFONT_SNFFORMAT
+libbitmap_la_SOURCES += snfread.c snfstr.h
+endif
index 9b20faf..0a379eb 100644 (file)
@@ -63,8 +63,12 @@ bitmapGetGlyphs(FontPtr pFont, unsigned long count, unsigned char *chars,
 
     case Linear8Bit:
     case TwoD8Bit:
-       if (pFont->info.firstRow > 0)
+       if (pFont->info.firstRow > 0) {
+            if (pDefault)
+                while (count--)
+                    *glyphs++ = pDefault;
            break;
+        }
        if (pFont->info.allExist && pDefault) {
            while (count--) {
                c = (*chars++) - firstCol;
index 603d5d9..8c6b3d8 100644 (file)
@@ -32,29 +32,20 @@ in this Software without prior written authorization from The Open Group.
 #include <config.h>
 #endif
 
-/*
- * Translate monolithic #defines to modular definitions
- */
-
-#ifdef PCFFORMAT
-#define XFONT_PCFFORMAT 1
-#endif
-
-#ifdef SNFFORMAT
-#define XFONT_SNFFORMAT 1
-#endif
-
-#ifdef BDFFORMAT
-#define XFONT_BDFFORMAT 1
-#endif
-
 #include <X11/fonts/fntfilst.h>
 #include <X11/fonts/bitmap.h>
 #include <X11/fonts/fontutil.h>
+#if XFONT_BDFFORMAT
 #include <X11/fonts/bdfint.h>
+#endif
+#if XFONT_PCFFORMAT
 #include <X11/fonts/pcf.h>
+#endif
+#if XFONT_SNFFORMAT
 #include "snfstr.h"
+#endif
 
+#if XFONT_PCFFORMAT || XFONT_SNFFORMAT || XFONT_BDFFORMAT
 typedef struct _BitmapFileFunctions {
     int         (*ReadFont) (FontPtr /* pFont */, FontFilePtr /* file */,
                             int /* bit */, int /* byte */,
@@ -252,3 +243,11 @@ BitmapGetRenderIndex(FontRendererPtr renderer)
 {
     return renderer - renderers;
 }
+
+#else
+void
+BitmapRegisterFontFileFunctions (void)
+{
+    /* nothing to do */
+}
+#endif /* XFONT_PCFFORMAT || XFONT_SNFFORMAT || XFONT_BDFFORMAT */
index e89ba7c..c9af4c0 100644 (file)
@@ -34,22 +34,6 @@ from The Open Group.
 #include <config.h>
 #endif
 
-/*
- * Translate monolithic #defines to modular definitions
- */
-
-#ifdef PCFFORMAT
-#define XFONT_PCFFORMAT 1
-#endif
-
-#ifdef SNFFORMAT
-#define XFONT_SNFFORMAT 1
-#endif
-
-#ifdef BDFFORMAT
-#define XFONT_BDFFORMAT 1
-#endif
-
 #include <X11/fonts/fntfilst.h>
 #include <X11/fonts/bitmap.h>
 #include <X11/fonts/fontutil.h>
@@ -60,7 +44,7 @@ from The Open Group.
 #endif
 
 /* Should get this from elsewhere */
-extern unsigned long serverGeneration;
+extern unsigned long __GetServerGeneration(void);
 
 static void bitmapUnloadScalable (FontPtr pFont);
 static void ScaleBitmap ( FontPtr pFont, CharInfoPtr opci,
@@ -597,9 +581,9 @@ ComputeScaledProperties(FontInfoPtr sourceFontInfo, /* the font to be scaled */
     char       *isStringProp;
     int                nProps;
 
-    if (bitscaleGeneration != serverGeneration) {
+    if (bitscaleGeneration != __GetServerGeneration()) {
        initFontPropTable();
-       bitscaleGeneration = serverGeneration;
+       bitscaleGeneration = __GetServerGeneration();
     }
     nProps = NPROPS + 1 + sizeof(fontPropTable) / sizeof(fontProp) +
                          sizeof(rawFontPropTable) / sizeof(fontProp);
@@ -751,6 +735,8 @@ compute_xform_matrix(FontScalablePtr vals, double dx, double dy,
  *  ScaleFont
  *  returns a pointer to the new scaled font, or NULL (due to AllocError).
  */
+#pragma GCC diagnostic ignored "-Wbad-function-cast"
+
 static FontPtr
 ScaleFont(FontPtr opf,            /* originating font */
          double widthMult,       /* glyphs width scale factor */
@@ -811,8 +797,6 @@ ScaleFont(FontPtr opf,            /* originating font */
        needs to be for the output font */
     if (vals->nranges)
     {
-       int i;
-
        pfi->allExist = 0;
        firstCol = 255;
        lastCol = 0;
index 75dff8d..f9a4cea 100644 (file)
@@ -54,9 +54,9 @@ extern const int              builtin_dir_count;
 extern const BuiltinAliasRec   builtin_alias[];
 extern const int               builtin_alias_count;
 
-extern FontFilePtr     BuiltinFileOpen (char *);
+extern FontFilePtr     BuiltinFileOpen (const char *);
 extern int             BuiltinFileClose (BufFilePtr, int);
-extern int BuiltinReadDirectory (char *, FontDirectoryPtr *);
+extern int BuiltinReadDirectory (const char *, FontDirectoryPtr *);
 extern void BuiltinRegisterFontFileFunctions (void);
 
 extern void BuiltinRegisterFpeFunctions (void);
index 490e7e3..0225bfc 100644 (file)
@@ -148,7 +148,7 @@ BuiltinAliasesRestore (BuiltinAliasPtr a_cur_tab,
 }
 
 int
-BuiltinReadDirectory (char *directory, FontDirectoryPtr *pdir)
+BuiltinReadDirectory (const char *directory, FontDirectoryPtr *pdir)
 {
     FontDirectoryPtr   dir;
     int                        i;
index 3f657d9..93527c1 100644 (file)
@@ -90,7 +90,7 @@ BuiltinClose (BufFilePtr f, int unused)
 
 
 FontFilePtr
-BuiltinFileOpen (char *name)
+BuiltinFileOpen (const char *name)
 {
     int                    i;
     BuiltinIOPtr    io;
index 83905da..4f5d4cf 100644 (file)
@@ -32,7 +32,7 @@ static int  font_file_type;
 static const char builtin_fonts[] = "built-ins";
 
 static int
-BuiltinNameCheck (char *name)
+BuiltinNameCheck (const char *name)
 {
     return (strcmp (name, builtin_fonts) == 0);
 }
@@ -54,9 +54,6 @@ BuiltinInitFPE (FontPathElementPtr fpe)
 static int
 BuiltinResetFPE (FontPathElementPtr fpe)
 {
-    FontDirectoryPtr   dir;
-
-    dir = (FontDirectoryPtr) fpe->private;
     /* builtins can't change! */
     return Successful;
 }
index faf2e5d..18b0c0d 100644 (file)
@@ -118,6 +118,10 @@ _fs_convert_props(fsPropInfo *pi, fsPropOffset *po, pointer pd,
     for (i = 0; i < nprops; i++, dprop++, is_str++)
     {
        memcpy(&local_off, off_adr, SIZEOF(fsPropOffset));
+       if ((local_off.name.position >= pi->data_len) ||
+               (local_off.name.length >
+                (pi->data_len - local_off.name.position)))
+           goto bail;
        dprop->name = MakeAtom(&pdc[local_off.name.position],
                               local_off.name.length, 1);
        if (local_off.type != PropTypeString) {
@@ -125,10 +129,15 @@ _fs_convert_props(fsPropInfo *pi, fsPropOffset *po, pointer pd,
            dprop->value = local_off.value.position;
        } else {
            *is_str = TRUE;
+           if ((local_off.value.position >= pi->data_len) ||
+               (local_off.value.length >
+                (pi->data_len - local_off.value.position)))
+               goto bail;
            dprop->value = (INT32) MakeAtom(&pdc[local_off.value.position],
                                            local_off.value.length, 1);
            if (dprop->value == BAD_RESOURCE)
            {
+             bail:
                free (pfi->props);
                pfi->nprops = 0;
                pfi->props = 0;
@@ -634,7 +643,7 @@ _fs_unload_font(FontPtr pfont)
 
 FontPtr
 fs_create_font (FontPathElementPtr  fpe,
-               char                *name,
+               const char          *name,
                int                 namelen,
                fsBitmapFormat      format,
                fsBitmapFormatMask  fmask)
@@ -712,7 +721,12 @@ fs_alloc_glyphs (FontPtr pFont, int size)
     FSGlyphPtr glyphs;
     FSFontPtr  fsfont = (FSFontPtr) pFont->fontPrivate;
 
-    glyphs = malloc (sizeof (FSGlyphRec) + size);
+    if (size < (INT_MAX - sizeof (FSGlyphRec)))
+       glyphs = malloc (sizeof (FSGlyphRec) + size);
+    else
+       glyphs = NULL;
+    if (glyphs == NULL)
+       return NULL;
     glyphs->next = fsfont->glyphs;
     fsfont->glyphs = glyphs;
     return (pointer) (glyphs + 1);
index a445144..92b0d53 100644 (file)
@@ -70,6 +70,7 @@ in this Software without prior written authorization from The Open Group.
 #include       "fservestr.h"
 #include       <X11/fonts/fontutil.h>
 #include       <errno.h>
+#include       <limits.h>
 
 #include       <time.h>
 #define Time_t time_t
@@ -91,6 +92,15 @@ in this Software without prior written authorization from The Open Group.
                             (pci)->descent || \
                             (pci)->characterWidth)
 
+/*
+ * SIZEOF(r) is in bytes, length fields in the protocol are in 32-bit words,
+ * so this converts for doing size comparisons.
+ */
+#define LENGTHOF(r)    (SIZEOF(r) >> 2)
+
+/* Somewhat arbitrary limit on maximum reply size we'll try to read. */
+#define MAX_REPLY_LENGTH       ((64 * 1024 * 1024) >> 2)
+
 extern void ErrorF(const char *f, ...);
 
 static int fs_read_glyphs ( FontPathElementPtr fpe, FSBlockDataPtr blockrec );
@@ -137,7 +147,7 @@ static void
 _fs_close_server (FSFpePtr conn);
 
 static FSFpePtr
-_fs_init_conn (char *servername);
+_fs_init_conn (const char *servername);
 
 static int
 _fs_wait_connect (FSFpePtr conn);
@@ -206,13 +216,26 @@ _fs_add_rep_log (FSFpePtr conn, fsGenericReply *rep)
                 rep->sequenceNumber,
                 conn->reqbuffer[i].opcode);
 }
+
+#define _fs_reply_failed(rep, name, op) do {                            \
+    if (rep) {                                                          \
+        if (rep->type == FS_Error)                                      \
+            fprintf (stderr, "Error: %d Request: %s\n",                 \
+                     ((fsError *)rep)->request, #name);                 \
+        else                                                            \
+            fprintf (stderr, "Bad Length for %s Reply: %d %s %d\n",     \
+                     #name, rep->length, op, LENGTHOF(name));           \
+    }                                                                   \
+} while (0)
+
 #else
 #define _fs_add_req_log(conn,op)    ((conn)->current_seq++)
 #define _fs_add_rep_log(conn,rep)
+#define _fs_reply_failed(rep,name,op)
 #endif
 
 static Bool
-fs_name_check(char *name)
+fs_name_check(const char *name)
 {
     /* Just make sure there is a protocol/ prefix */
     return (name && *name != '/' && strchr(name, '/'));
@@ -270,7 +293,7 @@ static int
 fs_init_fpe(FontPathElementPtr fpe)
 {
     FSFpePtr    conn;
-    char       *name;
+    const char  *name;
     int         err;
     int                ret;
 
@@ -600,6 +623,21 @@ fs_get_reply (FSFpePtr conn, int *error)
 
     rep = (fsGenericReply *) buf;
 
+    /*
+     * Refuse to accept replies longer than a maximum reasonable length,
+     * before we pass to _fs_start_read, since it will try to resize the
+     * incoming connection buffer to this size.  Also avoids integer overflow
+     * on 32-bit systems.
+     */
+    if (rep->length > MAX_REPLY_LENGTH)
+    {
+       ErrorF("fserve: reply length %d > MAX_REPLY_LENGTH, disconnecting"
+              " from font server\n", rep->length);
+       _fs_connection_died (conn);
+       *error = FSIO_ERROR;
+       return 0;
+    }
+
     ret = _fs_start_read (conn, rep->length << 2, &buf);
     if (ret != FSIO_READY)
     {
@@ -682,13 +720,15 @@ fs_read_open_font(FontPathElementPtr fpe, FSBlockDataPtr blockrec)
     int                            ret;
 
     rep = (fsOpenBitmapFontReply *) fs_get_reply (conn, &ret);
-    if (!rep || rep->type == FS_Error)
+    if (!rep || rep->type == FS_Error ||
+       (rep->length != LENGTHOF(fsOpenBitmapFontReply)))
     {
        if (ret == FSIO_BLOCK)
            return StillWorking;
        if (rep)
            _fs_done_read (conn, rep->length << 2);
        fs_cleanup_bfont (bfont);
+       _fs_reply_failed (rep, fsOpenBitmapFontReply, "!=");
        return BadFontName;
     }
 
@@ -815,6 +855,7 @@ fs_read_query_info(FontPathElementPtr fpe, FSBlockDataPtr blockrec)
     FSFpePtr           conn = (FSFpePtr) fpe->private;
     fsQueryXInfoReply  *rep;
     char               *buf;
+    long               bufleft; /* length of reply left to use */
     fsPropInfo         *pi;
     fsPropOffset       *po;
     pointer            pd;
@@ -824,13 +865,15 @@ fs_read_query_info(FontPathElementPtr fpe, FSBlockDataPtr blockrec)
     int                        ret;
 
     rep = (fsQueryXInfoReply *) fs_get_reply (conn, &ret);
-    if (!rep || rep->type == FS_Error)
+    if (!rep || rep->type == FS_Error ||
+       (rep->length < LENGTHOF(fsQueryXInfoReply)))
     {
        if (ret == FSIO_BLOCK)
            return StillWorking;
        if (rep)
            _fs_done_read (conn, rep->length << 2);
        fs_cleanup_bfont (bfont);
+       _fs_reply_failed (rep, fsQueryXInfoReply, "<");
        return BadFontName;
     }
 
@@ -844,6 +887,9 @@ fs_read_query_info(FontPathElementPtr fpe, FSBlockDataPtr blockrec)
     buf = (char *) rep;
     buf += SIZEOF(fsQueryXInfoReply);
 
+    bufleft = rep->length << 2;
+    bufleft -= SIZEOF(fsQueryXInfoReply);
+
     /* move the data over */
     fsUnpack_XFontInfoHeader(rep, pInfo);
 
@@ -851,17 +897,50 @@ fs_read_query_info(FontPathElementPtr fpe, FSBlockDataPtr blockrec)
     _fs_init_fontinfo(conn, pInfo);
 
     /* Compute offsets into the reply */
+    if (bufleft < SIZEOF(fsPropInfo))
+    {
+       ret = -1;
+#ifdef DEBUG
+       fprintf(stderr, "fsQueryXInfo: bufleft (%ld) < SIZEOF(fsPropInfo)\n",
+               bufleft);
+#endif
+       goto bail;
+    }
     pi = (fsPropInfo *) buf;
     buf += SIZEOF (fsPropInfo);
+    bufleft -= SIZEOF(fsPropInfo);
 
+    if ((bufleft / SIZEOF(fsPropOffset)) < pi->num_offsets)
+    {
+       ret = -1;
+#ifdef DEBUG
+       fprintf(stderr,
+               "fsQueryXInfo: bufleft (%ld) / SIZEOF(fsPropOffset) < %d\n",
+               bufleft, pi->num_offsets);
+#endif
+       goto bail;
+    }
     po = (fsPropOffset *) buf;
     buf += pi->num_offsets * SIZEOF(fsPropOffset);
+    bufleft -= pi->num_offsets * SIZEOF(fsPropOffset);
 
+    if (bufleft < pi->data_len)
+    {
+       ret = -1;
+#ifdef DEBUG
+       fprintf(stderr,
+               "fsQueryXInfo: bufleft (%ld) < data_len (%d)\n",
+               bufleft, pi->data_len);
+#endif
+       goto bail;
+    }
     pd = (pointer) buf;
     buf += pi->data_len;
+    bufleft -= pi->data_len;
 
     /* convert the properties and step over the reply */
     ret = _fs_convert_props(pi, po, pd, pInfo);
+  bail:
     _fs_done_read (conn, rep->length << 2);
 
     if (ret == -1)
@@ -951,13 +1030,15 @@ fs_read_extent_info(FontPathElementPtr fpe, FSBlockDataPtr blockrec)
     FontInfoRec                    *fi = &bfont->pfont->info;
 
     rep = (fsQueryXExtents16Reply *) fs_get_reply (conn, &ret);
-    if (!rep || rep->type == FS_Error)
+    if (!rep || rep->type == FS_Error ||
+       (rep->length < LENGTHOF(fsQueryXExtents16Reply)))
     {
        if (ret == FSIO_BLOCK)
            return StillWorking;
        if (rep)
            _fs_done_read (conn, rep->length << 2);
        fs_cleanup_bfont (bfont);
+       _fs_reply_failed (rep, fsQueryXExtents16Reply, "<");
        return BadFontName;
     }
 
@@ -970,7 +1051,26 @@ fs_read_extent_info(FontPathElementPtr fpe, FSBlockDataPtr blockrec)
        numInfos *= 2;
        haveInk = TRUE;
     }
-    ci = pCI = malloc(sizeof(CharInfoRec) * numInfos);
+    if (numInfos >= (INT_MAX / sizeof(CharInfoRec))) {
+#ifdef DEBUG
+       fprintf(stderr,
+               "fsQueryXExtents16: numInfos (%d) >= %ld\n",
+               numInfos, (INT_MAX / sizeof(CharInfoRec)));
+#endif
+       pCI = NULL;
+    }
+    else if (numExtents > ((rep->length - LENGTHOF(fsQueryXExtents16Reply))
+                           / LENGTHOF(fsXCharInfo))) {
+#ifdef DEBUG
+       fprintf(stderr,
+               "fsQueryXExtents16: numExtents (%d) > (%d - %d) / %d\n",
+               numExtents, rep->length,
+               LENGTHOF(fsQueryXExtents16Reply), LENGTHOF(fsXCharInfo));
+#endif
+       pCI = NULL;
+    }
+    else
+       pCI = malloc(sizeof(CharInfoRec) * numInfos);
 
     if (!pCI)
     {
@@ -1111,7 +1211,7 @@ fs_read_extent_info(FontPathElementPtr fpe, FSBlockDataPtr blockrec)
 }
 
 #ifdef DEBUG
-static char *fs_open_states[] = {
+static const char *fs_open_states[] = {
     "OPEN_REPLY  ",
     "INFO_REPLY  ",
     "EXTENT_REPLY",
@@ -1381,7 +1481,6 @@ fs_wakeup(FontPathElementPtr fpe, unsigned long *mask)
     {
        FSBlockDataPtr      blockrec;
        FSBlockedFontPtr    bfont;
-       FSBlockedListPtr    blist;
        static CARD32       lastState;
        static FSBlockDataPtr   lastBlock;
 
@@ -1405,7 +1504,6 @@ fs_wakeup(FontPathElementPtr fpe, unsigned long *mask)
                         "<freed>");
                break;
            case FS_LIST_FONTS:
-               blist = (FSBlockedListPtr) blockrec->data;
                fprintf (stderr, "  Blocked list errcode %d sequence %d\n",
                         blockrec->errcode, blockrec->sequenceNumber);
                break;
@@ -1517,7 +1615,7 @@ _fs_do_blocked (FSFpePtr conn)
 /* ARGSUSED */
 static int
 fs_send_open_font(pointer client, FontPathElementPtr fpe, Mask flags,
-                 char *name, int namelen,
+                 const char *name, int namelen,
                  fsBitmapFormat format, fsBitmapFormatMask fmask,
                  XID id, FontPtr *ppfont)
 {
@@ -1535,7 +1633,7 @@ fs_send_open_font(pointer client, FontPathElementPtr fpe, Mask flags,
     if (conn->blockState & FS_GIVE_UP)
        return BadFontName;
 
-    if (namelen <= 0 || namelen > sizeof (buf) - 1)
+    if (namelen < 0 || namelen > sizeof (buf) - 1)
        return BadFontName;
 
     /*
@@ -1709,7 +1807,7 @@ fs_send_query_bitmaps(FontPathElementPtr fpe, FSBlockDataPtr blockrec)
 /* ARGSUSED */
 static int
 fs_open_font(pointer client, FontPathElementPtr fpe, Mask flags,
-            char *name, int namelen,
+            const char *name, int namelen,
             fsBitmapFormat format, fsBitmapFormatMask fmask,
             XID id, FontPtr *ppfont,
             char **alias, FontPtr non_cachable_font)
@@ -1809,6 +1907,7 @@ fs_read_glyphs(FontPathElementPtr fpe, FSBlockDataPtr blockrec)
     FontInfoPtr                    pfi = &pfont->info;
     fsQueryXBitmaps16Reply  *rep;
     char                   *buf;
+    long                   bufleft; /* length of reply left to use */
     fsOffset32             *ppbits;
     fsOffset32             local_off;
     char                   *off_adr;
@@ -1825,22 +1924,48 @@ fs_read_glyphs(FontPathElementPtr fpe, FSBlockDataPtr blockrec)
     unsigned long          minchar, maxchar;
 
     rep = (fsQueryXBitmaps16Reply *) fs_get_reply (conn, &ret);
-    if (!rep || rep->type == FS_Error)
+    if (!rep || rep->type == FS_Error ||
+       (rep->length < LENGTHOF(fsQueryXBitmaps16Reply)))
     {
        if (ret == FSIO_BLOCK)
            return StillWorking;
        if (rep)
            _fs_done_read (conn, rep->length << 2);
        err = AllocError;
+       _fs_reply_failed (rep, fsQueryXBitmaps16Reply, "<");
        goto bail;
     }
 
     buf = (char *) rep;
     buf += SIZEOF (fsQueryXBitmaps16Reply);
 
+    bufleft = rep->length << 2;
+    bufleft -= SIZEOF (fsQueryXBitmaps16Reply);
+
+    if ((bufleft / SIZEOF (fsOffset32)) < rep->num_chars)
+    {
+#ifdef DEBUG
+       fprintf(stderr,
+               "fsQueryXBitmaps16: num_chars (%d) > bufleft (%ld) / %d\n",
+               rep->num_chars, bufleft, SIZEOF (fsOffset32));
+#endif
+       err = AllocError;
+       goto bail;
+    }
     ppbits = (fsOffset32 *) buf;
     buf += SIZEOF (fsOffset32) * (rep->num_chars);
+    bufleft -= SIZEOF (fsOffset32) * (rep->num_chars);
 
+    if (bufleft < rep->nbytes)
+    {
+#ifdef DEBUG
+       fprintf(stderr,
+               "fsQueryXBitmaps16: nbytes (%d) > bufleft (%ld)\n",
+               rep->nbytes, bufleft);
+#endif
+       err = AllocError;
+       goto bail;
+    }
     pbitmaps = (pointer ) buf;
 
     if (blockrec->type == FS_LOAD_GLYPHS)
@@ -1898,7 +2023,9 @@ fs_read_glyphs(FontPathElementPtr fpe, FSBlockDataPtr blockrec)
             */
            if (NONZEROMETRICS(&fsdata->encoding[minchar].metrics))
            {
-               if (local_off.length)
+               if (local_off.length &&
+                   (local_off.position < rep->nbytes) &&
+                   (local_off.length <= (rep->nbytes - local_off.position)))
                {
                    bits = allbits;
                    allbits += local_off.length;
@@ -2034,7 +2161,7 @@ fs_send_load_glyphs(pointer client, FontPtr pfont,
 }
 
 
-extern pointer serverClient;   /* This could be any number that
+extern pointer __GetServerClient(void);        /* This could be any number that
                                   doesn't conflict with existing
                                   client values. */
 
@@ -2206,17 +2333,17 @@ fs_load_all_glyphs(FontPtr pfont)
      * perform an unpleasant job that, we hope, will never be required.
      */
 
-    while ((err = _fs_load_glyphs(serverClient, pfont, TRUE, 0, 0, NULL)) ==
+    while ((err = _fs_load_glyphs(__GetServerClient(), pfont, TRUE, 0, 0, NULL)) ==
           Suspended)
     {
        if (fs_await_reply (conn) != FSIO_READY)
        {
            /* Get rid of blockrec */
-           fs_client_died(serverClient, pfont->fpe);
+           fs_client_died(__GetServerClient(), pfont->fpe);
            err = BadCharRange;
            break;
        }
-       fs_read_reply (pfont->fpe, serverClient);
+       fs_read_reply (pfont->fpe, __GetServerClient());
     }
     return err;
 }
@@ -2228,38 +2355,55 @@ fs_read_list(FontPathElementPtr fpe, FSBlockDataPtr blockrec)
     FSBlockedListPtr   blist = (FSBlockedListPtr) blockrec->data;
     fsListFontsReply   *rep;
     char               *data;
+    long               dataleft; /* length of reply left to use */
     int                        length,
                        i,
                        ret;
     int                        err;
 
     rep = (fsListFontsReply *) fs_get_reply (conn, &ret);
-    if (!rep || rep->type == FS_Error)
+    if (!rep || rep->type == FS_Error ||
+       (rep->length < LENGTHOF(fsListFontsReply)))
     {
        if (ret == FSIO_BLOCK)
            return StillWorking;
        if (rep)
            _fs_done_read (conn, rep->length << 2);
+       _fs_reply_failed (rep, fsListFontsReply, "<");
        return AllocError;
     }
     data = (char *) rep + SIZEOF (fsListFontsReply);
+    dataleft = (rep->length << 2) - SIZEOF (fsListFontsReply);
 
     err = Successful;
     /* copy data into FontPathRecord */
     for (i = 0; i < rep->nFonts; i++)
     {
+       if (dataleft < 1)
+           break;
        length = *(unsigned char *)data++;
+       dataleft--; /* used length byte */
+       if (length > dataleft) {
+#ifdef DEBUG
+           fprintf(stderr,
+                   "fsListFonts: name length (%d) > dataleft (%ld)\n",
+                   length, dataleft);
+#endif
+           err = BadFontName;
+           break;
+       }
        err = AddFontNamesName(blist->names, data, length);
        if (err != Successful)
            break;
        data += length;
+       dataleft -= length;
     }
     _fs_done_read (conn, rep->length << 2);
     return err;
 }
 
 static int
-fs_send_list_fonts(pointer client, FontPathElementPtr fpe, char *pattern,
+fs_send_list_fonts(pointer client, FontPathElementPtr fpe, const char *pattern,
                   int patlen, int maxnames, FontNamesPtr newnames)
 {
     FSFpePtr           conn = (FSFpePtr) fpe->private;
@@ -2315,7 +2459,7 @@ fs_send_list_fonts(pointer client, FontPathElementPtr fpe, char *pattern,
 
 static int
 fs_list_fonts(pointer client, FontPathElementPtr fpe,
-             char *pattern, int patlen, int maxnames, FontNamesPtr newnames)
+             const char *pattern, int patlen, int maxnames, FontNamesPtr newnames)
 {
     FSFpePtr           conn = (FSFpePtr) fpe->private;
     FSBlockDataPtr     blockrec;
@@ -2347,6 +2491,7 @@ fs_read_list_info(FontPathElementPtr fpe, FSBlockDataPtr blockrec)
     FSBlockedListInfoPtr       binfo = (FSBlockedListInfoPtr) blockrec->data;
     fsListFontsWithXInfoReply  *rep;
     char                       *buf;
+    long                       bufleft;
     FSFpePtr                   conn = (FSFpePtr) fpe->private;
     fsPropInfo                 *pi;
     fsPropOffset               *po;
@@ -2358,12 +2503,15 @@ fs_read_list_info(FontPathElementPtr fpe, FSBlockDataPtr blockrec)
     _fs_free_props (&binfo->info);
 
     rep = (fsListFontsWithXInfoReply *) fs_get_reply (conn, &ret);
-    if (!rep || rep->type == FS_Error)
+    if (!rep || rep->type == FS_Error ||
+       ((rep->nameLength != 0) &&
+        (rep->length < LENGTHOF(fsListFontsWithXInfoReply))))
     {
        if (ret == FSIO_BLOCK)
            return StillWorking;
        binfo->status = FS_LFWI_FINISHED;
        err = AllocError;
+       _fs_reply_failed (rep, fsListFontsWithXInfoReply, "<");
        goto done;
     }
     /*
@@ -2380,6 +2528,7 @@ fs_read_list_info(FontPathElementPtr fpe, FSBlockDataPtr blockrec)
     }
 
     buf = (char *) rep + SIZEOF (fsListFontsWithXInfoReply);
+    bufleft = (rep->length << 2) - SIZEOF (fsListFontsWithXInfoReply);
 
     /*
      * The original FS implementation didn't match
@@ -2388,19 +2537,71 @@ fs_read_list_info(FontPathElementPtr fpe, FSBlockDataPtr blockrec)
      */
     if (conn->fsMajorVersion <= 1)
     {
+       if (rep->nameLength > bufleft) {
+#ifdef DEBUG
+           fprintf(stderr,
+                   "fsListFontsWithXInfo: name length (%d) > bufleft (%ld)\n",
+                   (int) rep->nameLength, bufleft);
+#endif
+           err = AllocError;
+           goto done;
+       }
+       /* binfo->name is a 256 char array, rep->nameLength is a CARD8 */
        memcpy (binfo->name, buf, rep->nameLength);
        buf += _fs_pad_length (rep->nameLength);
+       bufleft -= _fs_pad_length (rep->nameLength);
     }
     pi = (fsPropInfo *) buf;
+    if (SIZEOF (fsPropInfo) > bufleft) {
+#ifdef DEBUG
+       fprintf(stderr,
+               "fsListFontsWithXInfo: PropInfo length (%d) > bufleft (%ld)\n",
+               (int) SIZEOF (fsPropInfo), bufleft);
+#endif
+       err = AllocError;
+       goto done;
+    }
+    bufleft -= SIZEOF (fsPropInfo);
     buf += SIZEOF (fsPropInfo);
     po = (fsPropOffset *) buf;
+    if (pi->num_offsets > (bufleft / SIZEOF (fsPropOffset))) {
+#ifdef DEBUG
+       fprintf(stderr,
+               "fsListFontsWithXInfo: offset length (%d * %d) > bufleft (%ld)\n",
+               pi->num_offsets, (int) SIZEOF (fsPropOffset), bufleft);
+#endif
+       err = AllocError;
+       goto done;
+    }
+    bufleft -= pi->num_offsets * SIZEOF (fsPropOffset);
     buf += pi->num_offsets * SIZEOF (fsPropOffset);
     pd = (pointer) buf;
+    if (pi->data_len > bufleft) {
+#ifdef DEBUG
+       fprintf(stderr,
+               "fsListFontsWithXInfo: data length (%d) > bufleft (%ld)\n",
+               pi->data_len, bufleft);
+#endif
+       err = AllocError;
+       goto done;
+    }
+    bufleft -= pi->data_len;
     buf += pi->data_len;
     if (conn->fsMajorVersion > 1)
     {
+       if (rep->nameLength > bufleft) {
+#ifdef DEBUG
+           fprintf(stderr,
+                   "fsListFontsWithXInfo: name length (%d) > bufleft (%ld)\n",
+                   (int) rep->nameLength, bufleft);
+#endif
+           err = AllocError;
+           goto done;
+       }
+       /* binfo->name is a 256 char array, rep->nameLength is a CARD8 */
        memcpy (binfo->name, buf, rep->nameLength);
        buf += _fs_pad_length (rep->nameLength);
+       bufleft -= _fs_pad_length (rep->nameLength);
     }
 
 #ifdef DEBUG
@@ -2429,7 +2630,7 @@ done:
 /* ARGSUSED */
 static int
 fs_start_list_with_info(pointer client, FontPathElementPtr fpe,
-                       char *pattern, int len, int maxnames, pointer *pdata)
+                       const char *pattern, int len, int maxnames, pointer *pdata)
 {
     FSFpePtr               conn = (FSFpePtr) fpe->private;
     FSBlockDataPtr         blockrec;
@@ -2786,7 +2987,7 @@ _fs_recv_conn_setup (FSFpePtr conn)
     int                        ret = FSIO_ERROR;
     fsConnSetup                *setup;
     FSFpeAltPtr                alts;
-    int                        i, alt_len;
+    unsigned int       i, alt_len;
     int                        setup_len;
     char               *alt_save, *alt_names;
 
@@ -2813,8 +3014,9 @@ _fs_recv_conn_setup (FSFpePtr conn)
        }
        if (setup->num_alternates)
        {
+           size_t alt_name_len = setup->alternate_len << 2;
            alts = malloc (setup->num_alternates * sizeof (FSFpeAltRec) +
-                          (setup->alternate_len << 2));
+                          alt_name_len);
            if (alts)
            {
                alt_names = (char *) (setup + 1);
@@ -2823,10 +3025,25 @@ _fs_recv_conn_setup (FSFpePtr conn)
                {
                    alts[i].subset = alt_names[0];
                    alt_len = alt_names[1];
+                   if (alt_len >= alt_name_len) {
+                       /*
+                        * Length is longer than setup->alternate_len
+                        * told us to allocate room for, assume entire
+                        * alternate list is corrupted.
+                        */
+#ifdef DEBUG
+                       fprintf (stderr,
+                                "invalid alt list (length %lx >= %lx)\n",
+                                (long) alt_len, (long) alt_name_len);
+#endif
+                       free(alts);
+                       return FSIO_ERROR;
+                   }
                    alts[i].name = alt_save;
                    memcpy (alt_save, alt_names + 2, alt_len);
                    alt_save[alt_len] = '\0';
                    alt_save += alt_len + 1;
+                   alt_name_len -= alt_len + 1;
                    alt_names += _fs_pad_length (alt_len + 2);
                }
                conn->numAlts = setup->num_alternates;
@@ -2964,6 +3181,7 @@ _fs_send_cat_sync (FSFpePtr conn)
      * by a bogus catalogue
      */
     lcreq.reqType = FS_ListCatalogues;
+    lcreq.data = 0;
     lcreq.length = (SIZEOF(fsListCataloguesReq)) >> 2;
     lcreq.maxNames = 0;
     lcreq.nbytes = 0;
@@ -3144,7 +3362,7 @@ _fs_start_reconnect (FSFpePtr conn)
 
 
 static FSFpePtr
-_fs_init_conn (char *servername)
+_fs_init_conn (const char *servername)
 {
     FSFpePtr   conn;
 
index 5999861..502e201 100644 (file)
@@ -72,7 +72,7 @@ typedef struct _fs_blocked_extents *FSBlockedExtentPtr;
 extern void _fs_convert_char_info ( fsXCharInfo *src, xCharInfo *dst );
 extern void _fs_free_props (FontInfoPtr pfi);
 extern FontPtr fs_create_font (FontPathElementPtr   fpe,
-                              char                 *name,
+                              const char           *name,
                               int                  namelen,
                               fsBitmapFormat       format,
                               fsBitmapFormatMask   fmask);
index 2bb8e0b..fa1e7d8 100644 (file)
@@ -26,8 +26,9 @@
 #ifndef        _FSIO_H_
 #define        _FSIO_H_
 
-#undef DEBUG
+#ifdef DEBUG
 #define        REQUEST_LOG_SIZE        100
+#endif
 
 typedef struct _fs_fpe_alternate {
     char       *name;
index 34b7f36..d8d4f29 100644 (file)
@@ -162,8 +162,10 @@ BufFileOpenWrite (int fd)
     setmode(fd,O_BINARY);
 #endif
     f = BufFileCreate ((char *)(long) fd, 0, BufFileRawFlush, 0, BufFileFlush);
-    f->bufp = f->buffer;
-    f->left = BUFFILESIZE;
+    if (f != NULL) {
+       f->bufp = f->buffer;
+       f->left = BUFFILESIZE;
+    }
     return f;
 }
 
index 09ca2ae..81a1e13 100644 (file)
@@ -40,7 +40,7 @@ static const char CataloguePrefix[] = "catalogue:";
 static int CatalogueFreeFPE (FontPathElementPtr fpe);
 
 static int
-CatalogueNameCheck (char *name)
+CatalogueNameCheck (const char *name)
 {
     return strncmp(name, CataloguePrefix, sizeof(CataloguePrefix) - 1) == 0;
 }
@@ -116,7 +116,7 @@ CatalogueUnrefFPEs (FontPathElementPtr fpe)
        if (subfpe->refcount == 0)
        {
            FontFileFreeFPE (subfpe);
-           free(subfpe->name);
+           free((void *) subfpe->name);
            free(subfpe);
        }
     }
@@ -158,6 +158,7 @@ CatalogueRescan (FontPathElementPtr fpe, Bool forceScan)
     CatalogueUnrefFPEs (fpe);
     while (entry = readdir(dir), entry != NULL)
     {
+        char *name;
        snprintf(link, sizeof link, "%s/%s", path, entry->d_name);
        len = readlink(link, dest, sizeof dest - 1);
        if (len < 0)
@@ -191,15 +192,16 @@ CatalogueRescan (FontPathElementPtr fpe, Bool forceScan)
         * (which uses font->fpe->type) goes to CatalogueCloseFont. */
        subfpe->type = fpe->type;
        subfpe->name_length = len;
-       subfpe->name = malloc (len + 1);
-       if (subfpe->name == NULL)
+       name = malloc (len + 1);
+       if (name == NULL)
        {
            free(subfpe);
            continue;
        }
 
-       memcpy(subfpe->name, dest, len);
-       subfpe->name[len] = '\0';
+       memcpy(name, dest, len);
+       name[len] = '\0';
+        subfpe->name = name;
 
        /* The X server will manipulate the subfpe ref counts
         * associated with the font in OpenFont and CloseFont, so we
@@ -208,7 +210,7 @@ CatalogueRescan (FontPathElementPtr fpe, Bool forceScan)
 
        if (FontFileInitFPE (subfpe) != Successful)
        {
-           free(subfpe->name);
+           free((void *) subfpe->name);
            free(subfpe);
            continue;
        }
@@ -280,14 +282,13 @@ CatalogueFreeFPE (FontPathElementPtr fpe)
 
 static int
 CatalogueOpenFont (pointer client, FontPathElementPtr fpe, Mask flags,
-                  char *name, int namelen,
+                  const char *name, int namelen,
                   fsBitmapFormat format, fsBitmapFormatMask fmask,
                   XID id, FontPtr *pFont, char **aliasName,
                   FontPtr non_cachable_font)
 {
     CataloguePtr cat = fpe->private;
     FontPathElementPtr subfpe;
-    FontDirectoryPtr dir;
     int i, status;
 
     CatalogueRescan (fpe, FALSE);
@@ -295,7 +296,6 @@ CatalogueOpenFont (pointer client, FontPathElementPtr fpe, Mask flags,
     for (i = 0; i < cat->fpeCount; i++)
     {
        subfpe = cat->fpeList[i];
-       dir = subfpe->private;
        status = FontFileOpenFont(client, subfpe, flags,
                                  name, namelen, format, fmask, id,
                                  pFont, aliasName, non_cachable_font);
@@ -316,12 +316,11 @@ CatalogueCloseFont (FontPathElementPtr fpe, FontPtr pFont)
 }
 
 static int
-CatalogueListFonts (pointer client, FontPathElementPtr fpe, char *pat,
+CatalogueListFonts (pointer client, FontPathElementPtr fpe, const char *pat,
                    int len, int max, FontNamesPtr names)
 {
     CataloguePtr cat = fpe->private;
     FontPathElementPtr subfpe;
-    FontDirectoryPtr dir;
     int i;
 
     CatalogueRescan (fpe, FALSE);
@@ -329,18 +328,12 @@ CatalogueListFonts (pointer client, FontPathElementPtr fpe, char *pat,
     for (i = 0; i < cat->fpeCount; i++)
     {
        subfpe = cat->fpeList[i];
-       dir = subfpe->private;
        FontFileListFonts(client, subfpe, pat, len, max, names);
     }
 
     return Successful;
 }
 
-int
-FontFileStartListFonts(pointer client, FontPathElementPtr fpe,
-                      char *pat, int len, int max,
-                      pointer *privatep, int mark_aliases);
-
 typedef struct _LFWIData {
     pointer            *privates;
     int                        current;
@@ -348,7 +341,7 @@ typedef struct _LFWIData {
 
 static int
 CatalogueStartListFonts(pointer client, FontPathElementPtr fpe,
-                       char *pat, int len, int max, pointer *privatep,
+                       const char *pat, int len, int max, pointer *privatep,
                        int mark_aliases)
 {
     CataloguePtr       cat = fpe->private;
@@ -384,7 +377,7 @@ CatalogueStartListFonts(pointer client, FontPathElementPtr fpe,
 
 static int
 CatalogueStartListFontsWithInfo(pointer client, FontPathElementPtr fpe,
-                               char *pat, int len, int max,
+                               const char *pat, int len, int max,
                                pointer *privatep)
 {
     return CatalogueStartListFonts(client, fpe, pat, len, max, privatep, 0);
@@ -422,7 +415,7 @@ CatalogueListNextFontWithInfo(pointer client, FontPathElementPtr fpe,
 
 static int
 CatalogueStartListFontsAndAliases(pointer client, FontPathElementPtr fpe,
-                                 char *pat, int len, int max,
+                                 const char *pat, int len, int max,
                                  pointer *privatep)
 {
     return CatalogueStartListFonts(client, fpe, pat, len, max, privatep, 1);
index 0d34db9..38ced75 100644 (file)
@@ -42,6 +42,7 @@ in this Software without prior written authorization from The Open Group.
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <errno.h>
+#include <limits.h>
 
 static Bool AddFileNameAliases ( FontDirectoryPtr dir );
 static int ReadFontAlias ( char *directory, Bool isFile,
@@ -49,8 +50,10 @@ static int ReadFontAlias ( char *directory, Bool isFile,
 static int lexAlias ( FILE *file, char **lexToken );
 static int lexc ( FILE *file );
 
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
+
 int
-FontFileReadDirectory (char *directory, FontDirectoryPtr *pdir)
+FontFileReadDirectory (const char *directory, FontDirectoryPtr *pdir)
 {
     char        file_name[MAXFONTFILENAMELEN];
     char        font_name[MAXFONTNAMELEN];
@@ -374,6 +377,9 @@ lexAlias(FILE *file, char **lexToken)
            int         nsize;
            char       *nbuf;
 
+           if (tokenSize >= (INT_MAX >> 2))
+               /* Stop before we overflow */
+               return EALLOC;
            nsize = tokenSize ? (tokenSize << 1) : 64;
            nbuf = realloc(tokenBuf, nsize);
            if (!nbuf)
index ef7ffa5..7271603 100644 (file)
@@ -177,6 +177,11 @@ FontFileAddEntry(FontTablePtr table, FontEntryPtr prototype)
     if (table->sorted)
        return (FontEntryPtr) 0;    /* "cannot" happen */
     if (table->used == table->size) {
+       if (table->size >= ((INT32_MAX / sizeof(FontEntryRec)) - 100))
+           /* If we've read so many entries we're going to ask for 2gb
+              or more of memory, something is so wrong with this font
+              directory that we should just give up before we overflow. */
+           return NULL;
        newsize = table->size + 100;
        entry = realloc(table->entries, newsize * sizeof(FontEntryRec));
        if (!entry)
index c55282b..05a9610 100644 (file)
@@ -50,7 +50,7 @@ ISOLatin1ToLower(unsigned char source)
 }
 
 _X_HIDDEN void
-CopyISOLatin1Lowered(char *dest, char *source, int length)
+CopyISOLatin1Lowered(char *dest, const char *source, int length)
 {
     int i;
     for (i = 0; i < length; i++, source++, dest++)
@@ -69,7 +69,7 @@ static int FontFileOpenBitmapNCF (FontPathElementPtr fpe, FontPtr *pFont,
                                  FontPtr non_cachable_font);
 
 int
-FontFileNameCheck (char *name)
+FontFileNameCheck (const char *name)
 {
 #ifndef NCD
 #if defined(WIN32)
@@ -254,7 +254,7 @@ transfer_values_to_alias(char *entryname, int entrynamelength,
 /* ARGSUSED */
 int
 FontFileOpenFont (pointer client, FontPathElementPtr fpe, Mask flags,
-                 char *name, int namelen,
+                 const char *name, int namelen,
                  fsBitmapFormat format, fsBitmapFormatMask fmask,
                  XID id, FontPtr *pFont, char **aliasName,
                  FontPtr non_cachable_font)
@@ -688,7 +688,7 @@ _FontFileAddScalableNames(FontNamesPtr names, FontNamesPtr scaleNames,
 /* ARGSUSED */
 static int
 _FontFileListFonts (pointer client, FontPathElementPtr fpe,
-                   char *pat, int len, int max, FontNamesPtr names,
+                   const char *pat, int len, int max, FontNamesPtr names,
                    int mark_aliases)
 {
     FontDirectoryPtr   dir;
@@ -794,7 +794,7 @@ typedef struct _LFWIData {
 } LFWIDataRec, *LFWIDataPtr;
 
 int
-FontFileListFonts (pointer client, FontPathElementPtr fpe, char *pat,
+FontFileListFonts (pointer client, FontPathElementPtr fpe, const char *pat,
                   int len, int max, FontNamesPtr names)
 {
     return _FontFileListFonts (client, fpe, pat, len, max, names, 0);
@@ -802,7 +802,7 @@ FontFileListFonts (pointer client, FontPathElementPtr fpe, char *pat,
 
 int
 FontFileStartListFonts(pointer client, FontPathElementPtr fpe,
-                      char *pat, int len, int max,
+                      const char *pat, int len, int max,
                       pointer *privatep, int mark_aliases)
 {
     LFWIDataPtr        data;
@@ -833,7 +833,7 @@ FontFileStartListFonts(pointer client, FontPathElementPtr fpe,
 
 int
 FontFileStartListFontsWithInfo(pointer client, FontPathElementPtr fpe,
-                              char *pat, int len, int max,
+                              const char *pat, int len, int max,
                               pointer *privatep)
 {
     return FontFileStartListFonts(client, fpe, pat, len, max, privatep, 0);
@@ -1067,7 +1067,7 @@ FontFileListNextFontWithInfo(pointer client, FontPathElementPtr fpe,
 
 int
 FontFileStartListFontsAndAliases(pointer client, FontPathElementPtr fpe,
-                                char *pat, int len, int max,
+                                const char *pat, int len, int max,
                                 pointer *privatep)
 {
     return FontFileStartListFonts(client, fpe, pat, len, max, privatep, 1);
index 5091922..bbcd466 100644 (file)
@@ -40,7 +40,7 @@ static FontRenderersRec       renderers;
  * XXX Maybe should allow unregistering renders. For now, just clear the
  * list at each new generation.
  */
-extern unsigned long serverGeneration;
+extern unsigned long __GetServerGeneration(void);
 static unsigned long rendererGeneration = 0;
 
 Bool
@@ -55,8 +55,8 @@ FontFilePriorityRegisterRenderer (FontRendererPtr renderer, int priority)
     int                    i;
     struct _FontRenderersElement *new;
 
-    if (rendererGeneration != serverGeneration) {
-       rendererGeneration = serverGeneration;
+    if (rendererGeneration != __GetServerGeneration()) {
+       rendererGeneration = __GetServerGeneration();
        renderers.number = 0;
        if (renderers.renderers)
           free(renderers.renderers);
index 23e3bd1..7eb16d4 100644 (file)
@@ -10,7 +10,6 @@ libstubs_la_SOURCES =                 \
        csignal.c               \
        delfntcid.c             \
        errorf.c                \
-       fatalerror.c            \
        findoldfnt.c            \
        getcres.c               \
        getdefptsize.c          \
@@ -22,4 +21,5 @@ libstubs_la_SOURCES =                 \
        servclient.c            \
        setfntauth.c            \
        stfntcfnt.c             \
+       stubsinit.c             \
        stubs.h
index 026c52d..10086e4 100644 (file)
@@ -10,5 +10,6 @@
 weak int
 client_auth_generation(ClientPtr client)
 {
+    OVERRIDE_SYMBOL(client_auth_generation, client);
     return 0;
 }
index e6fdeae..dd88b3d 100644 (file)
@@ -10,5 +10,6 @@
 weak Bool
 ClientSignal(ClientPtr client)
 {
+    OVERRIDE_SYMBOL(ClientSignal,client);
     return True;
 }
index ca71328..8113b9f 100644 (file)
@@ -10,4 +10,5 @@
 weak void
 DeleteFontClientID(Font id)
 {
+    OVERRIDE_SYMBOL(DeleteFontClientID, id);
 }
index fd32965..d2de6c6 100644 (file)
@@ -10,4 +10,5 @@
 weak void
 ErrorF(const char *f, ...)
 {
+    OVERRIDE_VA_SYMBOL(VErrorF, f);
 }
diff --git a/src/stubs/fatalerror.c b/src/stubs/fatalerror.c
deleted file mode 100644 (file)
index 1549ad3..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "stubs.h"
-
-#ifdef __SUNPRO_C
-#pragma weak FatalError
-#endif
-
-weak void
-FatalError(const char *f, ...)
-{
-}
index 7a00084..c73279e 100644 (file)
@@ -10,5 +10,6 @@
 weak FontPtr
 find_old_font(FSID id)
 {
+    OVERRIDE_SYMBOL(find_old_font, id);
     return (FontPtr)NULL;
 }
index 0b98f46..27a9180 100644 (file)
@@ -10,5 +10,6 @@
 weak FontResolutionPtr
 GetClientResolutions(int *num)
 {
+  OVERRIDE_SYMBOL(GetClientResolutions, num);
   return (FontResolutionPtr) 0;
 }
index 0b9e409..50c1b18 100644 (file)
@@ -10,5 +10,6 @@
 weak int
 GetDefaultPointSize(void)
 {
+    OVERRIDE_SYMBOL(GetDefaultPointSize);
     return 0;
 }
index e2fe8bb..d31ccf1 100644 (file)
@@ -10,5 +10,6 @@
 weak Font
 GetNewFontClientID(void)
 {
+    OVERRIDE_SYMBOL(GetNewFontClientID);
     return (Font)0;
 }
index 7b2d3b3..1b20f62 100644 (file)
@@ -10,5 +10,6 @@
 weak unsigned long
 GetTimeInMillis (void)
 {
+    OVERRIDE_SYMBOL(GetTimeInMillis);
     return 0;
 }
index a14daff..e1c0b24 100644 (file)
@@ -11,5 +11,6 @@ weak int
 init_fs_handlers(FontPathElementPtr fpe,
                  BlockHandlerProcPtr block_handler)
 {
+  OVERRIDE_SYMBOL(init_fs_handlers, fpe, block_handler);
   return Successful;
 }
index fdf22cd..ae12a01 100644 (file)
@@ -24,5 +24,9 @@ RegisterFPEFunctions(NameCheckFunc name_func,
                     NextLaFunc next_list_alias_func,
                     SetPathFunc set_path_func)
 {
+    OVERRIDE_SYMBOL(RegisterFPEFunctions, name_func, init_func, free_func,
+                    reset_func, open_func, close_func, list_func, start_lfwi_func,
+                    next_lfwi_func, wakeup_func, client_died, load_glyphs,
+                    start_list_alias_func, next_list_alias_func, set_path_func);
     return 0;
 }
index b495661..22a3091 100644 (file)
@@ -12,4 +12,5 @@ remove_fs_handlers(FontPathElementPtr fpe,
                    BlockHandlerProcPtr blockHandler,
                    Bool all)
 {
+    OVERRIDE_SYMBOL(remove_fs_handlers, fpe, blockHandler, all);
 }
index 9b6cebb..f85e08e 100644 (file)
@@ -8,3 +8,12 @@
 #endif
 
 weak void *serverClient = 0;
+
+void *__GetServerClient(void);
+
+void *
+__GetServerClient(void)
+{
+   OVERRIDE_DATA(serverClient);
+   return serverClient;
+}
index 0c7eccc..371807e 100644 (file)
@@ -10,5 +10,6 @@
 weak int
 set_font_authorizations(char **authorizations, int *authlen, ClientPtr client)
 {
+    OVERRIDE_SYMBOL(set_font_authorizations, authorizations, authlen, client);
     return 0;
 }
index 5fc1745..d490988 100644 (file)
@@ -10,5 +10,6 @@
 weak int
 StoreFontClientFont(FontPtr pfont, Font id)
 {
+    OVERRIDE_SYMBOL(StoreFontClientFont, pfont, id);
     return 0;
 }
index fa634e9..7d499d5 100644 (file)
 #endif
 #endif
 
+#if defined(NO_WEAK_SYMBOLS) && defined(PIC)
+#include <stdarg.h>
+extern int _font_init_stubs(void);
+#define OVERRIDE_DATA(sym) \
+    _font_init_stubs(); \
+    if (__ptr_##sym && __ptr_##sym != &sym) \
+      sym = *__ptr_##sym
+#define OVERRIDE_SYMBOL(sym,...) \
+    _font_init_stubs(); \
+    if (__##sym && __##sym != sym) \
+      return (*__##sym)(__VA_ARGS__)
+#define OVERRIDE_VA_SYMBOL(sym,f) \
+    va_list _args; \
+    _font_init_stubs(); \
+    va_start(_args, f); \
+    if (__##sym) \
+      (*__##sym)(f, _args); \
+    va_end(_args)
+
+int (*__client_auth_generation)(ClientPtr);
+Bool (*__ClientSignal)(ClientPtr);
+void (*__DeleteFontClientID)(Font);
+void (*__VErrorF)(const char *, va_list);
+FontPtr (*__find_old_font)(FSID);
+FontResolutionPtr (*__GetClientResolutions)(int *);
+int (*__GetDefaultPointSize)(void);
+Font (*__GetNewFontClientID)(void);
+unsigned long (*__GetTimeInMillis)(void);
+int (*__init_fs_handlers)(FontPathElementPtr, BlockHandlerProcPtr);
+int (*__RegisterFPEFunctions)(NameCheckFunc, InitFpeFunc, FreeFpeFunc,
+     ResetFpeFunc, OpenFontFunc, CloseFontFunc, ListFontsFunc,
+     StartLfwiFunc, NextLfwiFunc, WakeupFpeFunc, ClientDiedFunc,
+     LoadGlyphsFunc, StartLaFunc, NextLaFunc, SetPathFunc);
+void (*__remove_fs_handlers)(FontPathElementPtr, BlockHandlerProcPtr, Bool);
+void **__ptr_serverClient;
+int (*__set_font_authorizations)(char **, int *, ClientPtr);
+int (*__StoreFontClientFont)(FontPtr, Font);
+Atom (*__MakeAtom)(const char *, unsigned, int);
+int (*__ValidAtom)(Atom);
+char *(*__NameForAtom)(Atom);
+unsigned long *__ptr_serverGeneration;
+void (*__register_fpe_functions)(void);
+#else /* NO_WEAK_SYMBOLS && PIC */
+#define OVERRIDE_DATA(sym)
+#define OVERRIDE_SYMBOL(sym,...)
+#define OVERRIDE_VA_SYMBOL(sym,f)
+#endif
+
 /* This is really just a hack for now... __APPLE__ really should be using
  * the weak symbols route above, but it's causing an as-yet unresolved issue,
  * so we're instead building with flat_namespace.
@@ -36,6 +84,5 @@ extern int set_font_authorizations ( char **authorizations,
 extern unsigned long GetTimeInMillis (void);
 
 extern void ErrorF(const char *format, ...);
-extern void FatalError(const char *format, ...);
 
 /* end of file */
diff --git a/src/stubs/stubsinit.c b/src/stubs/stubsinit.c
new file mode 100644 (file)
index 0000000..fc52332
--- /dev/null
@@ -0,0 +1,82 @@
+#include "stubs.h"
+
+#if defined(NO_WEAK_SYMBOLS) && defined(PIC)
+
+#ifdef WIN32
+#include <X11/Xwindows.h>
+#define DLOPEN_SELF() GetModuleHandle(NULL)
+#define DLSYM(h,f) GetProcAddress(h,f)
+#else
+#include <dlfcn.h>
+#define DLOPEN_SELF() dlopen(NULL, RTLD_LOCAL)
+#define DLSYM(h,f) dlsym(h, f)
+#endif
+
+int (*__client_auth_generation)(ClientPtr) = NULL;
+Bool (*__ClientSignal)(ClientPtr) = NULL;
+void (*__DeleteFontClientID)(Font) = NULL;
+void (*__VErrorF)(const char *, va_list) = NULL;
+FontPtr (*__find_old_font)(FSID) = NULL;
+FontResolutionPtr (*__GetClientResolutions)(int *) = NULL;
+int (*__GetDefaultPointSize)(void) = NULL;
+Font (*__GetNewFontClientID)(void) = NULL;
+unsigned long (*__GetTimeInMillis)(void) = NULL;
+int (*__init_fs_handlers)(FontPathElementPtr, BlockHandlerProcPtr) = NULL;
+int (*__RegisterFPEFunctions)(NameCheckFunc, InitFpeFunc, FreeFpeFunc,
+     ResetFpeFunc, OpenFontFunc, CloseFontFunc, ListFontsFunc,
+     StartLfwiFunc, NextLfwiFunc, WakeupFpeFunc, ClientDiedFunc,
+     LoadGlyphsFunc, StartLaFunc, NextLaFunc, SetPathFunc) = NULL;
+void (*__remove_fs_handlers)(FontPathElementPtr, BlockHandlerProcPtr, Bool) = NULL;
+void **__ptr_serverClient = NULL;
+int (*__set_font_authorizations)(char **, int *, ClientPtr) = NULL;
+int (*__StoreFontClientFont)(FontPtr, Font) = NULL;
+Atom (*__MakeAtom)(const char *, unsigned, int) = NULL;
+int (*__ValidAtom)(Atom) = NULL;
+char *(*__NameForAtom)(Atom) = NULL;
+unsigned long *__ptr_serverGeneration = NULL;
+void (*__register_fpe_functions)(void) = NULL;
+
+#define INIT_SYMBOL(sym) \
+  if (!__##sym) \
+   __##sym = (typeof(__##sym)) DLSYM(handle, #sym)
+#define INIT_DATA(sym) \
+  if (!__ptr_##sym) \
+   __ptr_##sym = (typeof(__ptr_##sym)) DLSYM(handle, #sym)
+
+int
+_font_init_stubs (void)
+{
+  static int inited = FALSE;
+  static void *handle = NULL;
+
+  if (inited)
+    return inited;
+  if (!handle)
+    handle = DLOPEN_SELF();
+
+  INIT_SYMBOL(client_auth_generation);
+  INIT_SYMBOL(ClientSignal);
+  INIT_SYMBOL(DeleteFontClientID);
+  INIT_SYMBOL(VErrorF);
+  INIT_SYMBOL(find_old_font);
+  INIT_SYMBOL(GetClientResolutions);
+  INIT_SYMBOL(GetDefaultPointSize);
+  INIT_SYMBOL(GetNewFontClientID);
+  INIT_SYMBOL(GetTimeInMillis);
+  INIT_SYMBOL(init_fs_handlers);
+  INIT_SYMBOL(RegisterFPEFunctions);
+  INIT_SYMBOL(remove_fs_handlers);
+  INIT_SYMBOL(set_font_authorizations);
+  INIT_SYMBOL(StoreFontClientFont);
+  INIT_SYMBOL(MakeAtom);
+  INIT_SYMBOL(ValidAtom);
+  INIT_SYMBOL(NameForAtom);
+  INIT_SYMBOL(register_fpe_functions);
+  INIT_DATA(serverClient);
+  INIT_DATA(serverGeneration);
+
+  inited = TRUE;
+  return inited;
+}
+
+#endif /* NO_WEAK_SYMBOLS && PIC */
index 37811f9..5f7f1c6 100644 (file)
@@ -158,6 +158,8 @@ MakeAtom(const char *string, unsigned len, int makeit)
     int                h = 0;
     int                r;
 
+    OVERRIDE_SYMBOL(MakeAtom, string, len, makeit);
+
     hash = Hash (string, len);
     if (hashTable)
     {
@@ -230,6 +232,7 @@ MakeAtom(const char *string, unsigned len, int makeit)
 weak int
 ValidAtom(Atom atom)
 {
+    OVERRIDE_SYMBOL(ValidAtom, atom);
     return (atom != None) && (atom <= lastAtom);
 }
 
@@ -240,6 +243,7 @@ ValidAtom(Atom atom)
 weak char *
 NameForAtom(Atom atom)
 {
+    OVERRIDE_SYMBOL(NameForAtom, atom);
     if (atom != None && atom <= lastAtom)
        return reverseMap[atom]->name;
     return NULL;
index 3d802d2..61c9d11 100644 (file)
@@ -45,14 +45,22 @@ from The Open Group.
 
 extern void BuiltinRegisterFpeFunctions(void);
 
-#ifndef NO_WEAK_SYMBOLS
 /* make sure everything initializes themselves at least once */
 weak unsigned long serverGeneration = 1;
-#endif
+
+unsigned long __GetServerGeneration (void);
+
+unsigned long
+__GetServerGeneration (void)
+{
+  OVERRIDE_DATA(serverGeneration);
+  return serverGeneration;
+}
 
 weak void
 register_fpe_functions (void)
 {
+    OVERRIDE_SYMBOL(register_fpe_functions);
     BuiltinRegisterFpeFunctions();
     FontFileRegisterFpeFunctions();
 #ifdef XFONT_FC
index 9c05fa1..2101015 100644 (file)
@@ -50,7 +50,7 @@ typedef unsigned char EntryPtr;
 typedef struct _FontPatternCacheEntry {
     struct _FontPatternCacheEntry   *next, **prev;
     short                          patlen;
-    char                           *pattern;
+    const char                     *pattern;
     int                                    hash;
     FontPtr                        pFont;      /* associated font */
 } FontPatternCacheEntryRec, *FontPatternCacheEntryPtr;
@@ -74,7 +74,7 @@ EmptyFontPatternCache (FontPatternCachePtr cache)
        cache->entries[i].next = &cache->entries[i+1];
        cache->entries[i].prev = 0;
        cache->entries[i].pFont = 0;
-       free (cache->entries[i].pattern);
+       free ((void *) cache->entries[i].pattern);
        cache->entries[i].pattern = 0;
        cache->entries[i].patlen = 0;
     }
@@ -107,7 +107,7 @@ FreeFontPatternCache (FontPatternCachePtr cache)
     int            i;
 
     for (i = 0; i < NENTRIES; i++)
-       free (cache->entries[i].pattern);
+       free ((void *) cache->entries[i].pattern);
     free (cache);
 }
 
@@ -128,7 +128,7 @@ Hash (const char *string, int len)
 /* add entry */
 void
 CacheFontPattern (FontPatternCachePtr cache,
-                 char *pattern,
+                 const char *pattern,
                  int patlen,
                  FontPtr pFont)
 {
@@ -154,7 +154,7 @@ CacheFontPattern (FontPatternCachePtr cache,
        if (e->next)
            e->next->prev = e->prev;
        *e->prev = e->next;
-       free (e->pattern);
+       free ((void *) e->pattern);
     }
     /* set pattern */
     memcpy (newpat, pattern, patlen);
@@ -174,7 +174,7 @@ CacheFontPattern (FontPatternCachePtr cache,
 /* find matching entry */
 FontPtr
 FindCachedFontPattern (FontPatternCachePtr cache,
-                      char *pattern,
+                      const char *pattern,
                       int patlen)
 {
     int                                hash;
@@ -211,7 +211,7 @@ RemoveCachedFontPattern (FontPatternCachePtr cache,
            *e->prev = e->next;
            e->next = cache->free;
            cache->free = e;
-           free (e->pattern);
+           free ((void *) e->pattern);
            e->pattern = 0;
        }
     }