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

« back to all changes in this revision

Viewing changes to unix/xc/lib/Xmu/StrToCurs.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: StrToCurs.c,v 1.4 2001/02/09 02:03:53 xorgcvs Exp $ */
 
2
 
 
3
/*
 
4
 
 
5
Copyright 1987, 1988, 1998  The Open Group
 
6
 
 
7
Permission to use, copy, modify, distribute, and sell this software and its
 
8
documentation for any purpose is hereby granted without fee, provided that
 
9
the above copyright notice appear in all copies and that both that
 
10
copyright notice and this permission notice appear in supporting
 
11
documentation.
 
12
 
 
13
The above copyright notice and this permission notice shall be included in
 
14
all copies or substantial portions of the Software.
 
15
 
 
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
 
19
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 
20
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
21
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
22
 
 
23
Except as contained in this notice, the name of The Open Group shall not be
 
24
used in advertising or otherwise to promote the sale, use or other dealings
 
25
in this Software without prior written authorization from The Open Group.
 
26
 
 
27
*/
 
28
 
 
29
/***********************************************************
 
30
 
 
31
Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
 
32
 
 
33
                        All Rights Reserved
 
34
 
 
35
Permission to use, copy, modify, and distribute this software and its 
 
36
documentation for any purpose and without fee is hereby granted, 
 
37
provided that the above copyright notice appear in all copies and that
 
38
both that copyright notice and this permission notice appear in 
 
39
supporting documentation, and that the name of Digital not be
 
40
used in advertising or publicity pertaining to distribution of the
 
41
software without specific, written prior permission.  
 
42
 
 
43
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
 
44
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
 
45
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
 
46
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
 
47
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
 
48
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 
49
SOFTWARE.
 
50
 
 
51
******************************************************************/
 
52
 
 
53
/* $XFree86: xc/lib/Xmu/StrToCurs.c,v 1.12 2002/09/24 18:55:21 alanh Exp $ */
 
54
 
 
55
#include        <X11/Intrinsic.h>
 
56
#include        <X11/StringDefs.h>
 
57
#include        <X11/Xmu/Converters.h>
 
58
#include        <X11/Xmu/Drawing.h>
 
59
#include        <X11/Xmu/CurUtil.h>
 
60
#include        <X11/Xmu/CharSet.h>
 
61
 
 
62
#ifndef X_NOT_POSIX
 
63
#include <stdlib.h>
 
64
#ifdef _POSIX_SOURCE
 
65
#include <limits.h>
 
66
#else
 
67
#define _POSIX_SOURCE
 
68
#include <limits.h>
 
69
#undef _POSIX_SOURCE
 
70
#endif
 
71
#endif /* X_NOT_POSIX */
 
72
#ifndef PATH_MAX
 
73
#ifdef WIN32
 
74
#define PATH_MAX 512
 
75
#else
 
76
#include <sys/param.h>
 
77
#endif
 
78
#ifndef PATH_MAX
 
79
#ifdef MAXPATHLEN
 
80
#define PATH_MAX MAXPATHLEN
 
81
#else
 
82
#define PATH_MAX 1024
 
83
#endif
 
84
#endif
 
85
#endif /* PATH_MAX */
 
86
 
 
87
/* Kludge source to avoid encountering broken shared library linkers
 
88
   which insist on resolving references unused by the application,
 
89
   and broken object file formats that don't correctly distinguish
 
90
   references to procedures from references to data.
 
91
 */
 
92
#if defined(SUNSHLIB) || defined(SVR4)
 
93
#define XMU_KLUDGE
 
94
#endif
 
95
 
 
96
/*
 
97
 * XmuConvertStringToCursor:
 
98
 *
 
99
 * allows String to specify a standard cursor name (from cursorfont.h), a
 
100
 * font name and glyph index of the form "FONT fontname index [[font] index]", 
 
101
 * or a bitmap file name (absolute, or relative to the global resource
 
102
 * bitmapFilePath, class BitmapFilePath).  If the resource is not
 
103
 * defined, the default value is the build symbol BITMAPDIR.
 
104
 *
 
105
 * shares lots of code with XmuCvtStringToPixmap, but unfortunately
 
106
 * can't use it as the hotspot info is lost.
 
107
 *
 
108
 * To use, include the following in your ClassInitialize procedure:
 
109
 
 
110
static XtConvertArgRec screenConvertArg[] = {
 
111
    {XtBaseOffset, (XtPointer) XtOffsetOf(WidgetRec, core.screen),
 
112
     sizeof(Screen *)}
 
113
};
 
114
 
 
115
    XtAddConverter(XtRString, XtRCursor, XmuCvtStringToCursor,      
 
116
                   screenConvertArg, XtNumber(screenConvertArg));
 
117
 *
 
118
 */
 
119
 
 
120
#define done(address, type) \
 
121
        { (*toVal).size = sizeof(type); (*toVal).addr = (XPointer) address; }
 
122
 
 
123
#define FONTSPECIFIER           "FONT "
 
