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

« back to all changes in this revision

Viewing changes to unix/xc/lib/X11/omDefault.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: omDefault.c,v 1.3 2000/08/17 19:45:21 cpqbld Exp $ */
 
2
/*
 
3
 * Copyright 1992, 1993 by TOSHIBA Corp.
 
4
 *
 
5
 * Permission to use, copy, modify, and distribute this software and its
 
6
 * documentation for any purpose and without fee is hereby granted, provided
 
7
 * that the above copyright notice appear in all copies and that both that
 
8
 * copyright notice and this permission notice appear in supporting
 
9
 * documentation, and that the name of TOSHIBA not be used in advertising
 
10
 * or publicity pertaining to distribution of the software without specific,
 
11
 * written prior permission. TOSHIBA make no representations about the
 
12
 * suitability of this software for any purpose.  It is provided "as is"
 
13
 * without express or implied warranty.
 
14
 *
 
15
 * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
 
16
 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
 
17
 * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
 
18
 * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
 
19
 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
 
20
 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 
21
 * SOFTWARE.
 
22
 *
 
23
 * Author: Katsuhisa Yano       TOSHIBA Corp.
 
24
 *                              mopi@osa.ilab.toshiba.co.jp
 
25
 */
 
26
/*
 
27
 *  (c) Copyright 1995 FUJITSU LIMITED
 
28
 *  This is source code modified by FUJITSU LIMITED under the Joint
 
29
 *  Development Agreement for the CDE/Motif PST.
 
30
 */
 
31
/* $XFree86: xc/lib/X11/omDefault.c,v 1.5 2001/01/17 19:41:56 dawes Exp $ */
 
32
 
 
33
#include "Xlibint.h"
 
34
#include "XomGeneric.h"
 
35
#include <X11/Xos.h>
 
36
#include <X11/Xatom.h>
 
37
#include <stdio.h>
 
38
 
 
39
#define DefineLocalBuf          char local_buf[BUFSIZ]
 
40
#define AllocLocalBuf(length)   (length > BUFSIZ ? (char *)Xmalloc(length) : local_buf)
 
41
#define FreeLocalBuf(ptr)       if (ptr != local_buf) Xfree(ptr)
 
42
 
 
43
static Bool
 
44
wcs_to_mbs(oc, to, from, length)
 
45
    XOC oc;
 
46
    char *to;
 
47
    _Xconst wchar_t *from;
 
48
    int length;
 
49
{
 
50
    XlcConv conv;
 
51
    int to_left, ret;
 
52
 
 
53
    conv = _XomInitConverter(oc, XOMWideChar);
 
54
    if (conv == NULL)
 
55
        return False;
 
56
 
 
57
    to_left = length;
 
58
    ret = _XlcConvert(conv, (XPointer *) &from, &length, (XPointer *) &to,
 
59
                      &to_left, NULL, 0);
 
60
    if (ret != 0 || length > 0)
 
61
        return False;
 
62
 
 
63
    return True;
 
64
}
 
65
 
 
66
static Bool
 
67
utf8_to_mbs(oc, to, from, length)
 
68
    XOC oc;
 
69
    char *to;
 
70
    _Xconst char *from;
 
71
    int length;
 
72
{
 
73
    XlcConv conv;
 
74
    int to_left, ret;
 
75
 
 
76
    conv = _XomInitConverter(oc, XOMUtf8String);
 
77
    if (conv == NULL)
 
78
        return False;
 
79
 
 
80
    to_left = length;
 
81
    ret = _XlcConvert(conv, (XPointer *) &from, &length, (XPointer *) &to,
 
82
                      &to_left, NULL, 0);
 
83
    if (ret != 0 || length > 0)
 
84
        return False;
 
85
 
 
86
    return True;
 
87
}
 
88
 
 
89
int
 
90
#if NeedFunctionPrototypes
 
91
_XmbDefaultTextEscapement(XOC oc, _Xconst char *text, int length)
 
92
#else
 
