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

« back to all changes in this revision

Viewing changes to unix/xc/lib/X11/GetProp.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: GetProp.c,v 1.5 2001/02/09 02:03:33 xorgcvs Exp $ */
 
2
/*
 
3
 
 
4
Copyright 1986, 1998  The Open Group
 
5
 
 
6
Permission to use, copy, modify, distribute, and sell this software and its
 
7
documentation for any purpose is hereby granted without fee, provided that
 
8
the above copyright notice appear in all copies and that both that
 
9
copyright notice and this permission notice appear in supporting
 
10
documentation.
 
11
 
 
12
The above copyright notice and this permission notice shall be included in
 
13
all copies or substantial portions of the Software.
 
14
 
 
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
16
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
17
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
 
18
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 
19
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
20
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
21
 
 
22
Except as contained in this notice, the name of The Open Group shall not be
 
23
used in advertising or otherwise to promote the sale, use or other dealings
 
24
in this Software without prior written authorization from The Open Group.
 
25
 
 
26
*/
 
27
/* $XFree86: xc/lib/X11/GetProp.c,v 1.6 2001/12/14 19:54:01 dawes Exp $ */
 
28
 
 
29
#define NEED_REPLIES
 
30
#include "Xlibint.h"
 
31
 
 
32
int
 
33
XGetWindowProperty(dpy, w, property, offset, length, delete, 
 
34
        req_type, actual_type, actual_format, nitems, bytesafter, prop)
 
35
    register Display *dpy;
 
36
    Window w;
 
37
    Atom property;
 
38
    Bool delete;
 
39
    Atom req_type;
 
40
    Atom *actual_type;          /* RETURN */
 
41
    int *actual_format;         /* RETURN  8, 16, or 32 */
 
42
    long offset, length;
 
43
    unsigned long *nitems;      /* RETURN  # of 8-, 16-, or 32-bit entities */
 
44
    unsigned long *bytesafter;  /* RETURN */
 
45
    unsigned char **prop;       /* RETURN */
 
46
{
 
47
    xGetPropertyReply reply;
 
48
    register xGetPropertyReq *req;
 
49
    xError error;
 
50
 
 
51
    LockDisplay(dpy);
 
52
    GetReq (GetProperty, req);
 
53
    req->window = w;
 
54
    req->property = property;
 
55
    req->type = req_type;
 
56
    req->delete = delete;
 
57
    req->longOffset = offset;
 
58
    req->longLength = length;
 
59
    error.sequenceNumber = dpy->request;
 
60
    
 
61
    if (!_XReply (dpy, (xReply *) &reply, 0, xFalse)) {
 
62
        UnlockDisplay(dpy);
 
63
        SyncHandle();
 
64
        return (1);     /* not Success */
 
65
        }       
 
66
 
 
67
    *prop = (unsigned char *) NULL;
 
68
    if (reply.propertyType != None) {
 
69
        long nbytes, netbytes;
 
70
        switch (reply.format) {
 
71
      /* 
 
72
       * One extra byte is malloced than is needed to contain the property
 
73
       * data, but this last byte is null terminated and convenient for 
 
74
       * returning string properties, so the client doesn't then have to 
 
75
       * recopy the string to make it null terminated. 
 
76
       */
 
77
          case 8:
 
78
            nbytes = netbytes = reply.nItems;
 
79
            if (nbytes + 1 > 0 &&
 
80
                (*prop = (unsigned char *) Xmalloc ((unsigned)nbytes + 1)))
 
81
                _XReadPad (dpy, (char *) *prop, netbytes);
 
82
            break;
 
83
 
 
84
          case 16:
 
85
            nbytes = reply.nItems * sizeof (short);
 
86
            netbytes = reply.nItems << 1;
 
87
            if (nbytes + 1 > 0 &&
 
88
                (*prop = (unsigned char *) Xmalloc ((unsigned)nbytes + 1)))
 
89
                _XRead16Pad (dpy, (short *) *prop, netbytes);
 
90
            break;
 
91
 
 
92
          case 32:
 
93
            nbytes = reply.nItems * sizeof (long);
 
94
            netbytes = reply.nItems << 2;
 
95
            if (nbytes + 1 > 0 &&
 
96
                (*prop = (unsigned char *) Xmalloc ((unsigned)nbytes + 1)))
 
97
                _XRead32 (dpy, (long *) *prop, netbytes);
 
98
            break;
 
99
 
 
100
          default:
 
101
            /*
 
102
             * This part of the code should never be reached.  If it is,
 
103
             * the server sent back a property with an invalid format.
 
104
             * This is a BadImplementation error. 
 
105
             */
 
106
            {
 
107
                /* sequence number stored above */
 
108
                error.type = X_Error;
 
109
                error.majorCode = X_GetProperty;
 
110
                error.minorCode = 0;
 
111
                error.errorCode = BadImplementation;
 
112
                _XError(dpy, &error);
 
113
            }
 
114
            nbytes = netbytes = 0L;
 
115
            break;
 
116
        }
 
117
        if (! *prop) {
 
118
            _XEatData(dpy, (unsigned long) netbytes);
 
119
            UnlockDisplay(dpy);
 
120
            SyncHandle();
 
121
            return(BadAlloc);   /* not Success */
 
122
        }
 
123
        (*prop)[nbytes] = '\0';
 
124
    }
 
125
    *actual_type = reply.propertyType;
 
126
    *actual_format = reply.format;
 
127
    *nitems = reply.nItems;
 
128
    *bytesafter = reply.bytesAfter;
 
129
    UnlockDisplay(dpy);
 
130
    SyncHandle();
 
131
    return(Success);
 
132
}
 
133