diff options
Diffstat (limited to 'src')
43 files changed, 534 insertions, 146 deletions
diff --git a/src/FreeType/ftfuncs.c b/src/FreeType/ftfuncs.c index 44e5e02..a4969d1 100644 --- a/src/FreeType/ftfuncs.c +++ b/src/FreeType/ftfuncs.c @@ -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++; diff --git a/src/FreeType/xttcap.c b/src/FreeType/xttcap.c index 104dc89..cee752e 100644 --- a/src/FreeType/xttcap.c +++ b/src/FreeType/xttcap.c @@ -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'; diff --git a/src/Makefile.am b/src/Makefile.am index cd09ab9..33fd135 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 diff --git a/src/bitmap/Makefile.am b/src/bitmap/Makefile.am index 99682d9..0f2d10a 100644 --- a/src/bitmap/Makefile.am +++ b/src/bitmap/Makefile.am @@ -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 diff --git a/src/bitmap/bitmap.c b/src/bitmap/bitmap.c index 9b20faf..0a379eb 100644 --- a/src/bitmap/bitmap.c +++ b/src/bitmap/bitmap.c @@ -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; diff --git a/src/bitmap/bitmapfunc.c b/src/bitmap/bitmapfunc.c index 603d5d9..8c6b3d8 100644 --- a/src/bitmap/bitmapfunc.c +++ b/src/bitmap/bitmapfunc.c @@ -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 */ diff --git a/src/bitmap/bitscale.c b/src/bitmap/bitscale.c index e89ba7c..c9af4c0 100644 --- a/src/bitmap/bitscale.c +++ b/src/bitmap/bitscale.c @@ -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; diff --git a/src/builtins/builtin.h b/src/builtins/builtin.h index 75dff8d..f9a4cea 100644 --- a/src/builtins/builtin.h +++ b/src/builtins/builtin.h @@ -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); diff --git a/src/builtins/dir.c b/src/builtins/dir.c index 490e7e3..0225bfc 100644 --- a/src/builtins/dir.c +++ b/src/builtins/dir.c @@ -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; diff --git a/src/builtins/file.c b/src/builtins/file.c index 3f657d9..93527c1 100644 --- a/src/builtins/file.c +++ b/src/builtins/file.c @@ -90,7 +90,7 @@ BuiltinClose (BufFilePtr f, int unused) FontFilePtr -BuiltinFileOpen (char *name) +BuiltinFileOpen (const char *name) { int i; BuiltinIOPtr io; diff --git a/src/builtins/fpe.c b/src/builtins/fpe.c index 83905da..4f5d4cf 100644 --- a/src/builtins/fpe.c +++ b/src/builtins/fpe.c @@ -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; } diff --git a/src/fc/fsconvert.c b/src/fc/fsconvert.c index faf2e5d..18b0c0d 100644 --- a/src/fc/fsconvert.c +++ b/src/fc/fsconvert.c @@ -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); diff --git a/src/fc/fserve.c b/src/fc/fserve.c index a445144..92b0d53 100644 --- a/src/fc/fserve.c +++ b/src/fc/fserve.c @@ -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; diff --git a/src/fc/fserve.h b/src/fc/fserve.h index 5999861..502e201 100644 --- a/src/fc/fserve.h +++ b/src/fc/fserve.h @@ -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); diff --git a/src/fc/fsio.h b/src/fc/fsio.h index 2bb8e0b..fa1e7d8 100644 --- a/src/fc/fsio.h +++ b/src/fc/fsio.h @@ -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; diff --git a/src/fontfile/bufio.c b/src/fontfile/bufio.c index 34b7f36..d8d4f29 100644 --- a/src/fontfile/bufio.c +++ b/src/fontfile/bufio.c @@ -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; } diff --git a/src/fontfile/catalogue.c b/src/fontfile/catalogue.c index 09ca2ae..81a1e13 100644 --- a/src/fontfile/catalogue.c +++ b/src/fontfile/catalogue.c @@ -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); diff --git a/src/fontfile/dirfile.c b/src/fontfile/dirfile.c index 0d34db9..38ced75 100644 --- a/src/fontfile/dirfile.c +++ b/src/fontfile/dirfile.c @@ -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) diff --git a/src/fontfile/fontdir.c b/src/fontfile/fontdir.c index ef7ffa5..7271603 100644 --- a/src/fontfile/fontdir.c +++ b/src/fontfile/fontdir.c @@ -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) diff --git a/src/fontfile/fontfile.c b/src/fontfile/fontfile.c index c55282b..05a9610 100644 --- a/src/fontfile/fontfile.c +++ b/src/fontfile/fontfile.c @@ -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); diff --git a/src/fontfile/renderers.c b/src/fontfile/renderers.c index 5091922..bbcd466 100644 --- a/src/fontfile/renderers.c +++ b/src/fontfile/renderers.c @@ -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); diff --git a/src/stubs/Makefile.am b/src/stubs/Makefile.am index 23e3bd1..7eb16d4 100644 --- a/src/stubs/Makefile.am +++ b/src/stubs/Makefile.am @@ -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 diff --git a/src/stubs/cauthgen.c b/src/stubs/cauthgen.c index 026c52d..10086e4 100644 --- a/src/stubs/cauthgen.c +++ b/src/stubs/cauthgen.c @@ -10,5 +10,6 @@ weak int client_auth_generation(ClientPtr client) { + OVERRIDE_SYMBOL(client_auth_generation, client); return 0; } diff --git a/src/stubs/csignal.c b/src/stubs/csignal.c index e6fdeae..dd88b3d 100644 --- a/src/stubs/csignal.c +++ b/src/stubs/csignal.c @@ -10,5 +10,6 @@ weak Bool ClientSignal(ClientPtr client) { + OVERRIDE_SYMBOL(ClientSignal,client); return True; } diff --git a/src/stubs/delfntcid.c b/src/stubs/delfntcid.c index ca71328..8113b9f 100644 --- a/src/stubs/delfntcid.c +++ b/src/stubs/delfntcid.c @@ -10,4 +10,5 @@ weak void DeleteFontClientID(Font id) { + OVERRIDE_SYMBOL(DeleteFontClientID, id); } diff --git a/src/stubs/errorf.c b/src/stubs/errorf.c index fd32965..d2de6c6 100644 --- a/src/stubs/errorf.c +++ b/src/stubs/errorf.c @@ -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 index 1549ad3..0000000 --- a/src/stubs/fatalerror.c +++ /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, ...) -{ -} diff --git a/src/stubs/findoldfnt.c b/src/stubs/findoldfnt.c index 7a00084..c73279e 100644 --- a/src/stubs/findoldfnt.c +++ b/src/stubs/findoldfnt.c @@ -10,5 +10,6 @@ weak FontPtr find_old_font(FSID id) { + OVERRIDE_SYMBOL(find_old_font, id); return (FontPtr)NULL; } diff --git a/src/stubs/getcres.c b/src/stubs/getcres.c index 0b98f46..27a9180 100644 --- a/src/stubs/getcres.c +++ b/src/stubs/getcres.c @@ -10,5 +10,6 @@ weak FontResolutionPtr GetClientResolutions(int *num) { + OVERRIDE_SYMBOL(GetClientResolutions, num); return (FontResolutionPtr) 0; } diff --git a/src/stubs/getdefptsize.c b/src/stubs/getdefptsize.c index 0b9e409..50c1b18 100644 --- a/src/stubs/getdefptsize.c +++ b/src/stubs/getdefptsize.c @@ -10,5 +10,6 @@ weak int GetDefaultPointSize(void) { + OVERRIDE_SYMBOL(GetDefaultPointSize); return 0; } diff --git a/src/stubs/getnewfntcid.c b/src/stubs/getnewfntcid.c index e2fe8bb..d31ccf1 100644 --- a/src/stubs/getnewfntcid.c +++ b/src/stubs/getnewfntcid.c @@ -10,5 +10,6 @@ weak Font GetNewFontClientID(void) { + OVERRIDE_SYMBOL(GetNewFontClientID); return (Font)0; } diff --git a/src/stubs/gettime.c b/src/stubs/gettime.c index 7b2d3b3..1b20f62 100644 --- a/src/stubs/gettime.c +++ b/src/stubs/gettime.c @@ -10,5 +10,6 @@ weak unsigned long GetTimeInMillis (void) { + OVERRIDE_SYMBOL(GetTimeInMillis); return 0; } diff --git a/src/stubs/initfshdl.c b/src/stubs/initfshdl.c index a14daff..e1c0b24 100644 --- a/src/stubs/initfshdl.c +++ b/src/stubs/initfshdl.c @@ -11,5 +11,6 @@ weak int init_fs_handlers(FontPathElementPtr fpe, BlockHandlerProcPtr block_handler) { + OVERRIDE_SYMBOL(init_fs_handlers, fpe, block_handler); return Successful; } diff --git a/src/stubs/regfpefunc.c b/src/stubs/regfpefunc.c index fdf22cd..ae12a01 100644 --- a/src/stubs/regfpefunc.c +++ b/src/stubs/regfpefunc.c @@ -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; } diff --git a/src/stubs/rmfshdl.c b/src/stubs/rmfshdl.c index b495661..22a3091 100644 --- a/src/stubs/rmfshdl.c +++ b/src/stubs/rmfshdl.c @@ -12,4 +12,5 @@ remove_fs_handlers(FontPathElementPtr fpe, BlockHandlerProcPtr blockHandler, Bool all) { + OVERRIDE_SYMBOL(remove_fs_handlers, fpe, blockHandler, all); } diff --git a/src/stubs/servclient.c b/src/stubs/servclient.c index 9b6cebb..f85e08e 100644 --- a/src/stubs/servclient.c +++ b/src/stubs/servclient.c @@ -8,3 +8,12 @@ #endif weak void *serverClient = 0; + +void *__GetServerClient(void); + +void * +__GetServerClient(void) +{ + OVERRIDE_DATA(serverClient); + return serverClient; +} diff --git a/src/stubs/setfntauth.c b/src/stubs/setfntauth.c index 0c7eccc..371807e 100644 --- a/src/stubs/setfntauth.c +++ b/src/stubs/setfntauth.c @@ -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; } diff --git a/src/stubs/stfntcfnt.c b/src/stubs/stfntcfnt.c index 5fc1745..d490988 100644 --- a/src/stubs/stfntcfnt.c +++ b/src/stubs/stfntcfnt.c @@ -10,5 +10,6 @@ weak int StoreFontClientFont(FontPtr pfont, Font id) { + OVERRIDE_SYMBOL(StoreFontClientFont, pfont, id); return 0; } diff --git a/src/stubs/stubs.h b/src/stubs/stubs.h index fa634e9..7d499d5 100644 --- a/src/stubs/stubs.h +++ b/src/stubs/stubs.h @@ -19,6 +19,54 @@ #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 index 0000000..fc52332 --- /dev/null +++ b/src/stubs/stubsinit.c @@ -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 */ diff --git a/src/util/atom.c b/src/util/atom.c index 37811f9..5f7f1c6 100644 --- a/src/util/atom.c +++ b/src/util/atom.c @@ -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; diff --git a/src/util/miscutil.c b/src/util/miscutil.c index 3d802d2..61c9d11 100644 --- a/src/util/miscutil.c +++ b/src/util/miscutil.c @@ -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 diff --git a/src/util/patcache.c b/src/util/patcache.c index 9c05fa1..2101015 100644 --- a/src/util/patcache.c +++ b/src/util/patcache.c @@ -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; } } |