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

« back to all changes in this revision

Viewing changes to unix/xc/lib/X11/imTransR.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: imTransR.c,v 1.4 2000/08/17 19:45:16 cpqbld Exp $ */
 
2
/******************************************************************
 
3
 
 
4
              Copyright 1992 by Sun Microsystems, Inc.
 
5
              Copyright 1992, 1993, 1994 by FUJITSU LIMITED
 
6
 
 
7
Permission to use, copy, modify, distribute, and sell this software
 
8
and its documentation for any purpose is hereby granted without fee,
 
9
provided that the above copyright notice appear in all copies and
 
10
that both that copyright notice and this permission notice appear
 
11
in supporting documentation, and that the name of Sun Microsystems, Inc.
 
12
and FUJITSU LIMITED not be used in advertising or publicity pertaining to
 
13
distribution of the software without specific, written prior permission.
 
14
Sun Microsystems, Inc. and FUJITSU LIMITED makes no representations about
 
15
the suitability of this software for any purpose.
 
16
It is provided "as is" without express or implied warranty.
 
17
 
 
18
Sun Microsystems Inc. AND FUJITSU LIMITED DISCLAIMS ALL WARRANTIES WITH
 
19
REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
 
20
AND FITNESS, IN NO EVENT SHALL Sun Microsystems, Inc. AND FUJITSU LIMITED
 
21
BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 
22
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 
23
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
 
24
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
25
 
 
26
  Author: Hideki Hiura (hhiura@Sun.COM) Sun Microsystems, Inc.
 
27
          Takashi Fujiwara     FUJITSU LIMITED 
 
28
                               fujiwara@a80.tech.yk.fujitsu.co.jp
 
29
 
 
30
******************************************************************/
 
31
/* $XFree86: xc/lib/X11/imTransR.c,v 3.4 2001/01/17 19:41:52 dawes Exp $ */
 
32
 
 
33
#include "Xlibint.h"
 
34
#include "Xlcint.h"
 
35
#include "XimTrInt.h"
 
36
#include "Ximint.h"
 
37
 
 
38
Public TransportSW _XimTransportRec[] = {
 
39
    { "X",          _XimXConf },  /* 1st entry must be X. 
 
40
                                        This will be a fallback */
 
41
#ifdef TCPCONN
 
42
    { "tcp",        _XimTransConf }, /* use X transport lib */
 
43
#endif /* TCPCONN */
 
44
#if defined(UNIXCONN) || defined(LOCALCONN)
 
45
    { "local",      _XimTransConf }, /* use X transport lib */
 
46
#endif /* UNIXCONN */
 
47
#ifdef DNETCONN
 
48
    { "dnet",     _XimTransConf }, /* use X transport lib */
 
49
#endif /* DNETCONN */
 
50
#ifdef STREAMSCONN
 
51
    { "streams",    _XimTransConf }, /* use X transport lib */
 
52
#endif /* STREAMSCONN */
 
53
    { (char *)NULL, (Bool (*)())NULL },
 
54
};
 
55
 
 
56
Public Bool
 
57
_XimConnect(im)
 
58
    Xim          im;
 
59
{
 
60
    return im->private.proto.connect(im);
 
61
}
 
62
 
 
63
Public Bool
 
64
_XimShutdown(im)
 
65
    Xim          im;
 
66
{
 
67
    return im->private.proto.shutdown(im);
 
68
}
 
69
 
 
70
Public Bool
 
71
#if NeedFunctionPrototypes
 
72
_XimWrite(Xim im, INT16 len, XPointer data)
 
73
#else
 
74
_XimWrite(im, len, data)
 
75
    Xim          im;
 
76
    INT16        len;
 
77
    XPointer     data;
 
78
#endif
 
79
{
 
80
    return im->private.proto.write(im, len, data);
 
81
}
 
82
 
 
83
Private int
 
84
_CheckProtocolData(im, recv_buf)
 
85
    Xim           im;
 
86
    char         *recv_buf;
 
87
{
 
88
    int          data_len;
 
89
 
 
90
    data_len = (int)(((*((CARD16 *)recv_buf + 1)) * 4) + XIM_HEADER_SIZE);
 
91
    return data_len;
 
92
}
 
93
 
 
94
Private int
 
