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

« back to all changes in this revision

Viewing changes to unix/xc/lib/X11/omTextEsc.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: omTextEsc.c,v 1.3 2000/08/17 19:45:22 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
/* $XFree86: xc/lib/X11/omTextEsc.c,v 1.5 2001/01/17 19:41:56 dawes Exp $ */
 
27
/*
 
28
 * Copyright 1995 by FUJITSU LIMITED
 
29
 * This is source code modified by FUJITSU LIMITED under the Joint
 
30
 * Development Agreement for the CDE/Motif PST.
 
31
 */
 
32
 
 
33
#include "Xlibint.h"
 
34
#include "XomGeneric.h"
 
35
#include <stdio.h>
 
36
 
 
37
/* For VW/UDC start */
 
38
 
 
39
#define VMAP            0
 
40
#define VROTATE         1
 
41
#define FONTSCOPE       2
 
42
 
 
43
static int
 
44
is_rotate(oc, font)
 
45
    XOC         oc;
 
46
    XFontStruct *font;
 
47
{
 
48
    XOCGenericPart      *gen = XOC_GENERIC(oc);
 
49
    FontSet             font_set;
 
50
    VRotate             vrotate;
 
51
    int                 font_set_count;
 
52
    int                 vrotate_num;
 
53
 
 
54
    font_set = gen->font_set;
 
55
    font_set_count = gen->font_set_num;
 
56
    for( ; font_set_count-- ; font_set++) {
 
57
        if((font_set->vrotate_num > 0) && (font_set->vrotate != NULL)) {
 
58
            vrotate = font_set->vrotate;
 
59
            vrotate_num = font_set->vrotate_num;
 
60
            for( ; vrotate_num-- ; vrotate++)
 
61
                if(vrotate->font == font)
 
62
                    return True;
 
63
        }
 
64
    }
 
65
    return False;
 
66
}
 
67
 
 
68
static int
 
69
is_codemap(oc, font)
 
70
    XOC         oc;
 
71
    XFontStruct *font;
 
72
{
 
73
    XOCGenericPart      *gen = XOC_GENERIC(oc);
 
74
    FontSet             font_set;
 
75
    FontData            vmap;
 
76
    int                 font_set_count;
 
77
    int                 vmap_num;
 
78
 
 
79
    font_set = gen->font_set;
 
80
    font_set_count = gen->font_set_num;
 
81
    for( ; font_set_count-- ; font_set++) {
 
82
        if(font_set->vmap_num > 0) {
 
83
            vmap = font_set->vmap;
 
84
            vmap_num = font_set->vmap_num;
 
85
            for( ; vmap_num-- ; vmap++)
 
86
                if(vmap->font == font)
 
87
                    return True;
 
88
        }
 
89
    }
 
90
    return False;
 
91
}
 
92
 
 
93
static int
 
94
escapement_vertical(oc, font, is_xchar2b, text, length)
 
95
    XOC         oc;
 
96
    XFontStruct *font;
 
97
    Bool        is_xchar2b;
 
98
    XPointer    text;
 
99
    int         length;
 
100
{
 
101
    XChar2b     *buf2b;
 
102
    char        *buf;
 
103
    int         escapement = 0, i;
 
104
 
 
105
    if(is_xchar2b) {
 
106
        for(i = 0, buf2b = (XChar2b *) text ; i < length ; i++, buf2b++) {
 
107
            if(is_rotate(oc, font) == True) {
 
108
                escapement += _XTextHeight16(font, buf2b, 1);
 
109
            } else {
 
110
                escapement += (int) (font->max_bounds.ascent +
 
111
                                     font->max_bounds.descent);
 
112
            }
 
113
        }
 
114
    } else {
 
115
        for(i = 0, buf = (char *)text ; i < length && *buf ; i++, buf++) {
 
116
            if(is_rotate(oc, font) == True) {
 
117
                escapement += _XTextHeight(font, buf, 1);
 
118
            } else {
 
119
                escapement += (int) (font->max_bounds.ascent +
 
120
                                     font->max_bounds.descent);
 
121
            }
 
122
        }
 
123
    }
 
124
    return escapement;
 
125
}
 