93
_XmbDefaultTextEscapement(oc, text, length)
 
94
    XOC oc;
 
95
    _Xconst char *text;
 
96
    int length;
 
97
#endif
 
98
{
 
99
    return XTextWidth(*oc->core.font_info.font_struct_list, text, length);
 
100
}
 
101
 
 
102
int
 
103
#if NeedFunctionPrototypes
 
104
_XwcDefaultTextEscapement(XOC oc, _Xconst wchar_t *text, int length)
 
105
#else
 
106
_XwcDefaultTextEscapement(oc, text, length)
 
107
    XOC oc;
 
108
    _Xconst wchar_t *text;
 
109
    int length;
 
110
#endif
 
111
{
 
112
    DefineLocalBuf;
 
113
    char *buf = AllocLocalBuf(length);
 
114
    int ret;
 
115
 
 
116
    if (buf == NULL)
 
117
        return 0;
 
118
 
 
119
    if (wcs_to_mbs(oc, buf, text, length) == False) {
 
120
        ret = 0;
 
121
        goto err;
 
122
    }
 
123
 
 
124
    ret = _XmbDefaultTextEscapement(oc, buf, length);
 
125
 
 
126
err:
 
127
    FreeLocalBuf(buf);
 
128
 
 
129
    return ret;
 
130
}
 
131
 
 
132
int
 
133
#if NeedFunctionPrototypes
 
134
_Xutf8DefaultTextEscapement(XOC oc, _Xconst char *text, int length)
 
135
#else
 
136
_Xutf8DefaultTextEscapement(oc, text, length)
 
137
    XOC oc;
 
138
    _Xconst char *text;
 
139
    int length;
 
140
#endif
 
141
{
 
142
    DefineLocalBuf;
 
143
    char *buf = AllocLocalBuf(length);
 
144
    int ret;
 
145
 
 
146
    if (buf == NULL)
 
147
        return 0;
 
148
 
 
149
    if (utf8_to_mbs(oc, buf, text, length) == False) {
 
150
        ret = 0;
 
151
        goto err;
 
152
    }
 
153
 
 
154
    ret = _XmbDefaultTextEscapement(oc, buf, length);
 
155
 
 
156
err:
 
157
    FreeLocalBuf(buf);
 
158
 
 
159
    return ret;
 
160
}
 
161
 
 
162
int
 
163
#if NeedFunctionPrototypes
 
164
_XmbDefaultTextExtents(XOC oc, _Xconst char *text, int length,
 
165
                       XRectangle *overall_ink, XRectangle *overall_logical)
 
166
#else
 
167
_XmbDefaultTextExtents(oc, text, length, overall_ink, overall_logical)
 
168
    XOC oc;
 
169
    _Xconst char *text;
 
170
    int length;
 
171
    XRectangle *overall_ink;
 
172
    XRectangle *overall_logical;
 
173
#endif
 
174
{
 
175
    int direction, logical_ascent, logical_descent;
 
176
    XCharStruct overall;
 
177
 
 
178
    XTextExtents(*oc->core.font_info.font_struct_list, text, length, &direction,
 
179
                 &logical_ascent, &logical_descent, &overall);
 
180
 
 
181
    if (overall_ink) {
 
182
        overall_ink->x = overall.lbearing;
 
183
        overall_ink->y = -(overall.ascent);
 
184
        overall_ink->width = overall.rbearing - overall.lbearing;
 
185
        overall_ink->height = overall.ascent + overall.descent;
 
186
    }
 
187
 
 
188
    if (overall_logical) {
 
189
        overall_logical->x = 0;
 
190
        overall_logical->y = -(logical_ascent);
 
191
        overall_logical->width = overall.width;
 
192
        overall_logical->height = logical_ascent + logical_descent;
 
193
    }
 
194
 
 
195
    return overall.width;
 
196
}
 
197
 
 
198
int
 
199
#if NeedFunctionPrototypes
 