95
_XimReadData(im, len, buf, buf_size)
 
96
    Xim          im;
 
97
    INT16       *len;
 
98
    XPointer     buf;
 
99
    int          buf_size;
 
100
{
 
101
    char        *hold_buf;
 
102
    char        *tmp;
 
103
    int          data_len;
 
104
    int          packet_size;
 
105
    int          ret_len;
 
106
    register int i;
 
107
 
 
108
    if (buf_size < XIM_HEADER_SIZE) {
 
109
        *len = (INT16)XIM_HEADER_SIZE;
 
110
        return XIM_OVERFLOW;
 
111
    }
 
112
 
 
113
    bzero(buf, buf_size);
 
114
    packet_size = 0;
 
115
    data_len = 0;
 
116
 
 
117
    if ((hold_buf = im->private.proto.hold_data)) {
 
118
        data_len = im->private.proto.hold_data_len;
 
119
        if (data_len >= XIM_HEADER_SIZE) {
 
120
            packet_size = _CheckProtocolData(im, hold_buf);
 
121
            if (packet_size > buf_size) {
 
122
                *len = (INT16)packet_size;
 
123
                return XIM_OVERFLOW;
 
124
            }
 
125
            if (packet_size <= data_len) {
 
126
                memcpy(buf, hold_buf, packet_size);
 
127
                for (i = packet_size; i < data_len; i++) {
 
128
                    if (hold_buf[i])
 
129
                        break;
 
130
                }
 
131
                data_len -= i;
 
132
 
 
133
                if (data_len) {
 
134
                    if (!(tmp = (char *)Xmalloc(data_len))) {
 
135
                        return XIM_FALSE;
 
136
                    }
 
137
                    memcpy(tmp, &hold_buf[i], data_len);
 
138
                    im->private.proto.hold_data = tmp;
 
139
                    im->private.proto.hold_data_len = data_len;
 
140
                } else {
 
141
                    im->private.proto.hold_data = 0;
 
142
                    im->private.proto.hold_data_len = 0;
 
143
                }
 
144
                Xfree(hold_buf);
 
145
                *len = (INT16)packet_size;
 
146
                return XIM_TRUE;
 
147
            }
 
148
        }
 
149
        memcpy(buf, hold_buf, data_len);
 
150
        buf_size -= data_len;
 
151
        Xfree(hold_buf);
 
152
        im->private.proto.hold_data = 0;
 
153
        im->private.proto.hold_data_len = 0;
 
154
    }
 
155
 
 
156
    if (!packet_size) {
 
157
        while (data_len < XIM_HEADER_SIZE) {
 
158
            if (!(im->private.proto.read(im,
 
159
                        (XPointer)&buf[data_len], buf_size, &ret_len))) {
 
160
                return XIM_FALSE;
 
161
            }
 
162
            data_len += ret_len;
 
163
            buf_size -= ret_len;
 
164
        }
 
165
        packet_size = _CheckProtocolData(im, buf);
 
166
    }
 
167
 
 
168
    if (packet_size > buf_size) {
 
169
        if (!(tmp = (char *)Xmalloc(data_len))) {
 
170
            return XIM_FALSE;
 
171
        }
 
172
        memcpy(tmp, buf, data_len);
 
173
        bzero(buf, data_len);
 
174
        im->private.proto.hold_data = tmp;
 
175
        im->private.proto.hold_data_len = data_len;
 
176
        *len = (INT16)packet_size;
 
177
        return XIM_OVERFLOW;
 
178
    }
 
179
 
 
180
    while (data_len < packet_size) {
 
181
        if (!(im->private.proto.read(im,
 
182
                        (XPointer)&buf[data_len], buf_size, &ret_len))) {
 
183
            return XIM_FALSE;
 
184
        }
 
185
        data_len += ret_len;
 
186
        buf_size -= ret_len;
 
187
    }
 
188
 
 
189
    for (i = packet_size; i < data_len; i++) {
 
190
        if (buf[i])
 
191
            break;
 
192
    }
 
193
    data_len -= i;
 
194
 
 
195
    if (data_len) {
 
196
        if (!(tmp = (char *)Xmalloc(data_len))) {
 
197
            return XIM_FALSE;
 
198
        }
 
199
        memcpy(tmp, &buf[i], data_len);
 
200
        bzero(&buf[i], data_len);
 
201
        im->private.proto.hold_data = tmp;
 
202
        im->private.proto.hold_data_len = data_len;
 
203
    } else {
 
204
        im->private.proto.hold_data = 0;
 
205
        im->private.proto.hold_data_len = 0;
 
206
    }
 
207
    *len = (INT16)packet_size;
 
208
    return XIM_TRUE;
 
209
}
 
