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

« back to all changes in this revision

Viewing changes to unix/xc/programs/Xserver/XIE/mixie/export/medraw.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: medraw.c,v 1.4 2001/02/09 02:04:24 xorgcvs Exp $ */
 
2
/**** module medraw.c ****/
 
3
/******************************************************************************
 
4
 
 
5
Copyright 1993, 1994, 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
                                NOTICE
 
29
                              
 
30
This software is being provided by AGE Logic, Inc. under the
 
31
following license.  By obtaining, using and/or copying this software,
 
32
you agree that you have read, understood, and will comply with these
 
33
terms and conditions:
 
34
 
 
35
     Permission to use, copy, modify, distribute and sell this
 
36
     software and its documentation for any purpose and without
 
37
     fee or royalty and to grant others any or all rights granted
 
38
     herein is hereby granted, provided that you agree to comply
 
39
     with the following copyright notice and statements, including
 
40
     the disclaimer, and that the same appears on all copies and
 
41
     derivative works of the software and documentation you make.
 
42
     
 
43
     "Copyright 1993, 1994 by AGE Logic, Inc."
 
44
     
 
45
     THIS SOFTWARE IS PROVIDED "AS IS".  AGE LOGIC MAKES NO
 
46
     REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED.  By way of
 
47
     example, but not limitation, AGE LOGIC MAKE NO
 
48
     REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY OR FITNESS
 
49
     FOR ANY PARTICULAR PURPOSE OR THAT THE SOFTWARE DOES NOT
 
50
     INFRINGE THIRD-PARTY PROPRIETARY RIGHTS.  AGE LOGIC 
 
51
     SHALL BEAR NO LIABILITY FOR ANY USE OF THIS SOFTWARE.  IN NO
 
52
     EVENT SHALL EITHER PARTY BE LIABLE FOR ANY INDIRECT,
 
53
     INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOSS
 
54
     OF PROFITS, REVENUE, DATA OR USE, INCURRED BY EITHER PARTY OR
 
55
     ANY THIRD PARTY, WHETHER IN AN ACTION IN CONTRACT OR TORT OR
 
56
     BASED ON A WARRANTY, EVEN IF AGE LOGIC LICENSEES
 
57
     HEREUNDER HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
 
58
     DAMAGES.
 
59
    
 
60
     The name of AGE Logic, Inc. may not be used in
 
61
     advertising or publicity pertaining to this software without
 
62
     specific, written prior permission from AGE Logic.
 
63
 
 
64
     Title to this software shall at all times remain with AGE
 
65
     Logic, Inc.
 
66
*****************************************************************************
 
67
  
 
68
        medraw.c -- DDXIE prototype export drawable element
 
69
  
 
70
        Robert NC Shelley -- AGE Logic, Inc. April, 1993
 
71
  
 
72
*****************************************************************************/
 
73
/* $XFree86: xc/programs/Xserver/XIE/mixie/export/medraw.c,v 3.6 2001/12/14 19:58:19 dawes Exp $ */
 
74
 
 
75
#define _XIEC_MEDRAW
 
76
#define _XIEC_EDRAW
 
77
 
 
78
/*
 
79
 *  Include files
 
80
 */
 
81
 
 
82
/*
 
83
 *  Core X Includes
 
84
 */
 
85
#include <X.h>
 
86
#include <Xproto.h>
 
87
/*
 
88
 *  XIE Includes
 
89
 */
 
90
#include <XIE.h>
 
91
#include <XIEproto.h>
 
92
/*
 
93
 *  more X server includes.
 
94
 */
 
95
#include <misc.h>
 
96
#include <dixstruct.h>
 
97
#include <pixmapstr.h>
 
98
#include <gcstruct.h>
 
99
/*
 
100
 *  Server XIE Includes
 
101
 */
 
102
#include <error.h>
 
103
#include <macro.h>
 
104
#include <element.h>
 
105
#include <texstr.h>
 
106
#include <xiemd.h>
 
107
#include <memory.h>
 
108
 
 
109
 
 
110
/*
 
111
 *  routines referenced by other DDXIE modules
 
112
 */
 