200
_XwcDefaultTextExtents(XOC oc, _Xconst wchar_t *text, int length,
 
201
                       XRectangle *overall_ink, XRectangle *overall_logical)
 
202
#else
 
203
_XwcDefaultTextExtents(oc, text, length, overall_ink, overall_logical)
 
204
    XOC oc;
 
205
    _Xconst wchar_t *text;
 
206
    int length;
 
207
    XRectangle *overall_ink;
 
208
    XRectangle *overall_logical;
 
209
#endif
 
210
{
 
211
    DefineLocalBuf;
 
212
    char *buf = AllocLocalBuf(length);
 
213
    int ret;
 
214
 
 
215
    if (buf == NULL)
 
216
        return 0;
 
217
 
 
218
    if (wcs_to_mbs(oc, buf, text, length) == False) {
 
219
        ret = 0;
 
220
        goto err;
 
221
    }
 
222
 
 
223
    ret = _XmbDefaultTextExtents(oc, buf, length, overall_ink, overall_logical);
 
224
 
 
225
err:
 
226
    FreeLocalBuf(buf);
 
227
 
 
228
    return ret;
 
229
}
 
230
 
 
231
int
 
232
#if NeedFunctionPrototypes
 
233
_Xutf8DefaultTextExtents(XOC oc, _Xconst char *text, int length,
 
234
                         XRectangle *overall_ink, XRectangle *overall_logical)
 
235
#else
 
236
_Xutf8DefaultTextExtents(oc, text, length, overall_ink, overall_logical)
 
237
    XOC oc;
 
238
    _Xconst char *text;
 
239
    int length;
 
240
    XRectangle *overall_ink;
 
241
    XRectangle *overall_logical;
 
242
#endif
 
243
{
 
244
    DefineLocalBuf;
 
245
    char *buf = AllocLocalBuf(length);
 
246
    int ret;
 
247
 
 
248
    if (buf == NULL)
 
249
        return 0;
 
250
 
 
251
    if (utf8_to_mbs(oc, buf, text, length) == False) {
 
252
        ret = 0;
 
253
        goto err;
 
254
    }
 
255
 
 
256
    ret = _XmbDefaultTextExtents(oc, buf, length, overall_ink, overall_logical);
 
257
 
 
258
err:
 
259
    FreeLocalBuf(buf);
 
260
 
 
261
    return ret;
 
262
}
 
263
 
 
264
Status
 
265
#if NeedFunctionPrototypes
 
266
_XmbDefaultTextPerCharExtents(XOC oc, _Xconst char *text, int length,
 
267
                              XRectangle *ink_buf, XRectangle *logical_buf,
 
268
                              int buf_size, int *num_chars,
 
269
                              XRectangle *overall_ink,
 
270
                              XRectangle *overall_logical)
 
271
#else
 
272
_XmbDefaultTextPerCharExtents(oc, text, length, ink_buf, logical_buf, buf_size,
 
273
                              num_chars, overall_ink, overall_logical)
 
274
    XOC oc;
 
275
    _Xconst char *text; 
 
276
    int length;
 
277
    XRectangle *ink_buf;
 
278
    XRectangle *logical_buf;
 
279
    int buf_size;
 
280
    int *num_chars;
 
281
    XRectangle *overall_ink;
 
282
    XRectangle *overall_logical;
 
283
#endif
 
