~ubuntu-branches/ubuntu/gutsy/vnc4/gutsy

« back to all changes in this revision

Viewing changes to unix/xc/programs/xfs/difs/fontinfo.c

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2006-05-15 20:35:17 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060515203517-l4lre1ku942mn26k
Tags: 4.1.1+X4.3.0-10
* Correction of critical security issue. Thanks to Martin Kogler
  <e9925248@student.tuwien.ac.at> that informed me about the issue,
  and provided the patch.
  This flaw was originally found by Steve Wiseman of intelliadmin.com.
* Applied patch from Javier Kohen <jkohen@users.sourceforge.net> that
  inform the user that only 8 first characters of the password will
  actually be used when typing more than 8 characters, closes:
  #355619.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Xorg: fontinfo.c,v 1.4 2001/02/09 02:05:42 xorgcvs Exp $ */
 
2
/*
 
3
 * font data query
 
4
 */
 
5
/*
 
6
 
 
7
Copyright 1990, 1991, 1998  The Open Group
 
8
 
 
9
Permission to use, copy, modify, distribute, and sell this software and its
 
10
documentation for any purpose is hereby granted without fee, provided that
 
11
the above copyright notice appear in all copies and that both that
 
12
copyright notice and this permission notice appear in supporting
 
13
documentation.
 
14
 
 
15
The above copyright notice and this permission notice shall be included in
 
16
all copies or substantial portions of the Software.
 
17
 
 
18
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
19
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
20
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
 
21
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 
22
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
23
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
24
 
 
25
Except as contained in this notice, the name of The Open Group shall not be
 
26
used in advertising or otherwise to promote the sale, use or other dealings
 
27
in this Software without prior written authorization from The Open Group.
 
28
 
 
29
 * Copyright 1990, 1991 Network Computing Devices;
 
30
 * Portions Copyright 1987 by Digital Equipment Corporation 
 
31
 *
 
32
 * Permission to use, copy, modify, distribute, and sell this software and
 
33
 * its documentation for any purpose is hereby granted without fee, provided
 
34
 * that the above copyright notice appear in all copies and that both that
 
35
 * copyright notice and this permission notice appear in supporting
 
36
 * documentation, and that the names of Network Computing Devices, or Digital
 
37
 * not be used in advertising or publicity pertaining to distribution
 
38
 * of the software without specific, written prior permission.
 
39
 *
 
40
 * NETWORK COMPUTING DEVICES, AND DIGITAL DISCLAIM ALL WARRANTIES WITH
 
41
 * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
 
42
 * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES,
 
43
 * OR DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
 
44
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
 
45
 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
 
46
 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
 
47
 * THIS SOFTWARE.
 
48
 */
 
49
/* $XFree86: xc/programs/xfs/difs/fontinfo.c,v 1.11 2002/10/15 01:45:02 dawes Exp $ */
 
50
 
 
51
#include        "FS.h"
 
52
#include        "FSproto.h"
 
53
#include        <stdio.h>
 
54
#include        <X11/Xos.h>
 
55
#include        "clientstr.h"
 
56
#include        "difsfnst.h"
 
57
#include        "fontstruct.h"
 
58
#include        "closestr.h"
 
59
#include        "globals.h"
 
60
#include        "difs.h"
 
61
#include        "dispatch.h"
 
62
#include        <swapreq.h>
 
63
#include        <swaprep.h>
 
64
 
 
65
void
 
66
CopyCharInfo(
 
67
    CharInfoPtr ci,
 
68
    fsXCharInfo *dst)
 
69
{
 
70
    xCharInfo  *src = &ci->metrics;
 
71
 
 
72
    dst->ascent = src->ascent;
 
73
    dst->descent = src->descent;
 
74
    dst->left = src->leftSideBearing;
 
75
    dst->right = src->rightSideBearing;
 
76
    dst->width = src->characterWidth;
 
77
    dst->attributes = src->attributes;
 
78
}
 