210
 
 
211
Private Bool
 
212
_XimCallDispatcher(im, len, data)
 
213
    Xim          im;
 
214
    INT16        len;
 
215
    XPointer     data;
 
216
{
 
217
    return im->private.proto.call_dispatcher(im, len, data);
 
218
}
 
219
 
 
220
Public int
 
221
_XimRead(im, len, buf, buf_size, predicate, arg)
 
222
    Xim          im;
 
223
    INT16       *len;
 
224
    XPointer     buf;
 
225
    int          buf_size;
 
226
    Bool         (*predicate)(
 
227
#if NeedNestedPrototypes
 
228
                              Xim, INT16, XPointer, XPointer
 
229
#endif
 
230
                              );
 
231
    XPointer     arg;
 
232
{
 
233
    INT16        read_len;
 
234
    int          ret_code;
 
235
 
 
236
    for (;;) {
 
237
        ret_code = _XimReadData(im, &read_len, buf, buf_size);
 
238
        if(ret_code != XIM_TRUE) {
 
239
            return ret_code;
 
240
        }
 
241
        if ((*predicate)(im, read_len, buf, arg))
 
242
            break;
 
243
        if (_XimCallDispatcher(im, read_len, buf))
 
244
            continue;
 
245
        _XimError(im, 0, XIM_BadProtocol, (INT16)0, (CARD16)0, (char *)NULL);
 
246
    }
 
247
    *len = read_len;
 
248
    return True;
 
249
}
 
250
 
 
251
Public Bool
 
252
_XimRegisterDispatcher(im, callback, call_data)
 
253
    Xim          im;
 
254
    Bool         (*callback)(
 
255
#if NeedNestedPrototypes
 
256
                             Xim, INT16, XPointer, XPointer
 
257
#endif
 
258
                             );
 
259
    XPointer     call_data;
 
260
{
 
261
    return im->private.proto.register_dispatcher(im, callback, call_data);
 
262
}
 
263
 
 
264
Public void
 
265
_XimFlush(im)
 
266
    Xim          im;
 
267
{
 
268
    im->private.proto.flush(im);
 
269
    return;
 
270
}
 
271
 
 
272
Public Bool
 
273
_XimFilterWaitEvent(im)
 
274
    Xim          im;
 
275
{
 
276
    INT16        read_len;
 
277
    CARD32       reply32[BUFSIZE/4];
 
278
    char        *reply = (char *)reply32;
 
279
    XPointer     preply;
 
280
    int          buf_size;
 
281
    int          ret_code;
 
282
 
 
283
    buf_size = BUFSIZE;
 
284
    ret_code = _XimReadData(im, &read_len, (XPointer)reply, buf_size);
 
285
    if(ret_code == XIM_TRUE) {
 
286
        preply = reply;
 
287
    } else if(ret_code == XIM_OVERFLOW) {
 
288
        if(read_len <= 0) {
 
289
            preply = reply;
 
290
        } else {
 
291
            buf_size = (int)read_len;
 
292
            preply = (XPointer)Xmalloc(buf_size);
 
293
            ret_code = _XimReadData(im, &read_len, preply, buf_size);
 
294
            if(ret_code != XIM_TRUE) {
 
295
                if (preply != reply)
 
296
                    Xfree(preply);
 
297
                return False;
 
298
            }
 
299
        }
 
300
    } else {
 
301
        return False;
 
302
    }
 
303
    if (_XimCallDispatcher(im, read_len, preply)) {
 
304
        if(reply != preply)
 
305
            Xfree(preply);
 
306
        return True;
 
307
    }
 
308
    _XimError(im, 0, XIM_BadProtocol, (INT16)0, (CARD16)0, (char *)NULL);
 
309
    if(reply != preply)
 
310
        Xfree(preply);
 
311
    return True;
 
312
}