Module Name:    src
Committed By:   christos
Date:           Sun Nov  8 16:49:21 UTC 2015

Modified Files:
        src/sys/dev/wscons: wsdisplay_vcons.c

Log Message:
PR/50413: Vicente Chaves: Check the allocattr return and return an error.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/dev/wscons/wsdisplay_vcons.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/wscons/wsdisplay_vcons.c
diff -u src/sys/dev/wscons/wsdisplay_vcons.c:1.34 src/sys/dev/wscons/wsdisplay_vcons.c:1.35
--- src/sys/dev/wscons/wsdisplay_vcons.c:1.34	Sun Jul 19 09:22:42 2015
+++ src/sys/dev/wscons/wsdisplay_vcons.c	Sun Nov  8 11:49:20 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: wsdisplay_vcons.c,v 1.34 2015/07/19 13:22:42 mlelstv Exp $ */
+/*	$NetBSD: wsdisplay_vcons.c,v 1.35 2015/11/08 16:49:20 christos Exp $ */
 
 /*-
  * Copyright (c) 2005, 2006 Michael Lorenz
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: wsdisplay_vcons.c,v 1.34 2015/07/19 13:22:42 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wsdisplay_vcons.c,v 1.35 2015/11/08 16:49:20 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -285,15 +285,21 @@ vcons_init_screen(struct vcons_data *vd,
 #else
 	cnt = ri->ri_rows * ri->ri_cols;
 #endif
-	scr->scr_attrs = (long *)malloc(cnt * (sizeof(long) + 
+	scr->scr_attrs = malloc(cnt * (sizeof(long) + 
 	    sizeof(uint32_t)), M_DEVBUF, M_WAITOK);
 	if (scr->scr_attrs == NULL)
 		return ENOMEM;
 
 	scr->scr_chars = (uint32_t *)&scr->scr_attrs[cnt];
 
-	ri->ri_ops.allocattr(ri, WS_DEFAULT_FG, WS_DEFAULT_BG, 0, defattr);
-	scr->scr_defattr = *defattr;
+	i = ri->ri_ops.allocattr(ri, WS_DEFAULT_FG, WS_DEFAULT_BG, 0, defattr);
+	if (i != 0) {
+#ifdef DIAGNOSTIC
+		printf("vcons: error allocating attribute %d\n", i);
+#endif
+		scr->scr_defattr = 0;
+	} else
+		scr->scr_defattr = *defattr;
 
 	/* 
 	 * fill the attribute buffer with *defattr, chars with 0x20 
@@ -1140,6 +1146,7 @@ vcons_putwschar(struct vcons_screen *scr
 {
 	long attr;
 	struct rasops_info *ri;
+	int error;
 
 	KASSERT(scr != NULL && wsc != NULL);
 
@@ -1152,8 +1159,10 @@ vcons_putwschar(struct vcons_screen *scr
 	if ((wsc->row >= 0) && (wsc->row < ri->ri_rows) && (wsc->col >= 0) && 
 	     (wsc->col < ri->ri_cols)) {
 
-		ri->ri_ops.allocattr(ri, wsc->foreground, wsc->background,
-		    wsc->flags, &attr);
+		error = ri->ri_ops.allocattr(ri, wsc->foreground,
+		    wsc->background, wsc->flags, &attr);
+		if (error)
+			return error;
 		vcons_putchar(ri, wsc->row, wsc->col, wsc->letter, attr);
 #ifdef VCONS_DEBUG
 		printf("vcons_putwschar(%d, %d, %x, %lx\n", wsc->row, wsc->col,

Reply via email to