284
{
 
285
    XFontStruct *font = *oc->core.font_info.font_struct_list;
 
286
    XCharStruct *def, *cs, overall;
 
287
    Bool first = True;
 
288
 
 
289
    if (buf_size < length)
 
290
        return 0;
 
291
 
 
292
    bzero((char *) &overall, sizeof(XCharStruct));
 
293
    *num_chars = 0;
 
294
 
 
295
    CI_GET_DEFAULT_INFO_1D(font, def)
 
296
 
 
297
    while (length-- > 0) {
 
298
        CI_GET_CHAR_INFO_1D(font, *text, def, cs)
 
299
        text++;
 
300
        if (cs == NULL)
 
301
            continue;
 
302
 
 
303
        ink_buf->x = overall.width + cs->lbearing;
 
304
        ink_buf->y = -(cs->ascent);
 
305
        ink_buf->width = cs->rbearing - cs->lbearing;
 
306
        ink_buf->height = cs->ascent + cs->descent;
 
307
        ink_buf++;
 
308
 
 
309
        logical_buf->x = overall.width;
 
310
        logical_buf->y = -(font->ascent);
 
311
        logical_buf->width = cs->width;
 
312
        logical_buf->height = font->ascent + font->descent;
 
313
        logical_buf++;
 
314
 
 
315
        if (first) {
 
316
            overall = *cs;
 
317
            first = False;
 
318
        } else {
 
319
            overall.ascent = max(overall.ascent, cs->ascent);
 
320
            overall.descent = max(overall.descent, cs->descent);
 
321
            overall.lbearing = min(overall.lbearing, overall.width +
 
322
                                   cs->lbearing);
 
323
            overall.rbearing = max(overall.rbearing, overall.width +
 
324
                                   cs->rbearing);
 
325
            overall.width += cs->width;
 
326
        }
 
327
 
 
328
        (*num_chars)++;
 
329
    }
 
330
 
 
331
    if (overall_ink) {
 
332
        overall_ink->x = overall.lbearing;
 
333
        overall_ink->y = -(overall.ascent);
 
334
        overall_ink->width = overall.rbearing - overall.lbearing;
 
335
        overall_ink->height = overall.ascent + overall.descent;
 
336
    }
 
337
 
 
338
    if (overall_logical) {
 
339
        overall_logical->x = 0;
 
340
        overall_logical->y = -(font->ascent);
 
341
        overall_logical->width = overall.width;
 
342
        overall_logical->height = font->ascent + font->descent;
 
343
    }
 
344
 
 
345
    return 1;
 
346
}
 
347
 
 
348
Status
 
349
#if NeedFunctionPrototypes
 
350
_XwcDefaultTextPerCharExtents(XOC oc, _Xconst wchar_t *text, int length,
 
351
                              XRectangle *ink_buf, XRectangle *logical_buf,
 
352
                              int buf_size, int *num_chars,
 
353
                              XRectangle *overall_ink,
 
354
                              XRectangle *overall_logical)
 
355
#else
 
356
_XwcDefaultTextPerCharExtents(oc, text, length, ink_buf, logical_buf, buf_size,
 
357
                              num_chars, overall_ink, overall_logical)
 
358
    XOC oc;
 
359
    _Xconst wchar_t *text;
 
360
    int length;
 
361
    XRectangle *ink_buf;
 
362
    XRectangle *logical_buf;
 
363
    int buf_size;
 
364
    int *num_chars;
 
365
    XRectangle *overall_ink;
 
366
    XRectangle *overall_logical;
 
367
#endif
 
368
{
 
369
    DefineLocalBuf;
 
370
    char *buf = AllocLocalBuf(length);
 
371
    Status ret;
 
372
 
 
373
    if (buf == NULL)
 
374
        return 0;
 
375
 
 
376
    if (wcs_to_mbs(oc, buf, text, length) == False) {
 
377
        ret = 0;
 
378
        goto err;
 
379
    }
 
380
 
 
381
    ret = _XmbDefaultTextPerCharExtents(oc, buf, length, ink_buf, logical_buf,
 
382
                                        buf_size, num_chars, overall_ink,
 
383
                                        overall_logical);
 
384
 
 
385
err:
 
386
    FreeLocalBuf(buf);
 
387
 
 
388
    return ret;
 
389
}
 
390
 
 
391
Status
 
392
#if NeedFunctionPrototypes
 
393
_Xutf8DefaultTextPerCharExtents(XOC oc, _Xconst char *text, int length,
 
394
                                XRectangle *ink_buf, XRectangle *logical_buf,
 
395
                                int buf_size, int *num_chars,
 
396
                                XRectangle *overall_ink,
 
397
                                XRectangle *overall_logical)
 
