Bug Summary

File:hw/xquartz/../../mi/miinitext.c
Location:line 337, column 13
Description:Access to field 'initFunc' results in a dereference of a null pointer (loaded from variable 'ext')

Annotated Source Code

1/***********************************************************
2
3Copyright 1987, 1998 The Open Group
4
5Permission to use, copy, modify, distribute, and sell this software and its
6documentation for any purpose is hereby granted without fee, provided that
7the above copyright notice appear in all copies and that both that
8copyright notice and this permission notice appear in supporting
9documentation.
10
11The above copyright notice and this permission notice shall be included in
12all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
21Except as contained in this notice, the name of The Open Group shall not be
22used in advertising or otherwise to promote the sale, use or other dealings
23in this Software without prior written authorization from The Open Group.
24
25Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
26
27 All Rights Reserved
28
29Permission to use, copy, modify, and distribute this software and its
30documentation for any purpose and without fee is hereby granted,
31provided that the above copyright notice appear in all copies and that
32both that copyright notice and this permission notice appear in
33supporting documentation, and that the name of Digital not be
34used in advertising or publicity pertaining to distribution of the
35software without specific, written prior permission.
36
37DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
38ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
39DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
40ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
41WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
42ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
43SOFTWARE.
44
45******************************************************************/
46
47/*
48 * Copyright (c) 2000 by The XFree86 Project, Inc.
49 *
50 * Permission is hereby granted, free of charge, to any person obtaining a
51 * copy of this software and associated documentation files (the "Software"),
52 * to deal in the Software without restriction, including without limitation
53 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
54 * and/or sell copies of the Software, and to permit persons to whom the
55 * Software is furnished to do so, subject to the following conditions:
56 *
57 * The above copyright notice and this permission notice shall be included in
58 * all copies or substantial portions of the Software.
59 *
60 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
61 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
62 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
63 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
64 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
65 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
66 * OTHER DEALINGS IN THE SOFTWARE.
67 *
68 * Except as contained in this notice, the name of the copyright holder(s)
69 * and author(s) shall not be used in advertising or otherwise to promote
70 * the sale, use or other dealings in this Software without prior written
71 * authorization from the copyright holder(s) and author(s).
72 */
73
74#ifdef HAVE_DIX_CONFIG_H1
75#include <dix-config.h>
76#endif
77
78#ifdef HAVE_XORG_CONFIG_H
79#include <xorg-config.h>
80#include "xf86Extensions.h"
81#endif
82
83#ifdef HAVE_DMX_CONFIG_H
84#include <dmx-config.h>
85#undef XV1
86#undef DBE1
87#undef SCREENSAVER1
88#undef RANDR1
89#undef DAMAGE1
90#undef COMPOSITE
91#undef MITSHM1
92#endif
93
94#ifdef HAVE_XNEST_CONFIG_H
95#include <xnest-config.h>
96#undef COMPOSITE
97#undef DPMSExtension
98#endif
99
100#ifdef HAVE_KDRIVE_CONFIG_H
101#include <kdrive-config.h>
102#endif
103
104#ifdef HAVE_XGL_CONFIG_H
105#include <xgl-config.h>
106#endif
107
108#include "misc.h"
109#include "extension.h"
110#include "extinit.h"
111#ifdef INXQUARTZ1
112#include "nonsdk_extinit.h"
113#endif
114#include "micmap.h"
115#include "globals.h"
116
117/* The following is only a small first step towards run-time
118 * configurable extensions.
119 */
120typedef struct {
121 const char *name;
122 Bool *disablePtr;
123} ExtensionToggle;
124
125static ExtensionToggle ExtensionToggleList[] = {
126 /* sort order is extension name string as shown in xdpyinfo */
127 {"Generic Events", &noGEExtension},
128#ifdef COMPOSITE
129 {"Composite", &noCompositeExtension},
130#endif
131#ifdef DAMAGE1
132 {"DAMAGE", &noDamageExtension},
133#endif
134#ifdef DBE1
135 {"DOUBLE-BUFFER", &noDbeExtension},
136#endif
137#ifdef DPMSExtension
138 {"DPMS", &noDPMSExtension},
139#endif
140#ifdef GLXEXT1
141 {"GLX", &noGlxExtension},
142#endif
143#ifdef SCREENSAVER1
144 {"MIT-SCREEN-SAVER", &noScreenSaverExtension},
145#endif
146#ifdef MITSHM1
147 {SHMNAME"MIT-SHM", &noMITShmExtension},
148#endif
149#ifdef RANDR1
150 {"RANDR", &noRRExtension},
151#endif
152 {"RENDER", &noRenderExtension},
153#ifdef XCSECURITY
154 {"SECURITY", &noSecurityExtension},
155#endif
156#ifdef RES1
157 {"X-Resource", &noResExtension},
158#endif
159#ifdef XF86BIGFONT
160 {"XFree86-Bigfont", &noXFree86BigfontExtension},
161#endif
162#ifdef XORGSERVER
163#ifdef XFreeXDGA
164 {"XFree86-DGA", &noXFree86DGAExtension},
165#endif
166#ifdef XF86DRI
167 {"XFree86-DRI", &noXFree86DRIExtension},
168#endif
169#ifdef XF86VIDMODE
170 {"XFree86-VidModeExtension", &noXFree86VidModeExtension},
171#endif
172#endif
173 {"XFIXES", &noXFixesExtension},
174#ifdef PANORAMIX1
175 {"XINERAMA", &noPanoramiXExtension},
176#endif
177 {"XInputExtension", NULL((void*)0)},
178 {"XKEYBOARD", NULL((void*)0)},
179#ifdef XSELINUX
180 {"SELinux", &noSELinuxExtension},
181#endif
182 {"XTEST", &noTestExtensions},
183#ifdef XV1
184 {"XVideo", &noXvExtension},
185#endif
186};
187
188Bool
189EnableDisableExtension(const char *name, Bool enable)
190{
191 ExtensionToggle *ext;
192 int i;
193
194 for (i = 0; i < ARRAY_SIZE(ExtensionToggleList)(sizeof((ExtensionToggleList)) / sizeof((ExtensionToggleList)
[0]))
; i++) {
195 ext = &ExtensionToggleList[i];
196 if (strcmp(name, ext->name) == 0) {
197 if (ext->disablePtr != NULL((void*)0)) {
198 *ext->disablePtr = !enable;
199 return TRUE1;
200 }
201 else {
202 /* Extension is always on, impossible to disable */
203 return enable; /* okay if they wanted to enable,
204 fail if they tried to disable */
205 }
206 }
207 }
208
209 return FALSE0;
210}
211
212void
213EnableDisableExtensionError(const char *name, Bool enable)
214{
215 ExtensionToggle *ext;
216 int i;
217 Bool found = FALSE0;
218
219 for (i = 0; i < ARRAY_SIZE(ExtensionToggleList)(sizeof((ExtensionToggleList)) / sizeof((ExtensionToggleList)
[0]))
; i++) {
220 ext = &ExtensionToggleList[i];
221 if ((strcmp(name, ext->name) == 0) && (ext->disablePtr == NULL((void*)0))) {
222 ErrorF("[mi] Extension \"%s\" can not be disabled\n", name);
223 found = TRUE1;
224 break;
225 }
226 }
227 if (found == FALSE0)
228 ErrorF("[mi] Extension \"%s\" is not recognized\n", name);
229 ErrorF("[mi] Only the following extensions can be run-time %s:\n",
230 enable ? "enabled" : "disabled");
231 for (i = 0; i < ARRAY_SIZE(ExtensionToggleList)(sizeof((ExtensionToggleList)) / sizeof((ExtensionToggleList)
[0]))
; i++) {
232 ext = &ExtensionToggleList[i];
233 if (ext->disablePtr != NULL((void*)0)) {
234 ErrorF("[mi] %s\n", ext->name);
235 }
236 }
237}
238
239/* List of built-in (statically linked) extensions */
240static const ExtensionModule staticExtensions[] = {
241 {GEExtensionInit, "Generic Event Extension", &noGEExtension},
242 {ShapeExtensionInit, "SHAPE", NULL((void*)0)},
243#ifdef MITSHM1
244 {ShmExtensionInit, SHMNAME"MIT-SHM", &noMITShmExtension},
245#endif
246 {XInputExtensionInit, "XInputExtension", NULL((void*)0)},
247#ifdef XTEST1
248 {XTestExtensionInit, XTestExtensionName"XTEST", &noTestExtensions},
249#endif
250 {BigReqExtensionInit, "BIG-REQUESTS", NULL((void*)0)},
251 {SyncExtensionInit, "SYNC", NULL((void*)0)},
252 {XkbExtensionInit, XkbName"XKEYBOARD", NULL((void*)0)},
253 {XCMiscExtensionInit, "XC-MISC", NULL((void*)0)},
254#ifdef XCSECURITY
255 {SecurityExtensionInit, SECURITY_EXTENSION_NAME, &noSecurityExtension},
256#endif
257#ifdef PANORAMIX1
258 {PanoramiXExtensionInit, PANORAMIX_PROTOCOL_NAME"XINERAMA", &noPanoramiXExtension},
259#endif
260#ifdef INXQUARTZ1
261 /* PseudoramiXExtensionInit must be done before RRExtensionInit, or
262 * XQuartz will render windows offscreen.
263 */
264 {PseudoramiXExtensionInit, "PseudoramiX", &noPseudoramiXExtension},
265#endif
266 /* must be before Render to layer DisplayCursor correctly */
267 {XFixesExtensionInit, "XFIXES", &noXFixesExtension},
268#ifdef XF86BIGFONT
269 {XFree86BigfontExtensionInit, XF86BIGFONTNAME, &noXFree86BigfontExtension},
270#endif
271 {RenderExtensionInit, "RENDER", &noRenderExtension},
272#ifdef RANDR1
273 {RRExtensionInit, "RANDR", &noRRExtension},
274#endif
275#ifdef COMPOSITE
276 {CompositeExtensionInit, "COMPOSITE", &noCompositeExtension},
277#endif
278#ifdef DAMAGE1
279 {DamageExtensionInit, "DAMAGE", &noDamageExtension},
280#endif
281#ifdef SCREENSAVER1
282 {ScreenSaverExtensionInit, ScreenSaverName"MIT-SCREEN-SAVER", &noScreenSaverExtension},
283#endif
284#ifdef DBE1
285 {DbeExtensionInit, "DOUBLE-BUFFER", &noDbeExtension},
286#endif
287#ifdef XRECORD1
288 {RecordExtensionInit, "RECORD", &noTestExtensions},
289#endif
290#ifdef DPMSExtension
291 {DPMSExtensionInit, DPMSExtensionName, &noDPMSExtension},
292#endif
293#ifdef PRESENT1
294 {present_extension_init, PRESENT_NAME"Present", NULL((void*)0)},
295#endif
296#ifdef DRI3
297 {dri3_extension_init, DRI3_NAME, NULL((void*)0)},
298#endif
299#ifdef RES1
300 {ResExtensionInit, XRES_NAME"X-Resource", &noResExtension},
301#endif
302#ifdef XV1
303 {XvExtensionInit, XvName"XVideo", &noXvExtension},
304 {XvMCExtensionInit, XvMCName"XVideo-MotionCompensation", &noXvExtension},
305#endif
306#ifdef XSELINUX
307 {SELinuxExtensionInit, SELINUX_EXTENSION_NAME, &noSELinuxExtension},
308#endif
309};
310
311static ExtensionModule *ExtensionModuleList = NULL((void*)0);
312static int numExtensionModules = 0;
313
314static void
315AddStaticExtensions(void)
316{
317 static Bool listInitialised = FALSE0;
318
319 if (listInitialised)
320 return;
321 listInitialised = TRUE1;
322
323 /* Add built-in extensions to the list. */
324 LoadExtensionList(staticExtensions, ARRAY_SIZE(staticExtensions)(sizeof((staticExtensions)) / sizeof((staticExtensions)[0])), TRUE1);
325}
326
327void
328InitExtensions(int argc, char *argv[])
329{
330 int i;
331 ExtensionModule *ext;
332
333 AddStaticExtensions();
334
335 for (i = 0; i < numExtensionModules; i++) {
1
Assuming 'i' is < 'numExtensionModules'
2
Loop condition is true. Entering loop body
336 ext = &ExtensionModuleList[i];
3
Null pointer value stored to 'ext'
337 if (ext->initFunc != NULL((void*)0) &&
4
Access to field 'initFunc' results in a dereference of a null pointer (loaded from variable 'ext')
338 (ext->disablePtr == NULL((void*)0) || !*ext->disablePtr)) {
339 (ext->initFunc) ();
340 }
341 }
342}
343
344static ExtensionModule *
345NewExtensionModuleList(int size)
346{
347 ExtensionModule *save = ExtensionModuleList;
348 int n;
349
350 /* Sanity check */
351 if (!ExtensionModuleList)
352 numExtensionModules = 0;
353
354 n = numExtensionModules + size;
355 ExtensionModuleList = reallocarrayxreallocarray(ExtensionModuleList, n,
356 sizeof(ExtensionModule));
357 if (ExtensionModuleList == NULL((void*)0)) {
358 ExtensionModuleList = save;
359 return NULL((void*)0);
360 }
361 else {
362 numExtensionModules += size;
363 return ExtensionModuleList + (numExtensionModules - size);
364 }
365}
366
367void
368LoadExtensionList(const ExtensionModule ext[], int size, Bool builtin)
369{
370 ExtensionModule *newext;
371 int i;
372
373 /* Make sure built-in extensions get added to the list before those
374 * in modules. */
375 AddStaticExtensions();
376
377 if (!(newext = NewExtensionModuleList(size)))
378 return;
379
380 for (i = 0; i < size; i++, newext++) {
381 newext->name = ext[i].name;
382 newext->initFunc = ext[i].initFunc;
383 newext->disablePtr = ext[i].disablePtr;
384 }
385}