79
 
 
80
 
 
81
int
 
82
convert_props(
 
83
    FontInfoPtr pinfo,
 
84
    fsPropInfo **props)
 
85
{
 
86
    int i;
 
87
    int data_len, cur_off;
 
88
    char *str;
 
89
    pointer ptr, off_ptr, string_base;
 
90
    fsPropOffset local_offset;
 
91
 
 
92
    /*
 
93
     * compute the size of the property data
 
94
     */
 
95
    data_len = 0;
 
96
    for (i = 0; i < pinfo->nprops; i++)
 
97
    {
 
98
        data_len += strlen(NameForAtom(pinfo->props[i].name));
 
99
        if (NULL != pinfo->isStringProp && pinfo->isStringProp[i])
 
100
            data_len += strlen(NameForAtom(pinfo->props[i].value));
 
101
    }
 
102
 
 
103
    /*
 
104
     * allocate the single chunk that the difs layer requires
 
105
     */
 
106
    ptr = (pointer) fsalloc(SIZEOF(fsPropInfo)
 
107
                            + SIZEOF(fsPropOffset) * pinfo->nprops
 
108
                            + data_len);
 
109
    if (!ptr)
 
110
        return AllocError;
 
111
    string_base = (char *)ptr + SIZEOF(fsPropInfo) + SIZEOF(fsPropOffset) * pinfo->nprops;
 
112
  
 
113
    /*
 
114
     * copy in the header
 
115
     */
 
116
    ((fsPropInfo *)ptr)->num_offsets = pinfo->nprops;
 
117
    ((fsPropInfo *)ptr)->data_len = data_len;
 
118
 
 
119
    /*
 
120
     * compute the offsets and copy the string data
 
121
     */
 
122
    off_ptr = (char *)ptr + SIZEOF(fsPropInfo);
 
123
    cur_off = 0;
 
124
    for (i = 0; i < pinfo->nprops; i++)
 
125
    {
 
126
        local_offset.name.position = cur_off;
 
127
        str = NameForAtom(pinfo->props[i].name);
 
128
        local_offset.name.length = strlen(str);
 
129
        memmove( (char *)string_base+cur_off, str, local_offset.name.length);
 
130
        cur_off += local_offset.name.length;
 
131
        if (NULL != pinfo->isStringProp && pinfo->isStringProp[i])
 
132
        {
 
133
            local_offset.value.position = cur_off;
 
134
            str = NameForAtom(pinfo->props[i].value);
 
135
            local_offset.value.length = strlen(str);
 
136
            memmove( (char *)string_base+cur_off, str, local_offset.value.length);
 
137
            cur_off += local_offset.value.length;
 
138
            local_offset.type = PropTypeString;
 
139
        } else {
 
140
            local_offset.value.position = pinfo->props[i].value;
 
141
            local_offset.value.length = 0; /* protocol says must be zero */
 
142
            local_offset.type = PropTypeSigned;
 
143
        }
 
144
        memmove( off_ptr, &local_offset, SIZEOF(fsPropOffset));
 
145
        off_ptr = (char *)off_ptr + SIZEOF(fsPropOffset);
 
146
    }
 
147
 
 
148
    assert(off_ptr == string_base);
 
149
    assert(cur_off == data_len);
 
150
 
 
151
    *props = (fsPropInfo *) ptr;
 
152
    return Successful;
 
153
}
 
154
 
 
155
 
 
156
/*
 
157
 * does the real work of turning a list of range (or chars) into
 
158
 * a list of ranges
 
159
 */
 
160
static fsRange *
 
161
build_range(
 
162
    Bool        type,
 
163
    pointer     src,
 
164
    int         item_size,
 
165
    int        *num,
 
166
    Bool       *all,
 
167
    FontInfoPtr pfi)
 
