diff --git a/hw/xfree86/common/xf86cmap.c b/hw/xfree86/common/xf86cmap.c
index 08f557c..d88bbbb 100644
--- a/hw/xfree86/common/xf86cmap.c
+++ b/hw/xfree86/common/xf86cmap.c
@@ -1002,7 +1002,13 @@ xf86ChangeGammaRamp(
 
     if (xf86_crtc_supports_gamma(pScrn)) {
 	xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
-	RRCrtcPtr crtc = config->output[config->compat_output]->crtc->randr_crtc;
+	xf86OutputPtr output = config->output[config->compat_output];
+	RRCrtcPtr crtc;
+
+	if (!output || !output->crtc || !output->crtc->randr_crtc)
+	    return BadValue;
+
+	crtc = output->crtc->randr_crtc;
 
 	if (crtc->gammaSize != size)
 	    return BadValue;
@@ -1075,9 +1081,12 @@ xf86GetGammaRampSize(ScreenPtr pScreen)
 
     if (xf86_crtc_supports_gamma(pScrn)) {
 	xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
-	RRCrtcPtr crtc = config->output[config->compat_output]->crtc->randr_crtc;
+	xf86OutputPtr output = config->output[config->compat_output];
+
+	if (!output || !output->crtc || !output->crtc->randr_crtc)
+	    return 0;
 
-	return crtc->gammaSize;
+	return output->crtc->randr_crtc->gammaSize;
     }
 
     if(CMapScreenKey == NULL) return 0;
@@ -1104,7 +1113,13 @@ xf86GetGammaRamp(
 
     if (xf86_crtc_supports_gamma(pScrn)) {
 	xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
-	RRCrtcPtr crtc = config->output[config->compat_output]->crtc->randr_crtc;
+	xf86OutputPtr output = config->output[config->compat_output];
+	RRCrtcPtr crtc;
+
+	if (!output || !output->crtc || !output->crtc->randr_crtc)
+	    return BadValue;
+
+	crtc = output->crtc->randr_crtc;
 
 	if (crtc->gammaSize < size)
 	    return BadValue;
diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c
index 6ea9d26..df55b1a 100644
--- a/hw/xfree86/modes/xf86RandR12.c
+++ b/hw/xfree86/modes/xf86RandR12.c
@@ -1715,9 +1715,15 @@ xf86RandR12ChangeGamma(int scrnIndex, Gamma gamma)
     CARD16 *points, *red, *green, *blue;
     ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
     xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
-    RRCrtcPtr crtc = config->output[config->compat_output]->crtc->randr_crtc;
-    int size = max(0, crtc->gammaSize);
+    xf86OutputPtr output = config->output[config->compat_output];
+    RRCrtcPtr crtc;
+    int size;
 
+    if (!output || !output->crtc || !output->crtc->randr_crtc)
+	return Success;
+
+    crtc = output->crtc->randr_crtc;
+    size = max(0, crtc->gammaSize);
     if (!size)
 	return Success;