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

« back to all changes in this revision

Viewing changes to unix/xc/lib/GL/mesa/src/drv/common/mm.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
 * GLX Hardware Device Driver common code
 
3
 * Copyright (C) 1999 Keith Whitwell
 
4
 *
 
5
 * Permission is hereby granted, free of charge, to any person obtaining a
 
6
 * copy of this software and associated documentation files (the "Software"),
 
7
 * to deal in the Software without restriction, including without limitation
 
8
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 
9
 * and/or sell copies of the Software, and to permit persons to whom the
 
10
 * Software is furnished to do so, subject to the following conditions:
 
11
 *
 
12
 * The above copyright notice and this permission notice shall be included
 
13
 * in all copies or substantial portions of the Software.
 
14
 *
 
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 
16
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
17
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 
18
 * KEITH WHITWELL, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM, 
 
19
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 
 
20
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 
 
21
 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
22
 *
 
23
 */
 
24
/* $XFree86: xc/lib/GL/mesa/src/drv/common/mm.c,v 1.4 2002/10/30 12:51:27 alanh Exp $ */
 
25
 
 
26
#include <stdlib.h>
 
27
#include <stdio.h>
 
28
 
 
29
#include "mm.h"
 
30
#include "hwlog.h"
 
31
 
 
32
/* KW: I don't know who the author of this code is, but it wasn't me
 
33
 * despite what the copyright says...
 
34
 */
 
35
 
 
36
void mmDumpMemInfo( memHeap_t *heap )
 
37
{
 
38
   TMemBlock *p;
 
39
 
 
40
   fprintf(stderr, "Memory heap %p:\n", heap);
 
41
   if (heap == 0) {
 
42
      fprintf(stderr, "  heap == 0\n");
 
43
   } else {
 
44
      p = (TMemBlock *)heap;
 
45
      while (p) {
 
46
         fprintf(stderr, "  Offset:%08x, Size:%08x, %c%c\n",p->ofs,p->size,
 
47
                 p->free ? '.':'U',
 
48
                 p->reserved ? 'R':'.');
 
49
         p = p->next;
 
50
      }
 
51
   }
 
52
   fprintf(stderr, "End of memory blocks\n");
 
53
}
 
54
 
 
55
memHeap_t *mmInit(int ofs,
 
56
                  int size)
 
57
{
 
58
   PMemBlock blocks;
 
59
  
 
60
   if (size <= 0) {
 
61
      return 0;
 
62
   }
 
63
   blocks = (TMemBlock *) calloc(1,sizeof(TMemBlock));
 
64
   if (blocks) {
 
65
      blocks->ofs = ofs;
 
66
      blocks->size = size;
 
67
      blocks->free = 1;
 
68
      return (memHeap_t *)blocks;
 
69
   } else
 
70
      return 0;
 
71
}
 
72
 
 
73
 
 
74
static TMemBlock* SliceBlock(TMemBlock *p, 
 
75
                             int startofs, int size, 
 
76
                             int reserved, int alignment)
 
77
{
 
78
   TMemBlock *newblock;
 
79
 
 
80
   /* break left */
 
81
   if (startofs > p->ofs) {
 
82
      newblock = (TMemBlock*) calloc(1,sizeof(TMemBlock));
 
83
      if (!newblock)
 
84
         return NULL;
 
85
      newblock->ofs = startofs;
 
86
      newblock->size = p->size - (startofs - p->ofs);
 
87
      newblock->free = 1;
 
88
      newblock->next = p->next;
 
89
      p->size -= newblock->size;
 
90
      p->next = newblock;
 
91
      p = newblock;
 
92
   }
 
93
 
 
94
   /* break right */
 
95
   if (size < p->size) {
 
96
      newblock = (TMemBlock*) calloc(1,sizeof(TMemBlock));
 
97
      if (!newblock)
 
98
         return NULL;
 
99
      newblock->ofs = startofs + size;
 
100
      newblock->size = p->size - size;
 
101
      newblock->free = 1;
 
102
      newblock->next = p->next;
 
103
      p->size = size;
 
104
      p->next = newblock;
 
105
   }
 
106
 
 
107
   /* p = middle block */
 
108
   p->align = alignment;
 
109
   p->free = 0;
 
110
   p->reserved = reserved;
 
111
   return p;
 
112
}
 
113
 
 
114
PMemBlock mmAllocMem( memHeap_t *heap, int size, int align2, int startSearch)
 
115
{
 
116
   int mask,startofs,endofs;
 
117
   TMemBlock *p;
 
118
 
 
119
   if (!heap || align2 < 0 || size <= 0)
 
120
      return NULL;
 
121
   mask = (1 << align2)-1;
 
122
   startofs = 0;
 
123
   p = (TMemBlock *)heap;
 
124
   while (p) {
 
125
      if ((p)->free) {
 
126
         startofs = (p->ofs + mask) & ~mask;
 
127
         if ( startofs < startSearch ) {
 
128
            startofs = startSearch;
 
129
         }
 
130
         endofs = startofs+size;
 
131
         if (endofs <= (p->ofs+p->size))
 
132
            break;
 
133
      }
 
134
      p = p->next;
 
135
   }
 
136
   if (!p)
 
137
      return NULL;
 
138
   p = SliceBlock(p,startofs,size,0,mask+1);
 
139
   p->heap = heap;
 
140
   return p;
 
141
}
 
142
 
 
143
static __inline__ int Join2Blocks(TMemBlock *p)
 
144
{
 
145
   if (p->free && p->next && p->next->free) {
 
146
      TMemBlock *q = p->next;
 
147
      p->size += q->size;
 
148
      p->next = q->next;
 
149
      free(q);
 
150
      return 1;
 
151
   }
 
152
   return 0;
 
153
}
 
154
 
 
155
int mmFreeMem(PMemBlock b)
 
156
{
 
157
   TMemBlock *p,*prev;
 
158
 
 
159
   if (!b)
 
160
      return 0;
 
161
   if (!b->heap) {
 
162
      fprintf(stderr, "no heap\n");
 
163
      return -1;
 
164
   }
 
165
   p = b->heap;
 
166
   prev = NULL;
 
167
   while (p && p != b) {
 
168
      prev = p;
 
169
      p = p->next;
 
170
   }
 
171
   if (!p || p->free || p->reserved) {
 
172
      if (!p)
 
173
         fprintf(stderr, "block not found in heap\n");
 
174
      else if (p->free)
 
175
         fprintf(stderr, "block already free\n");
 
176
      else
 
177
         fprintf(stderr, "block is reserved\n");
 
178
      return -1;
 
179
   }
 
180
   p->free = 1;
 
181
   Join2Blocks(p);
 
182
   if (prev)
 
183
      Join2Blocks(prev);
 
184
   return 0;
 
185
}
 
186
 
 
187
 
 
188
void mmDestroy(memHeap_t *heap)
 
189
{
 
190
   TMemBlock *p,*q;
 
191
 
 
192
   if (!heap)
 
193
      return;
 
194
   p = (TMemBlock *)heap;
 
195
   while (p) {
 
196
      q = p->next;
 
197
      free(p);
 
198
      p = q;
 
199
   }
 
200
}