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

« back to all changes in this revision

Viewing changes to unix/xc/lib/X11/KeysymStr.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: KeysymStr.c,v 1.5 2001/02/09 02:03:34 xorgcvs Exp $ */
 
2
 
 
3
/*
 
4
 
 
5
Copyright 1990, 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
/* $XFree86: xc/lib/X11/KeysymStr.c,v 3.8 2001/12/14 19:54:02 dawes Exp $ */
 
29
 
 
30
#include "Xlibint.h"
 
31
#include <X11/Xresource.h>
 
32
#include <X11/keysymdef.h>
 
33
 
 
34
#include <stdio.h> /* sprintf */
 
35
 
 
36
typedef unsigned long Signature;
 
37
 
 
38
#define NEEDVTABLE
 
39
#include "ks_tables.h"
 
40
 
 
41
extern XrmDatabase _XInitKeysymDB();
 
42
extern const unsigned char _XkeyTable[];
 
43
 
 
44
 
 
45
typedef struct _GRNData {
 
46
    char *name;
 
47
    XrmRepresentation type;
 
48
    XrmValuePtr value;
 
49
} GRNData;
 
50
 
 
51
#if NeedFunctionPrototypes
 
52
/*ARGSUSED*/
 
53
static Bool SameValue(
 
54
    XrmDatabase*        db,
 
55
    XrmBindingList      bindings,
 
56
    XrmQuarkList        quarks,
 
57
    XrmRepresentation*  type,
 
58
    XrmValuePtr         value,
 
59
    XPointer            data
 
60
)
 
61
#else
 
62
static Bool SameValue(db, bindings, quarks, type, value, data)
 
63
    XrmDatabase         *db;
 
64
    XrmBindingList      bindings;
 
65
    XrmQuarkList        quarks;
 
66
    XrmRepresentation   *type;
 
67
    XrmValuePtr         value;
 
68
    XPointer            data;
 
69
#endif
 
70
{
 
71
    GRNData *gd = (GRNData *)data;
 
72
 
 
73
    if ((*type == gd->type) && (value->size == gd->value->size) &&
 
74
        !strncmp((char *)value->addr, (char *)gd->value->addr, value->size))
 
75
    {
 
76
        gd->name = XrmQuarkToString(*quarks); /* XXX */
 
77
        return True;
 
78
    }
 
79
    return False;
 
80
}
 
81
 
 
82
char *XKeysymToString(ks)
 
83
    KeySym ks;
 
84
{
 
85
    register int i, n;
 
86
    int h;
 
87
    register int idx;
 
88
    const unsigned char *entry;
 
89
    unsigned char val1, val2;
 
90
    XrmDatabase keysymdb;
 
91
 
 
92
    if (!ks || (ks & ((unsigned long) ~0x1fffffff)) != 0)
 
93
        return ((char *)NULL);
 
94
    if (ks == XK_VoidSymbol)
 
95
        ks = 0;
 
96
    if (ks <= 0xffff)
 
97
    {
 
98
        val1 = ks >> 8;
 
99
        val2 = ks & 0xff;
 
100
        i = ks % VTABLESIZE;
 
101
        h = i + 1;
 
102
        n = VMAXHASH;
 
103
        while ((idx = hashKeysym[i]))
 
104
        {
 
105
            entry = &_XkeyTable[idx];
 
106
            if ((entry[0] == val1) && (entry[1] == val2))
 
107
                return ((char *)entry + 2);
 
108
            if (!--n)
 
109
                break;
 
110
            i += h;
 
111
            if (i >= VTABLESIZE)
 
112
                i -= VTABLESIZE;
 
113
        }
 
114
    }
 
115
 
 
116
    if ((keysymdb = _XInitKeysymDB()))
 
117
    {
 
118
        char buf[9];
 
119
        XrmValue resval;
 
120
        XrmQuark empty = NULLQUARK;
 
121
        GRNData data;
 
122
 
 
123
        sprintf(buf, "%lX", ks);
 
124
        resval.addr = (XPointer)buf;
 
125
        resval.size = strlen(buf) + 1;
 
126
        data.name = (char *)NULL;
 
127
        data.type = XrmPermStringToQuark("String");
 
128
        data.value = &resval;
 
129
        (void)XrmEnumerateDatabase(keysymdb, &empty, &empty, XrmEnumAllLevels,
 
130
                                   SameValue, (XPointer)&data);
 
131
        if (data.name)
 
132
            return data.name;
 
133
    }
 
134
    if ((ks & 0xff000000) == 0x01000000){
 
135
        KeySym val = ks & 0xffffff;
 
136
        char *s;
 
137
        int i;
 
138
        if (val & 0xff0000)
 
139
            i = 10;
 
140
        else
 
141
            i = 6;
 
142
        s = Xmalloc(i);
 
143
        if (s == NULL)
 
144
            return s;
 
145
        i--;
 
146
        s[i--] = '\0';
 
147
        for (; i; i--){
 
148
            val1 = val & 0xf;
 
149
            val >>= 4;
 
150
            if (val1 < 10)
 
151
                s[i] = '0'+ val1;
 
152
            else
 
153
                s[i] = 'A'+ val1 - 10;
 
154
        }
 
155
        s[i] = 'U';
 
156
        return s; 
 
157
    }
 
158
    return ((char *) NULL);
 
159
}