113
extern int miAnalyzeEDraw(floDefPtr flo, peDefPtr ped);
 
114
 
 
115
/*
 
116
 *  routines used internal to this module
 
117
 */
 
118
static int CreateEDraw(floDefPtr flo, peDefPtr ped);
 
119
static int InitializeEDraw(floDefPtr flo, peDefPtr ped);
 
120
static int ActivateEDrawAlign(floDefPtr flo, peDefPtr ped, peTexPtr pet);
 
121
static int ActivateEDrawStrip(floDefPtr flo, peDefPtr ped, peTexPtr pet);
 
122
static int ResetEDraw(floDefPtr flo, peDefPtr ped);
 
123
static int DestroyEDraw(floDefPtr flo, peDefPtr ped);
 
124
 
 
125
static void adjustStride8to4(char *dst, char *src, CARD32 width);
 
126
static void adjustStride32to24(char *dst, char *src, CARD32 width);
 
127
 
 
128
extern Bool     DrawableAndGC();
 
129
 
 
130
/*
 
131
 * DDXIE ExportDrawable entry points
 
132
 */
 
133
static ddElemVecRec EDrawVec = {
 
134
  CreateEDraw,
 
135
  InitializeEDraw,
 
136
  (xieIntProc)NULL,
 
137
  (xieIntProc)NULL,
 
138
  ResetEDraw,
 
139
  DestroyEDraw
 
140
  };
 
141
 
 
142
typedef struct _medraw {
 
143
  xieVoidProc    adjust;
 
144
  char          *buf;
 
145
} meDrawRec, *meDrawPtr;
 
146
 
 
147
 
 
148
/*------------------------------------------------------------------------
 
149
------------------- see if we can handle this element --------------------
 
150
------------------------------------------------------------------------*/
 
151
int miAnalyzeEDraw(floDefPtr flo, peDefPtr ped)
 
152
{
 
153
  /* for now just stash our entry point vector in the peDef */
 
154
  ped->ddVec = EDrawVec;
 
155
 
 
156
  return(TRUE);
 
157
}                               /* end miAnalyzeEDraw */
 
158
 
 
159
/*------------------------------------------------------------------------
 
160
---------------------------- create peTex . . . --------------------------
 
161
------------------------------------------------------------------------*/
 
162
static int CreateEDraw(floDefPtr flo, peDefPtr ped)
 
163
{
 
164
  /* attach an execution context to the photo element definition */
 
165
  return MakePETex(flo, ped, sizeof(meDrawRec), NO_SYNC, NO_SYNC);
 
166
}                               /* end CreateEDraw */
 
167
 
 
168
/*------------------------------------------------------------------------
 
169
---------------------------- initialize peTex . . . ----------------------
 
170
------------------------------------------------------------------------*/
 
171
static int InitializeEDraw(floDefPtr flo, peDefPtr ped)
 
172
{
 
173
  peTexPtr    pet = ped->peTex;
 
174
  meDrawPtr   ddx = (meDrawPtr) pet->private;
 
175
  formatPtr   sf  = &ped->inFloLst[SRCtag].format[0];
 
176
  formatPtr   df  = &ped->outFlo.format[0];
 
177
  Bool adj_stride = sf->stride != df->stride;
 
178
  Bool adj_pitch  = sf->pitch  != df->pitch;
 
179
  
 
180
  if(adj_stride || adj_pitch) {
 
181
    ped->ddVec.activate = ActivateEDrawAlign;
 
182
 
 
183
    if(adj_stride) {
 
184
      if(!(ddx->buf = (char*) XieMalloc(df->pitch>>3)))
 
185
        AllocError(flo,ped, return(FALSE));
 
186
      
 
187
      if(sf->stride == 32 && df->stride == 24)
 
188
        ddx->adjust  = adjustStride32to24;
 
189
      
 
190
      else if(sf->stride == 8 && df->stride == 4)
 
191
        ddx->adjust  = adjustStride8to4;
 
192
      
 
193
      /* add more adjustment routines as required */
 
194
    }
 
195
  } else {
 
196
    ped->ddVec.activate = ActivateEDrawStrip;
 
197
  }
 
198
  return(InitReceptors(flo,ped,NO_DATAMAP,1));
 
199
}                               /* end InitializeEDraw */
 
