~sbeattie/ubuntu/lucid/vnc4/lp556147

« back to all changes in this revision

Viewing changes to unix/xc/lib/Xft/xftswap.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
/*
 
2
 * $XFree86: xc/lib/Xft/xftswap.c,v 1.1 2002/02/15 07:37:35 keithp Exp $
 
3
 *
 
4
 * Copyright � 2002 Keith Packard, member of The XFree86 Project, Inc.
 
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, and that the name of Keith Packard not be used in
 
11
 * advertising or publicity pertaining to distribution of the software without
 
12
 * specific, written prior permission.  Keith Packard makes no
 
13
 * representations about the suitability of this software for any purpose.  It
 
14
 * is provided "as is" without express or implied warranty.
 
15
 *
 
16
 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 
17
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 
18
 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 
19
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 
20
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 
21
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 
22
 * PERFORMANCE OF THIS SOFTWARE.
 
23
 */
 
24
 
 
25
#include <X11/Xlib.h>
 
26
#include "xftint.h"
 
27
 
 
28
int
 
29
XftNativeByteOrder (void)
 
30
{
 
31
    int     whichbyte = 1;
 
32
 
 
33
    if (*((char *) &whichbyte))
 
34
        return LSBFirst;
 
35
    return MSBFirst;
 
36
}
 
37
 
 
38
/* byte swap a 32-bit value */
 
39
#define swapl(x, n) { \
 
40
                 n = ((char *) (x))[0];\
 
41
                 ((char *) (x))[0] = ((char *) (x))[3];\
 
42
                 ((char *) (x))[3] = n;\
 
43
                 n = ((char *) (x))[1];\
 
44
                 ((char *) (x))[1] = ((char *) (x))[2];\
 
45
                 ((char *) (x))[2] = n; }
 
46
 
 
47
/* byte swap a short */
 
48
#define swaps(x, n) { \
 
49
                 n = ((char *) (x))[0];\
 
50
                 ((char *) (x))[0] = ((char *) (x))[1];\
 
51
                 ((char *) (x))[1] = n; }
 
52
 
 
53
/* byte swap a three-byte unit */
 
54
#define swapt(x, n) { \
 
55
                 n = ((char *) (x))[0];\
 
56
                 ((char *) (x))[0] = ((char *) (x))[2];\
 
57
                 ((char *) (x))[2] = n; }
 
58
 
 
59
void
 
60
XftSwapCARD32 (CARD32 *data, int u)
 
61
{
 
62
    char    n;
 
63
    while (u--)
 
64
    {
 
65
        swapl (data, n);
 
66
        data++;
 
67
    }
 
68
}
 
69
 
 
70
void
 
71
XftSwapCARD24 (CARD8 *data, int width, int height)
 
72
{
 
73
    int     units, u;
 
74
    char    n;
 
75
    CARD8   *d;
 
76
 
 
77
    units = width / 3;
 
78
    while (height--)
 
79
    {
 
80
        d = data;
 
81
        data += width;
 
82
        u = units;
 
83
        while (u--)
 
84
        {
 
85
            swapt (d, n);
 
86
            d += 3;
 
87
        }
 
88
    }
 
89
}
 
90
 
 
91
void
 
92
XftSwapCARD16 (CARD16 *data, int u)
 
93
{
 
94
    char    n;
 
95
    while (u--)
 
96
    {
 
97
        swaps (data, n);
 
98
        data++;
 
99
    }
 
100
}
 
101
 
 
102
void
 
103
XftSwapImage (XImage *image)
 
104
{
 
105
    switch (image->bits_per_pixel) {
 
106
    case 32:
 
107
        XftSwapCARD32 ((CARD32 *) image->data, 
 
108
                       image->height * image->bytes_per_line >> 2);
 
109
        break;
 
110
    case 24:
 
111
        XftSwapCARD24 ((CARD8 *) image->data,
 
112
                       image->bytes_per_line,
 
113
                       image->height);
 
114
        break;
 
115
    case 16:
 
116
        XftSwapCARD16 ((CARD16 *) image->data,
 
117
                       image->height * image->bytes_per_line >> 1);
 
118
        break;
 
119
    default:
 
120
        break;
 
121
    }
 
122
}