168
{
 
169
    fsRange    *new = (fsRange *) 0,
 
170
               *np;
 
171
    unsigned long src_num;
 
172
    unsigned long i;
 
173
 
 
174
    if (type) {                 /* range flag is set, deal with data as a list
 
175
                                 * of char2bs */
 
176
        char *rp = (char *) src;
 
177
 
 
178
        src_num = *num;
 
179
        if (src_num == 0) {
 
180
            *all = TRUE;
 
181
            return new;
 
182
        }
 
183
 
 
184
        np = new = (fsRange *) fsalloc(sizeof(fsRange) * (src_num + 1) / 2);
 
185
        if (!np)
 
186
            return np;
 
187
        /* Build a new range */
 
188
        for (i = 1; i < src_num; i += 2)
 
189
        {
 
190
            np->min_char_high = (item_size == 1) ? 0 : *rp++;
 
191
            np->min_char_low  = *rp++;
 
192
            np->max_char_high = (item_size == 1) ? 0 : *rp++;
 
193
            np->max_char_low  = *rp++;
 
194
            np++;
 
195
        }
 
196
 
 
197
        /* If src_num is odd, we need to determine the final range
 
198
           by examining the fontinfo */
 
199
        if (i == src_num)
 
200
        {
 
201
            np->min_char_high = (item_size == 1) ? 0 : *rp++;
 
202
            np->min_char_low  = *rp++;
 
203
            np->max_char_high = pfi->lastRow;
 
204
            np->max_char_low  = pfi->lastCol;
 
205
            np++;
 
206
        }
 
207
        *num = np - new;
 
208
        return new;
 
209
    } else {                    /* deal with data as a list of characters */
 
210
        unsigned char      *pp = src;
 
211
 
 
212
        src_num = *num;
 
213
        np = new = (fsRange *) fsalloc(SIZEOF(fsRange) * src_num);
 
214
        if (!np)
 
215
            return np;
 
216
 
 
217
        /* Build a range, with coalescence, from the list of chars */
 
218
 
 
219
        for (i = 0; i < src_num; i++) {
 
220
            if (item_size == 1) {
 
221
                np->min_char_low = *pp;
 
222
                np->min_char_high = 0;
 
223
            } else {
 
224
                np->min_char_low = ((fsChar2b *) pp)->low;
 
225
                np->min_char_high = ((fsChar2b *) pp)->high;
 
226
            }
 
227
            np->max_char_high = np->min_char_high;
 
228
            np->max_char_low = np->min_char_low;
 
229
            /* Can we coalesce? */
 
230
            if (np > new &&
 
231
                np->max_char_high == np[-1].max_char_high &&
 
232
                np->max_char_low == np[-1].max_char_low + 1)
 
233
                np[-1].max_char_low++;          /* Yes */
 
234
            else
 
235
                np++;                           /* No */
 
236
            pp += item_size;
 
237
        }
 
238
        *num = np - new;
 
239
        return new;
 
240
    }
 
241
}
 
242
 
 
243
/*
 
244
 * provide backward compatibility with version 1, which had
 
245
 * the bytes of char2b backwards
 
246
 */
 
247
static void
 
248
swap_char2b (fsChar2b *values, int number)
 
249
{
 
250
    fsChar2b temp;
 
251
    int i;
 
252
 
 
253
    for (i = 0; i < number; i++) {
 
254
        temp.low = ((fsChar2b_version1 *)values)->low;
 
255
        temp.high = ((fsChar2b_version1 *)values)->high;
 
256
        *values++ = temp;
 
257
    }
 
258
}
 
259
 
 
260
#define pPtr ((QEclosurePtr) data)
 
261
 
 
262
static Bool
 
263
do_query_extents(ClientPtr client, pointer data)
 