398
#else
 
399
_Xutf8DefaultTextPerCharExtents(oc, text, length, ink_buf, logical_buf,
 
400
                                buf_size, num_chars, overall_ink,
 
401
                                overall_logical)
 
402
    XOC oc;
 
403
    _Xconst char *text;
 
404
    int length;
 
405
    XRectangle *ink_buf;
 
406
    XRectangle *logical_buf;
 
407
    int buf_size;
 
408
    int *num_chars;
 
409
    XRectangle *overall_ink;
 
410
    XRectangle *overall_logical;
 
411
#endif
 
412
{
 
413
    DefineLocalBuf;
 
414
    char *buf = AllocLocalBuf(length);
 
415
    Status ret;
 
416
 
 
417
    if (buf == NULL)
 
418
        return 0;
 
419
 
 
420
    if (utf8_to_mbs(oc, buf, text, length) == False) {
 
421
        ret = 0;
 
422
        goto err;
 
423
    }
 
424
 
 
425
    ret = _XmbDefaultTextPerCharExtents(oc, buf, length, ink_buf, logical_buf,
 
426
                                        buf_size, num_chars, overall_ink,
 
427
                                        overall_logical);
 
428
 
 
429
err:
 
430
    FreeLocalBuf(buf);
 
431
 
 
432
    return ret;
 
433
}
 
434
 
 
435
int
 
436
#if NeedFunctionPrototypes
 
437
_XmbDefaultDrawString(Display *dpy, Drawable d, XOC oc, GC gc, int x, int y,
 
438
                      _Xconst char *text, int length)
 
439
#else
 
440
_XmbDefaultDrawString(dpy, d, oc, gc, x, y, text, length)
 
441
    Display *dpy;
 
442
    Drawable d;
 
443
    XOC oc;
 
444
    GC gc;
 
445
    int x, y;
 
446
    _Xconst char *text;
 
447
    int length;
 
448
#endif
 
449
{
 
450
    XFontStruct *font = *oc->core.font_info.font_struct_list;
 
451
 
 
452
    XSetFont(dpy, gc, font->fid);
 
453
    XDrawString(dpy, d, gc, x, y, text, length);
 
454
 
 
455
    return XTextWidth(font, text, length);
 
456
}
 
457
 
 
458
int
 
459
#if NeedFunctionPrototypes
 
460
_XwcDefaultDrawString(Display *dpy, Drawable d, XOC oc, GC gc, int x, int y,
 
461
                      _Xconst wchar_t *text, int length)
 
462
#else
 
463
_XwcDefaultDrawString(dpy, d, oc, gc, x, y, text, length)
 
464
    Display *dpy;
 
465
    Drawable d;
 
466
    XOC oc;
 
467
    GC gc;
 
468
    int x, y;
 
469
    _Xconst wchar_t *text;
 
470
    int length;
 
471
#endif
 
472
{
 
473
    DefineLocalBuf;
 
474
    char *buf = AllocLocalBuf(length);
 
475
    int ret;
 
476
 
 
477
    if (buf == NULL)
 
478
        return 0;
 
479
 
 
480
    if (wcs_to_mbs(oc, buf, text, length) == False) {
 
481
        ret = 0;
 
482
        goto err;
 
483
    }
 
484
 
 
485
    ret = _XmbDefaultDrawString(dpy, d, oc, gc, x, y, buf, length);
 
486
 
 
487
err:
 
488
    FreeLocalBuf(buf);
 
489
 
 
490
    return ret;
 
491
}
 
492
 
 
493
int
 
494
#if NeedFunctionPrototypes
 
495
_Xutf8DefaultDrawString(Display *dpy, Drawable d, XOC oc, GC gc, int x, int y,
 
496
                        _Xconst char *text, int length)
 
497
#else
 
498
_Xutf8DefaultDrawString(dpy, d, oc, gc, x, y, text, length)
 