124
 
 
125
/*ARGSUSED*/
 
126
void
 
127
XmuCvtStringToCursor(XrmValuePtr args, Cardinal *num_args,
 
128
                     XrmValuePtr fromVal, XrmValuePtr toVal)
 
129
{
 
130
    static Cursor cursor;               /* static for cvt magic */
 
131
    char *name = (char *)fromVal->addr;
 
132
    Screen *screen;
 
133
    register int i;
 
134
    char maskname[PATH_MAX];
 
135
    Pixmap source, mask = 0;
 
136
    /* XXX - make fg/bg resources */
 
137
    static XColor bgColor = {0, 0xffff, 0xffff, 0xffff};
 
138
    static XColor fgColor = {0, 0, 0, 0};
 
139
    int xhot, yhot;
 
140
    int len;
 
141
 
 
142
 
 
143
    if (*num_args != 1)
 
144
     XtErrorMsg("wrongParameters","cvtStringToCursor","XtToolkitError",
 
145
             "String to cursor conversion needs screen argument",
 
146
              (String *)NULL, (Cardinal *)NULL);
 
147
 
 
148
    if (XmuCompareISOLatin1(name, "None") == 0)
 
149
      {
 
150
        cursor = None;
 
151
        done(&cursor, Cursor);
 
152
        return;
 
153
      }
 
154
 
 
155
    screen = *((Screen **) args[0].addr);
 
156
 
 
157
    if (0 == strncmp(FONTSPECIFIER, name, strlen(FONTSPECIFIER))) {
 
158
        char source_name[PATH_MAX], mask_name[PATH_MAX];
 
159
        int source_char, mask_char, fields;
 
160
        Font source_font, mask_font;
 
161
        XrmValue fromString, toFont;
 
162
        XrmValue cvtArg;
 
163
        Boolean success;
 
164
        Display *dpy = DisplayOfScreen(screen);
 
165
        char *strspec = NULL;
 
166
#ifdef XMU_KLUDGE
 
167
        Cardinal num;
 
168
#endif
 
169
 
 
170
        strspec = XtMalloc(strlen("FONT %s %d %s %d") + 21);
 
171
        sprintf(strspec, "FONT %%%lds %%d %%%lds %%d",
 
172
                (unsigned long)sizeof(source_name) - 1,
 
173
                (unsigned long)sizeof(mask_name) - 1);
 
174
        fields = sscanf(name, strspec,
 
175
                        source_name, &source_char,
 
176
                        mask_name, &mask_char);
 
177
        XtFree(strspec);
 
178
        if (fields < 2) {
 
179
            XtStringConversionWarning(name, XtRCursor);
 
180
            return;
 
181
        }
 
182
 
 
183
        fromString.addr = source_name;
 
184
        fromString.size = strlen(source_name) + 1;
 
185
        toFont.addr = (XPointer) &source_font;
 
186
        toFont.size = sizeof(Font);
 
187
        cvtArg.addr = (XPointer) &dpy;
 
188
        cvtArg.size = sizeof(Display *);
 
189
        /* XXX using display of screen argument as message display */
 
190
#ifdef XMU_KLUDGE
 
191
        /* XXX Sacrifice caching */
 
192
        num = 1;
 
193
        success = XtCvtStringToFont(dpy, &cvtArg, &num, &fromString, &toFont,
 
194
                                    NULL);
 
195
#else
 
196
        success = XtCallConverter(dpy, XtCvtStringToFont, &cvtArg,
 
197
                                  (Cardinal)1, &fromString, &toFont, NULL);
 
198
#endif
 
199
        if (!success) {
 
200
            XtStringConversionWarning(name, XtRCursor);
 
201
            return;
 
202
        }
 
203
 
 
204
        switch (fields) {
 
205
          case 2:               /* defaulted mask font & char */
 
206
            mask_font = source_font;
 
207
            mask_char = source_char;
 
208
            break;
 
209
 
 
210
          case 3:               /* defaulted mask font */
 
211
            mask_font = source_font;
 
212
            mask_char = atoi(mask_name);
 
213
            break;
 
214
 
 
215
          case 4:               /* specified mask font & char */
 
216
            fromString.addr = mask_name;
 
217
            fromString.size = strlen(mask_name) + 1;
 
218
            toFont.addr = (XPointer) &mask_font;
 
219
            toFont.size = sizeof(Font);
 
220
            /* XXX using display of screen argument as message display */
 
221
#ifdef XMU_KLUDGE
 
222
            /* XXX Sacrifice caching */
 
223
            num = 1;
 
224
            success = XtCvtStringToFont(dpy, &cvtArg, &num, &fromString,
 
225
                                        &toFont, NULL);
 
226
#else
 
227
            success = XtCallConverter(dpy, XtCvtStringToFont, &cvtArg,
 
228
                                      (Cardinal)1, &fromString, &toFont, NULL);
 
229
#endif
 
230
            if (!success) {
 
231
                XtStringConversionWarning(name, XtRCursor);
 
232
                return;
 
233
            }
 
234
        }
 
235
 
 
236
        cursor = XCreateGlyphCursor( DisplayOfScreen(screen), source_font,
 
237
                                     mask_font, source_char, mask_char,
 
238
                                     &fgColor, &bgColor );
 
239
        done(&cursor, Cursor);
 
240
        return;
 
241
    }
 
242
 
 
243
    i = XmuCursorNameToIndex (name);
 
244
    if (i != -1) {
 
245
        cursor = XCreateFontCursor (DisplayOfScreen(screen), i);
 
246
        done(&cursor, Cursor);
 
247
        return;
 
248
    }
 
249
 
 
250
    if ((source = XmuLocateBitmapFile (screen, name, 
 
251
                                       maskname, (sizeof maskname) - 4,
 
252
                                       NULL, NULL, &xhot, &yhot)) == None) {
 
253
        XtStringConversionWarning (name, XtRCursor);
 
254
        cursor = None;
 
255
        done(&cursor, Cursor);
 
256
        return;
 
257
    }
 
258
    len = strlen (maskname);
 
259
    for (i = 0; i < 2; i++) {
 
260
        strcpy (maskname + len, i == 0 ? "Mask" : "msk");
 
261
        if ((mask = XmuLocateBitmapFile (screen, maskname, NULL, 0, 
 
262
                                         NULL, NULL, NULL, NULL)) != None)
 
263
          break;
 
264
    }
 
265
 
 
266
    cursor = XCreatePixmapCursor( DisplayOfScreen(screen), source, mask,
 
267
                                  &fgColor, &bgColor, xhot, yhot );
 
268
    XFreePixmap( DisplayOfScreen(screen), source );
 
269
    if (mask != None) XFreePixmap( DisplayOfScreen(screen), mask );
 
270
 
 
271
    done(&cursor, Cursor);
 
272
}
 