200
 
 
201
 
 
202
/*------------------------------------------------------------------------
 
203
----------------------------- crank some data ----------------------------
 
204
------------------------------------------------------------------------*/
 
205
static int ActivateEDrawAlign(floDefPtr flo, peDefPtr ped, peTexPtr pet)
 
206
{
 
207
  xieFloExportDrawable  *raw = (xieFloExportDrawable *) ped->elemRaw;
 
208
  eDrawDefPtr            dix = (eDrawDefPtr) ped->elemPvt;
 
209
  meDrawPtr              ddx = (meDrawPtr) pet->private;
 
210
  bandPtr                bnd = &pet->receptor[SRCtag].band[0];
 
211
  char            *dst, *src = (char*)GetCurrentSrc(flo,pet,bnd);
 
212
  CARD32               width = bnd->format->width;
 
213
 
 
214
  if (!DrawableAndGC(flo,ped,raw->drawable,raw->gc,&dix->pDraw,&dix->pGC))
 
215
    return FALSE;
 
216
  
 
217
  do {
 
218
    if(ddx->adjust) {
 
219
      dst = AlterSrc(flo,pet,bnd->strip) ? src : ddx->buf;
 
220
      (*ddx->adjust)(dst, src, width);
 
221
    } else
 
222
      dst = src;
 
223
 
 
224
    (*dix->pGC->ops->PutImage)(dix->pDraw,                /* drawable      */
 
225
                               dix->pGC,                  /* gc            */
 
226
                               dix->pDraw->depth,         /* depth         */
 
227
                               raw->dstX,                 /* drawable-x    */
 
228
                               raw->dstY + bnd->current,  /* drawable-y    */
 
229
                               width, 1,                  /* width, height */
 
230
                               bnd->strip->bitOff,        /* padding?      */
 
231
                               ZPixmap,                   /* data format   */
 
232
                               dst                        /* data buffer   */
 
233
                               );
 
234
  } while ((src = (char*)GetNextSrc(flo,pet,bnd,KEEP)) != 0);
 
235
  
 
236
  /* make sure the scheduler knows how much src we used */
 
237
  FreeData(flo,pet,bnd,bnd->current);
 
238
  
 
239
  return(TRUE);
 
240
}                               /* end ActivateEDrawAlign */
 
241
 
 
242
 
 
243
/*------------------------------------------------------------------------
 
244
----------------------------- crank some data ----------------------------
 
245
------------------------------------------------------------------------*/
 
246
static int ActivateEDrawStrip(floDefPtr flo, peDefPtr ped, peTexPtr pet)
 
247
{
 
248
  xieFloExportDrawable  *raw = (xieFloExportDrawable *) ped->elemRaw;
 
249
  eDrawDefPtr            pvt = (eDrawDefPtr) ped->elemPvt;
 
250
  bandPtr                bnd = &pet->receptor[SRCtag].band[0];
 
251
  char                  *src = (char*)GetCurrentSrc(flo,pet,bnd);
 
252
  
 
253
  if(src) {
 
254
    if (!DrawableAndGC(flo,ped,raw->drawable,raw->gc,&pvt->pDraw,&pvt->pGC))
 
255
      return FALSE;
 
256
    do    
 
257
      (*pvt->pGC->ops->PutImage)(pvt->pDraw,              /* drawable    */
 
258
                                 pvt->pGC,                /* gc          */
 
259
                                 pvt->pDraw->depth,       /* depth       */
 
260
                                 raw->dstX,               /* drawable-x  */
 
261
                                 raw->dstY+bnd->minLocal, /* drawable-y  */
 
262
                                 bnd->format->width,      /* width       */
 
263
                                 bnd->strip->length,      /* height      */
 
264
                                 bnd->strip->bitOff,      /* padding?    */
 
265
                                 ZPixmap,                 /* data format */
 
266
                                 src                      /* data buffer */
 
267
                                 );
 
268
    while ((src = (char*)GetSrc(flo,pet,bnd,bnd->maxLocal,KEEP)) != 0);
 
269
  }
 
270
  /* make sure the scheduler knows how much src we used */
 
271
  FreeData(flo,pet,bnd,bnd->current);
 
272
 
 
273
  return(TRUE);
 
274
}                               /* end ActivateEDrawStrip */
 