126
 
 
127
 
 
128
extern FontData _XomGetFontDataFromFontSet();
 
129
 
 
130
static int
 
131
TextWidthWithFontSet(font_set, oc, text, length)
 
132
    FontSet     font_set;
 
133
    XOC         oc;
 
134
    XPointer    text;
 
135
    int         length;
 
136
{
 
137
    FontData            fd;
 
138
    XFontStruct         *font;
 
139
    unsigned char       *ptr = (unsigned char *)text;
 
140
    Bool                is_xchar2b;
 
141
    int                 ptr_len = length;
 
142
    int                 escapement = 0, char_len = 0;
 
143
 
 
144
    if(font_set == (FontSet) NULL)
 
145
        return escapement;
 
146
 
 
147
    is_xchar2b = font_set->is_xchar2b;
 
148
 
 
149
    while(length > 0) {
 
150
        fd = _XomGetFontDataFromFontSet(font_set, ptr, length, &ptr_len,
 
151
                                               is_xchar2b, FONTSCOPE);
 
152
        if(ptr_len <= 0)
 
153
            break;
 
154
 
 
155
        /*
 
156
         * First, see if the "Best Match" font for the FontSet was set.
 
157
         * If it was, use that font.  If it was not set, then use the
 
158
         * font defined by font_set->font_data[0] (which is what
 
159
         * _XomGetFontDataFromFontSet() always seems to return for
 
160
         * non-VW text).  Note that given the new algorithm in
 
161
         * parse_fontname() and parse_fontdata(), fs->font will
 
162
         * *always* contain good data.   We should probably remove
 
163
         * the check for "fd->font", but we won't :-) -- jjw/pma (HP)
 
164
         *
 
165
         * Above comment and way this is done propagated from omText.c
 
166
         * Note that fd->font is junk so using the result of the
 
167
         * above call /needs/ to be ignored.
 
168
         *
 
169
         * Owen Taylor <otaylor@redhat.com>     12 Jul 2000
 
170
         *
 
171
         */
 
172
 
 
173
        if(fd == (FontData) NULL ||
 
174
           (font = font_set->font) == (XFontStruct *) NULL) {
 
175
 
 
176
            if((font = fd->font) == (XFontStruct *) NULL)
 
177
                break;
 
178
        }
 
179
 
 
180
        switch(oc->core.orientation) {
 
181
          case XOMOrientation_LTR_TTB:
 
182
          case XOMOrientation_RTL_TTB:
 
183
            if (is_xchar2b) {
 
184
                char_len = ptr_len / sizeof(XChar2b);
 
185
                escapement += XTextWidth16(font, (XChar2b *)ptr, char_len);
 
186
            } else {
 
187
                char_len = ptr_len;
 
188
                escapement += XTextWidth(font, (char *)ptr, char_len);
 
189
            }
 
190
            break;
 
191
 
 
192
          case XOMOrientation_TTB_LTR:
 
193
          case XOMOrientation_TTB_RTL:
 
194
            if(font_set->font == font) {
 
195
                fd = _XomGetFontDataFromFontSet(font_set, ptr, length, &ptr_len,
 
196
                                                is_xchar2b, VMAP);
 
197
                if(ptr_len <= 0)
 
198
                    break;
 
199
                if(fd == (FontData) NULL ||
 
200
                   (font = fd->font) == (XFontStruct *) NULL)
 
201
                    break;
 
202
 
 
203
                if(is_codemap(oc, fd->font) == False) {
 
204
                    fd = _XomGetFontDataFromFontSet(font_set, ptr, length,
 
205
                                                    &ptr_len, is_xchar2b,
 
206
                                                    VROTATE);
 
207
                    if(ptr_len <= 0)
 
208
                        break;
 
209
                    if(fd == (FontData) NULL ||
 
210
                       (font = fd->font) == (XFontStruct *) NULL)
 
211
                        break;
 
212
                }
 
213
            }
 
214
 
 
215
            if(is_xchar2b)
 
216
                char_len = ptr_len / sizeof(XChar2b);
 
217
            else
 
218
                char_len = ptr_len;
 
219
            escapement += escapement_vertical(oc, font, is_xchar2b,
 
220
                                              (XPointer) ptr, char_len);
 
221
            break;
 
222
 
 
223
          case XOMOrientation_Context:
 
224
            /* not used? */
 
225
            break;
 
226
        }
 
227
 
 
228
        if(char_len <= 0)
 
229
            break;
 
230
 
 
231
        length -= char_len;
 
232
        ptr += ptr_len;
 
233
    }
 
234
 
 
235
    return escapement;
 
236
}
 