273
 
 
274
#define new_done(type, value) \
 
275
        {                                                       \
 
276
            if (toVal->addr != NULL) {                          \
 
277
                if (toVal->size < sizeof(type)) {               \
 
278
                    toVal->size = sizeof(type);                 \
 
279
                    return False;                               \
 
280
                }                                               \
 
281
                *(type*)(toVal->addr) = (value);                \
 
282
            }                                                   \
 
283
            else {                                              \
 
284
                static type static_val;                         \
 
285
                static_val = (value);                           \
 
286
                toVal->addr = (XPointer)&static_val;            \
 
287
            }                                                   \
 
288
            toVal->size = sizeof(type);                         \
 
289
            return True;                                        \
 
290
        }
 
291
 
 
292
/*      Function Name: XmuCvtStringToColorCursor
 
293
 *      Description: Converts a string into a colored cursor.
 
294
 *      Arguments: dpy
 
295
 *                 args - an argument list (see below).
 
296
 *                 num_args - number of elements in the argument list.
 
297
 *                 fromVal - value to convert from.
 
298
 *                 toVal - value to convert to.
 
299
 *                 data
 
300
 *      Returns:   True or False
 
301
 */
 
302
 
 
303
/*ARGSUSED*/
 
304
Boolean
 
305
XmuCvtStringToColorCursor(Display *dpy, XrmValuePtr args, Cardinal *num_args,
 
306
                          XrmValuePtr fromVal, XrmValuePtr toVal,
 
307
                          XtPointer *converter_data)
 
308
{
 
309
    Cursor cursor;
 
310
    Screen *screen;
 
311
    Pixel fg, bg;
 
312
    Colormap c_map;
 
313
    XColor colors[2];
 
314
    Cardinal number;
 
315
    XrmValue ret_val;
 
316
 
 
317
    if (*num_args != 4) {
 
318
        XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
 
319
            "wrongParameters","cvtStringToColorCursor","XmuError",
 
320
            "String to color cursor conversion needs four arguments",
 
321
            (String *)NULL, (Cardinal *)NULL);
 
322
        return False;
 
323
    }
 
324
 
 
325
    screen = *((Screen **) args[0].addr);
 
326
    fg = *((Pixel *) args[1].addr);
 
327
    bg = *((Pixel *) args[2].addr);
 
328
    c_map = *((Colormap *) args[3].addr);
 
329
 
 
330
    number = 1;
 
331
    XmuCvtStringToCursor(args, &number, fromVal, &ret_val);
 
332
    
 
333
    cursor = *((Cursor *) ret_val.addr);
 
334
 
 
335
    if (cursor == None || (fg == BlackPixelOfScreen(screen)
 
336
                           && bg == WhitePixelOfScreen(screen)))
 
337
        new_done(Cursor, cursor);
 
338
 
 
339
    colors[0].pixel = fg;
 
340
    colors[1].pixel = bg;
 
341
 
 
342
    XQueryColors (dpy, c_map, colors, 2);
 
343
    XRecolorCursor(dpy, cursor, colors, colors + 1);
 
344
    new_done(Cursor, cursor);
 
345
}
 
346
 
 
347
    
 
348