if (namelen > sizeof (buf) - 1)
if (namelen <= 0 || namelen > sizeof (buf) - 1)
fs_send_open_font(client, fpe, flags, name, namelen, format, fmask, id, ppfont)    pointer     client;    FontPathElementPtr fpe;    Mask        flags;    char       *name;    int         namelen;    fsBitmapFormat format;    fsBitmapFormatMask fmask;    XID         id;    FontPtr    *ppfont;{    FontPtr     newfont;    FSBlockDataPtr blockrec = NULL;    FSBlockedFontPtr blockedfont;    FSFontDataPtr fsd;    FSFontPtr   fsfont;    FSFpePtr    conn;    fsOpenBitmapFontReq openreq;    int         err = Suspended;    XID         newid;    unsigned char buf[1024];    char       *fontname;    if (flags & FontReopen)    {	Atom nameatom, fn = None;	int i;	newfont = *ppfont;	fsd = (FSFontDataPtr)newfont->fpePrivate;	fsfont = (FSFontPtr)newfont->fontPrivate;	fpe = newfont->fpe;	format = fsd->format;	fmask = fsd->fmask;	newid = fsd->fontid;	/* This is an attempt to reopen a font.  Did the font have a	   NAME property? */	if ((nameatom = MakeAtom("FONT", 4, 0)) != None)	{	    for (i = 0; i < newfont->info.nprops; i++)		if (newfont->info.props[i].name == nameatom &&		    newfont->info.isStringProp[i])		{		    fn = newfont->info.props[i].value;		    break;		}	}	if (fn == None || !(name = NameForAtom(fn)))	{	    name = fsd->name;	    namelen = fsd->namelen;	}	else	    namelen = strlen(name);    }    conn = (FSFpePtr) fpe->private;    if (namelen > sizeof (buf) - 1)	return BadFontName;    _fs_client_access (conn, client, (flags & FontOpenSync) != 0);    _fs_client_resolution(conn);    if (!(flags & FontReopen))    {	newid = GetNewFontClientID();	/* make the font */	newfont = (FontPtr) xalloc(sizeof(FontRec));	/* and the FS data */	fsd = (FSFontDataPtr) xalloc(sizeof(FSFontDataRec));	fsfont = (FSFontPtr) xalloc(sizeof(FSFontRec));	fontname = (char *)xalloc(namelen);	if (!newfont || !fsd || !fsfont || !fontname) {lowmem:	    if (!(flags & FontReopen))	    {		xfree((char *) newfont);		xfree((char *) fsd);		xfree((char *) fsfont);		xfree((char *) fontname);	    }	    if (blockrec) fs_abort_blockrec(conn, blockrec);	    return AllocError;	}	bzero((char *) newfont, sizeof(FontRec));	bzero((char *) fsfont, sizeof(FSFontRec));	bzero((char *) fsd, sizeof(FSFontDataRec));    }    /* make a new block record, and add it to the end of the list */    blockrec = fs_new_block_rec(fpe, client, FS_OPEN_FONT);    if (!blockrec) {	goto lowmem;    }    if (!(flags & FontReopen))    {	int bit, byte, scan, glyph;	newfont->refcnt = 0;	newfont->maxPrivate = -1;	newfont->devPrivates = (pointer *) 0;	newfont->format = format;	/* These font components will be needed in packGlyphs */	CheckFSFormat(format, BitmapFormatMaskBit |			      BitmapFormatMaskByte |			      BitmapFormatMaskScanLineUnit |			      BitmapFormatMaskScanLinePad,		      &bit,		      &byte,		      &scan,		      &glyph,		      NULL);	newfont->bit = bit;	newfont->byte = byte;	newfont->scan = scan;	newfont->glyph = glyph;	newfont->fpe = fpe;	newfont->fpePrivate = (pointer) fsd;	newfont->fontPrivate = (pointer) fsfont;	_fs_init_font(newfont);	fsd->fpe = fpe;	fsd->name = fontname;	fsd->namelen = namelen;	memcpy(fontname, name, namelen);	fsd->format = format;	fsd->fmask = fmask;    }    fsd->fontid = newid;    fsd->generation = conn->generation;    blockedfont = (FSBlockedFontPtr) blockrec->data;    blockedfont->fontid = newid;    blockedfont->pfont = newfont;    blockedfont->state = FS_OPEN_REPLY;    blockedfont->flags = flags;    blockedfont->format = format;    blockedfont->clients_depending = (FSClientsDependingPtr)0;    /* save the ID */    if (!StoreFontClientFont(blockedfont->pfont, blockedfont->fontid)) {	goto lowmem;    }    /* do an FS_OpenFont, FS_QueryXInfo and FS_QueryXExtents */    buf[0] = (unsigned char) namelen;    memcpy(&buf[1], name, namelen);    namelen++;    openreq.reqType = FS_OpenBitmapFont;    openreq.fid = newid;    openreq.format_hint = format;    openreq.format_mask = fmask;    openreq.length = (SIZEOF(fsOpenBitmapFontReq) + namelen + 3) >> 2;    _fs_add_req_log(conn, FS_OpenBitmapFont);    _fs_write(conn, (char *) &openreq, SIZEOF(fsOpenBitmapFontReq));    _fs_write_pad(conn, (char *) buf, namelen);#ifdef NCD    if (configData.ExtendedFontDiags) {	memcpy(buf, name, MIN(256, namelen));	buf[MIN(256, namelen)] = '\0';	printf("Requesting font \"%s\" from font server \"%s\"\n",	       buf, fpe->name);    }#endif    if (flags & FontOpenSync) {	err = fs_do_open_font(fpe, blockrec, TRUE);	if (blockedfont->errcode == Successful) {	    *ppfont = blockedfont->pfont;	} else {	    _fs_cleanup_font(blockedfont);	}	_fs_remove_block_rec(conn, blockrec);    }    return err;}