237
 
 
238
/* For VW/UDC end */
 
239
 
 
240
static int
 
241
_XomGenericTextEscapement(oc, type, text, length)
 
242
    XOC oc;
 
243
    XOMTextType type;
 
244
    XPointer text;
 
245
    int length;
 
246
{
 
247
    XlcConv conv;
 
248
    XFontStruct *font;
 
249
    Bool is_xchar2b;
 
250
/* VW/UDC */
 
251
    XPointer args[3];
 
252
    FontSet font_set;
 
253
/* VW/UDC */
 
254
    XChar2b xchar2b_buf[BUFSIZ], *buf;
 
255
    int escapement = 0;
 
256
    int buf_len = 0, left = 0;
 
257
 
 
258
    conv = _XomInitConverter(oc, type);
 
259
    if (conv == NULL)
 
260
        return escapement;
 
261
    
 
262
    args[0] = (XPointer) &font;
 
263
    args[1] = (XPointer) &is_xchar2b;
 
264
    args[2] = (XPointer) &font_set;
 
265
 
 
266
    while (length > 0) {
 
267
        buf = xchar2b_buf;
 
268
        left = buf_len = BUFSIZ;
 
269
 
 
270
        if (_XomConvert(oc, conv, (XPointer *) &text, &length,
 
271
                        (XPointer *) &buf, &left, args, 3) < 0)
 
272
            break;
 
273
        buf_len -= left;
 
274
 
 
275
/* VW/UDC */
 
276
        escapement += TextWidthWithFontSet(font_set, oc,
 
277
                                           (XPointer) xchar2b_buf, buf_len);
 
278
/* VW/UDC */
 
279
    }
 
280
 
 
281
    return escapement;
 
282
}
 
283
 
 
284
int
 
285
#if NeedFunctionPrototypes
 
286
_XmbGenericTextEscapement(XOC oc, _Xconst char *text, int length)
 
287
#else
 
288
_XmbGenericTextEscapement(oc, text, length)
 
289
    XOC oc;
 
290
    _Xconst char *text;
 
291
    int length;
 
292
#endif
 
293
{
 
294
    return _XomGenericTextEscapement(oc, XOMMultiByte, (XPointer) text, length);
 
295
}
 
296
 
 
297
int
 
298
#if NeedFunctionPrototypes
 
299
_XwcGenericTextEscapement(XOC oc, _Xconst wchar_t *text, int length)
 
300
#else
 
301
_XwcGenericTextEscapement(oc, text, length)
 
302
    XOC oc;
 
303
    _Xconst wchar_t *text;
 
304
    int length;
 
305
#endif
 
306
{
 
307
    return _XomGenericTextEscapement(oc, XOMWideChar, (XPointer) text, length);
 
308
}
 
309
 
 
310
int
 
311
#if NeedFunctionPrototypes
 
312
_Xutf8GenericTextEscapement(XOC oc, _Xconst char *text, int length)
 
313
#else
 
314
_Xutf8GenericTextEscapement(oc, text, length)
 
315
    XOC oc;
 
316
    _Xconst char *text;
 
317
    int length;
 
318
#endif
 
319
{
 
320
    return _XomGenericTextEscapement(oc, XOMUtf8String, (XPointer) text,
 
321
                                     length);
 
322
}