499
    Display *dpy;
 
500
    Drawable d;
 
501
    XOC oc;
 
502
    GC gc;
 
503
    int x, y;
 
504
    _Xconst char *text;
 
505
    int length;
 
506
#endif
 
507
{
 
508
    DefineLocalBuf;
 
509
    char *buf = AllocLocalBuf(length);
 
510
    int ret;
 
511
 
 
512
    if (buf == NULL)
 
513
        return 0;
 
514
 
 
515
    if (utf8_to_mbs(oc, buf, text, length) == False) {
 
516
        ret = 0;
 
517
        goto err;
 
518
    }
 
519
 
 
520
    ret = _XmbDefaultDrawString(dpy, d, oc, gc, x, y, buf, length);
 
521
 
 
522
err:
 
523
    FreeLocalBuf(buf);
 
524
 
 
525
    return ret;
 
526
}
 
527
 
 
528
void
 
529
#if NeedFunctionPrototypes
 
530
_XmbDefaultDrawImageString(Display *dpy, Drawable d, XOC oc, GC gc, int x,
 
531
                           int y, _Xconst char *text, int length)
 
532
#else
 
533
_XmbDefaultDrawImageString(dpy, d, oc, gc, x, y, text, length)
 
534
    Display *dpy;
 
535
    Drawable d;
 
536
    XOC oc;
 
537
    GC gc;
 
538
    int x, y;
 
539
    _Xconst char *text;
 
540
    int length;
 
541
#endif
 
542
{
 
543
    XSetFont(dpy, gc, (*oc->core.font_info.font_struct_list)->fid);
 
544
    XDrawImageString(dpy, d, gc, x, y, text, length);
 
545
}
 
546
 
 
547
void
 
548
#if NeedFunctionPrototypes
 
549
_XwcDefaultDrawImageString(Display *dpy, Drawable d, XOC oc, GC gc, int x,
 
550
                           int y, _Xconst wchar_t *text, int length)
 
551
#else
 
552
_XwcDefaultDrawImageString(dpy, d, oc, gc, x, y, text, length)
 
553
    Display *dpy;
 
554
    Drawable d;
 
555
    XOC oc;
 
556
    GC gc;
 
557
    int x, y;
 
558
    _Xconst wchar_t *text;
 
559
    int length;
 
560
#endif
 
561
{
 
562
    DefineLocalBuf;
 
563
    char *buf = AllocLocalBuf(length);
 
564
 
 
565
    if (buf == NULL)
 
566
        return;
 
567
 
 
568
    if (wcs_to_mbs(oc, buf, text, length) == False)
 
569
        goto err;
 
570
 
 
571
    _XmbDefaultDrawImageString(dpy, d, oc, gc, x, y, buf, length);
 
572
 
 
573
err:
 
574
    FreeLocalBuf(buf);
 
575
}
 
576
 
 
577
void
 
578
#if NeedFunctionPrototypes
 
579
_Xutf8DefaultDrawImageString(Display *dpy, Drawable d, XOC oc, GC gc, int x,
 
580
                             int y, _Xconst char *text, int length)
 
581
#else
 
582
_Xutf8DefaultDrawImageString(dpy, d, oc, gc, x, y, text, length)
 
583
    Display *dpy;
 
584
    Drawable d;
 
585
    XOC oc;
 
586
    GC gc;
 
587
    int x, y;
 
588
    _Xconst char *text;
 
589
    int length;
 
590
#endif
 
591
{
 
592
    DefineLocalBuf;
 
593
    char *buf = AllocLocalBuf(length);
 
594
 
 
595
    if (buf == NULL)
 
596
        return;
 
597
 
 
598
    if (utf8_to_mbs(oc, buf, text, length) == False)
 
599
        goto err;
 
600
 
 
601
    _XmbDefaultDrawImageString(dpy, d, oc, gc, x, y, buf, length);
 
602
 
 
603
err:
 
604
    FreeLocalBuf(buf);
 
605
}