264
{
 
265
    int         err;
 
266
    unsigned long lendata,
 
267
                num_extents;
 
268
    fsXCharInfo *extents;
 
269
    fsQueryXExtents8Reply reply;
 
270
 
 
271
    err = GetExtents (pPtr->client, pPtr->pfont,
 
272
                     pPtr->flags, pPtr->nranges, pPtr->range, &num_extents, &extents);
 
273
    if (err == Suspended) {
 
274
        if (!pPtr->slept) {
 
275
            pPtr->pfont->unload_glyphs = 0;  /* Not a safe call for this font */
 
276
            pPtr->slept = TRUE;
 
277
            ClientSleep(client, do_query_extents, (pointer) pPtr);
 
278
        }
 
279
        return TRUE;
 
280
    }
 
281
    if (err != Successful) {
 
282
        SendErrToClient(pPtr->client, FontToFSError(err), (pointer) 0);
 
283
        goto finish;
 
284
    }
 
285
    reply.type = FS_Reply;
 
286
    reply.sequenceNumber = pPtr->client->sequence;
 
287
    reply.num_extents = num_extents;
 
288
    lendata = SIZEOF(fsXCharInfo) * num_extents;
 
289
    reply.length = (SIZEOF(fsQueryXExtents8Reply) + lendata) >> 2;
 
290
    if (client->swapped)
 
291
        SwapExtents(extents, num_extents);
 
292
    WriteReplyToClient(pPtr->client, SIZEOF(fsQueryXExtents8Reply), &reply);
 
293
    (void) WriteToClient(pPtr->client, lendata, (char *) extents);
 
294
    fsfree((char *) extents);
 
295
finish:
 
296
    if (pPtr->slept)
 
297
        ClientWakeup(pPtr->client);
 
298
    if (pPtr->pfont->unload_glyphs)  /* For rasterizers that want to save memory */
 
299
        (*pPtr->pfont->unload_glyphs)(pPtr->pfont);
 
300
    fsfree(pPtr->range);
 
301
    fsfree(pPtr);
 
302
    return TRUE;
 
303
}
 
304
 
 
305
int
 
306
QueryExtents(
 
307
    ClientPtr   client,
 
308
    ClientFontPtr cfp,
 
309
    int         item_size,
 
310
    int         nranges,
 
311
    Bool        range_flag,
 
312
    pointer     range_data)
 
313
{
 
314
    QEclosurePtr c;
 
315
    fsRange    *fixed_range;
 
316
    Bool        all_glyphs = FALSE;
 
317
 
 
318
    if (item_size == 2  &&  client->major_version == 1)
 
319
        swap_char2b ((fsChar2b *)range_data, nranges);
 
320
 
 
321
    fixed_range = build_range(range_flag, range_data, item_size,
 
322
                              &nranges, &all_glyphs, &cfp->font->info);
 
323
 
 
324
    if (!fixed_range && !all_glyphs) {
 
325
        SendErrToClient(client, FSBadRange, 0);
 
326
        return FSBadRange;
 
327
    }
 
328
    c = (QEclosurePtr) fsalloc(sizeof(QEclosureRec));
 
329
    if (!c)
 
330
        return FSBadAlloc;
 
331
    c->client = client;
 
332
    c->slept = FALSE;
 
333
    c->pfont = cfp->font;
 
334
    c->flags = (all_glyphs) ? LoadAll : 0;
 
335
    c->flags |= (item_size == 1) ? EightBitFont : SixteenBitFont;
 
336
    c->nranges = nranges;
 
337
    c->range = fixed_range;
 
338
 
 
339
    (void) do_query_extents(client, (pointer) c);
 
340
    return FSSuccess;
 
341
}
 
342
 
 
343
#undef pPtr
 
344
#define pPtr ((QBclosurePtr) data)
 
345
 
 
346
static Bool
 
347
do_query_bitmaps(ClientPtr client, pointer data)
 