275
 
 
276
 
 
277
/*------------------------------------------------------------------------
 
278
------------------------ get rid of run-time stuff -----------------------
 
279
------------------------------------------------------------------------*/
 
280
static int ResetEDraw(floDefPtr flo, peDefPtr ped)
 
281
{
 
282
  meDrawPtr ddx = (meDrawPtr) ped->peTex->private;
 
283
 
 
284
  if(ddx->buf) ddx->buf = (char*)XieFree(ddx->buf);
 
285
  ddx->adjust = (xieVoidProc)NULL;
 
286
 
 
287
  ResetReceptors(ped);
 
288
  
 
289
  return(TRUE);
 
290
}                               /* end ResetEDraw */
 
291
 
 
292
 
 
293
/*------------------------------------------------------------------------
 
294
-------------------------- get rid of this element -----------------------
 
295
------------------------------------------------------------------------*/
 
296
static int DestroyEDraw(floDefPtr flo, peDefPtr ped)
 
297
{
 
298
  /* get rid of the peTex structure  */
 
299
  if(ped->peTex)
 
300
    ped->peTex = (peTexPtr) XieFree(ped->peTex);
 
301
 
 
302
  /* zap this element's entry point vector */
 
303
  ped->ddVec.create     = (xieIntProc) NULL;
 
304
  ped->ddVec.initialize = (xieIntProc) NULL;
 
305
  ped->ddVec.activate   = (xieIntProc) NULL;
 
306
  ped->ddVec.reset      = (xieIntProc) NULL;
 
307
  ped->ddVec.destroy    = (xieIntProc) NULL;
 
308
 
 
309
  return(TRUE);
 
310
}                               /* end DestroyEDraw */
 
311
 
 
312
 
 
313
/*------------------------------------------------------------------------
 
314
---------------------------- alignment routines --------------------------
 
315
------------------------------------------------------------------------*/
 
316
static void adjustStride32to24(char *dst, char *src, CARD32 width)
 
317
{
 
318
  register char *ip, *op;
 
319
  CARD32   i;
 
320
  
 
321
#if (BITMAP_BIT_ORDER == IMAGE_BYTE_ORDER)
 
322
  ip = src;
 
323
  op = dst;
 
324
  for(i = 0; i < width; ip += 2, ++i) {
 
325
    *op++ = *ip++; *op++ = *ip++; *op++ = *ip;
 
326
  }
 
327
#else
 
328
  /* we'll do the first 2 pixels by hand in case we're doing this in-place
 
329
   */
 
330
  char tmp = src[0];
 
331
  dst[0]   = src[2];
 
332
  dst[2]   = tmp;
 
333
  if(width > 1) {
 
334
    tmp    = src[4];
 
335
    dst[3] = src[6];
 
336
    dst[4] = src[5];
 
337
    dst[5] = tmp;
 
338
  }
 
339
  if(width > 2) {
 
340
      ip = src + 8;
 
341
      op = dst + 6;
 
342
      for(i = 2; i < width; ip += 4, ++i) {
 
343
        *op++ = ip[2]; *op++ = ip[1]; *op++ = *ip;
 
344
      }
 
345
    }
 
346
#endif
 
347
}
 
348
 
 
349
static void adjustStride8to4(char *dst, char *src, CARD32 width)
 
350
{
 
351
  register char *ip = src, *op = dst;
 
352
  CARD32   i;
 
353
  
 
354
  for(i = 0; i < width; ip += 2, ++i) {
 
355
#if (BITMAP_BIT_ORDER == LSBFirst)
 
356
    *op++ = *ip | *(ip+1)<<8;
 
357
#else
 
358
    *op++ = *ip<<8 | *(ip+1);
 
359
#endif
 
360
  }
 
361
}
 
362
 
 
363
/* end module medraw.c */