348
{
 
349
    int         err;
 
350
    unsigned long num_glyphs;
 
351
    int data_size;
 
352
    fsOffset32   *offsets;
 
353
    pointer     glyph_data;
 
354
    fsQueryXBitmaps8Reply reply;
 
355
    int         freedata;
 
356
 
 
357
    err = GetBitmaps (pPtr->client, pPtr->pfont, pPtr->format,
 
358
                                    pPtr->flags, pPtr->nranges, pPtr->range,
 
359
                             &data_size, &num_glyphs, &offsets, &glyph_data, &freedata);
 
360
 
 
361
    if (err == Suspended) {
 
362
        if (!pPtr->slept) {
 
363
            pPtr->pfont->unload_glyphs = 0;  /* Not a safe call for this font */
 
364
            pPtr->slept = TRUE;
 
365
            ClientSleep(client, do_query_bitmaps, (pointer) pPtr);
 
366
        }
 
367
        return TRUE;
 
368
    }
 
369
    if (err != Successful) {
 
370
        SendErrToClient(pPtr->client, FontToFSError(err), (pointer) 0);
 
371
        goto finish;
 
372
    }
 
373
    reply.type = FS_Reply;
 
374
    reply.sequenceNumber = pPtr->client->sequence;
 
375
    reply.replies_hint = 0;
 
376
    reply.num_chars = num_glyphs;
 
377
    reply.nbytes = data_size;
 
378
    reply.length = (SIZEOF(fsQueryXBitmaps8Reply) + data_size +
 
379
                    (SIZEOF(fsOffset32) * num_glyphs) + 3) >> 2;
 
380
 
 
381
    WriteReplyToClient(pPtr->client, SIZEOF(fsQueryXBitmaps8Reply), &reply);
 
382
    if (client->swapped)
 
383
        SwapLongs((long *)offsets, num_glyphs * 2);
 
384
    (void) WriteToClient(pPtr->client, (num_glyphs * SIZEOF(fsOffset32)),
 
385
                         (char *) offsets);
 
386
    (void) WriteToClient(pPtr->client, data_size, (char *) glyph_data);
 
387
    fsfree((char *) offsets);
 
388
    if (freedata)
 
389
        fsfree((char *) glyph_data);
 
390
finish:
 
391
    if (pPtr->slept)
 
392
        ClientWakeup(pPtr->client);
 
393
    if (pPtr->pfont->unload_glyphs)  /* For rasterizers that want to save memory */
 
394
        (*pPtr->pfont->unload_glyphs)(pPtr->pfont);
 
395
    fsfree(pPtr->range);
 
396
    fsfree(pPtr);
 
397
    return TRUE;
 
398
}
 
399
 
 
400
int
 
401
QueryBitmaps(
 
402
    ClientPtr   client,
 
403
    ClientFontPtr cfp,
 
404
    int         item_size,
 
405
    fsBitmapFormat format,
 
406
    int         nranges,
 
407
    Bool        range_flag,
 
408
    pointer     range_data)
 
409
{
 
410
    QBclosurePtr c;
 
411
    fsRange    *fixed_range;
 
412
    Bool        all_glyphs = FALSE;
 
413
 
 
414
    if (item_size == 2  &&  client->major_version == 1)
 
415
        swap_char2b ((fsChar2b *)range_data, nranges);
 
416
 
 
417
    fixed_range = build_range(range_flag, range_data, item_size,
 
418
                              &nranges, &all_glyphs, &cfp->font->info);
 
419
 
 
420
    if (!fixed_range && !all_glyphs) {
 
421
        SendErrToClient(client, FSBadRange, 0);
 
422
        return FSBadRange;
 
423
    }
 
424
    c = (QBclosurePtr) fsalloc(sizeof(QBclosureRec));
 
425
    if (!c)
 
426
        return FSBadAlloc;
 
427
    c->client = client;
 
428
    c->slept = FALSE;
 
429
    c->pfont = cfp->font;
 
430
    c->flags = (all_glyphs) ? LoadAll : 0;
 
431
    c->nranges = nranges;
 
432
    c->range = fixed_range;
 
433
    c->format = format;
 
434
 
 
435
    (void) do_query_bitmaps(client, (pointer) c);
 
436
    return FSSuccess;
 
437
}