changeset 20593:996d7a50ea16

10186 uts: font functions should check if the char is from the input domain Reviewed by: Robert Mustacchi <rm@joyent.com> Reviewed by: Andy Fiddaman <andy@omniosce.org> Approved by: Dan McDonald <danmcd@joyent.com>
author Toomas Soome <tsoome@me.com>
date Thu, 26 Jan 2017 02:46:55 +0200
parents ed6a78345203
children 4c0bc9b71395
files usr/src/uts/common/font/font.c usr/src/uts/common/sys/font.h
diffstat 2 files changed, 28 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/uts/common/font/font.c	Sun Dec 16 15:02:15 2018 +0000
+++ b/usr/src/uts/common/font/font.c	Thu Jan 26 02:46:55 2017 +0200
@@ -25,7 +25,7 @@
  */
 
 /*
- * Copyright 2017 Toomas Soome <tsoome@me.com>
+ * Copyright 2019 Toomas Soome <tsoome@me.com>
  */
 
 /*
@@ -126,7 +126,7 @@
 font_bit_to_pix4(
     struct font *f,
     uint8_t *dest,
-    uint8_t c,
+    uint32_t c,
     uint8_t fg_color,
     uint8_t bg_color)
 {
@@ -138,6 +138,9 @@
 	uint8_t	nibblett;
 	int	bytes_wide;
 
+	if (c >= ENCODED_CHARS)
+		c = '?';
+
 	cp = f->char_ptr[c];
 	bytes_wide = (f->width + 7) / 8;
 
@@ -179,7 +182,7 @@
 font_bit_to_pix8(
     struct font *f,
     uint8_t *dest,
-    uint8_t c,
+    uint32_t c,
     uint8_t fg_color,
     uint8_t bg_color)
 {
@@ -192,6 +195,9 @@
 	uint8_t	mask;
 	int	bitsleft, nbits;
 
+	if (c >= ENCODED_CHARS)
+		c = '?';
+
 	cp = f->char_ptr[c];
 	bytes_wide = (f->width + 7) / 8;
 
@@ -234,7 +240,7 @@
 font_bit_to_pix16(
     struct font *f,
     uint16_t *dest,
-    uint8_t c,
+    uint32_t c,
     uint16_t fg_color16,
     uint16_t bg_color16)
 {
@@ -246,6 +252,9 @@
 	int	bytes_wide;
 	int	bitsleft, nbits;
 
+	if (c >= ENCODED_CHARS)
+		c = '?';
+
 	cp = f->char_ptr[c];
 	bytes_wide = (f->width + 7) / 8;
 
@@ -288,7 +297,7 @@
 font_bit_to_pix24(
     struct font *f,
     uint8_t *dest,
-    uint8_t c,
+    uint32_t c,
     uint32_t fg_color32,
     uint32_t bg_color32)
 {
@@ -300,6 +309,9 @@
 	int	bytes_wide;
 	int	bitsleft, nbits;
 
+	if (c >= ENCODED_CHARS)
+		c = '?';
+
 	cp = f->char_ptr[c];
 	bytes_wide = (f->width + 7) / 8;
 
@@ -346,7 +358,7 @@
 font_bit_to_pix32(
     struct font *f,
     uint32_t *dest,
-    uint8_t c,
+    uint32_t c,
     uint32_t fg_color32,
     uint32_t bg_color32)
 {
@@ -358,6 +370,9 @@
 	int	bytes_wide;
 	int	bitsleft, nbits;
 
+	if (c >= ENCODED_CHARS)
+		c = '?';
+
 	cp = f->char_ptr[c];
 	bytes_wide = (f->width + 7) / 8;
 
--- a/usr/src/uts/common/sys/font.h	Sun Dec 16 15:02:15 2018 +0000
+++ b/usr/src/uts/common/sys/font.h	Thu Jan 26 02:46:55 2017 +0200
@@ -22,6 +22,7 @@
 /*
  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
+ * Copyright 2019 Toomas Soome <tsoome@me.com>
  */
 
 #ifndef _SYS_FONT_H
@@ -42,7 +43,7 @@
 struct font {
 	short	width;
 	short	height;
-	uchar_t	*char_ptr[ENCODED_CHARS];
+	uint8_t	*char_ptr[ENCODED_CHARS];
 	void	*image_data;
 };
 
@@ -71,11 +72,11 @@
 extern bitmap_data_t font_data_6x10;
 
 void set_font(struct font *, short *, short *, short, short);
-void font_bit_to_pix4(struct font *, uint8_t *, uint8_t, uint8_t, uint8_t);
-void font_bit_to_pix8(struct font *, uint8_t *, uint8_t, uint8_t, uint8_t);
-void font_bit_to_pix16(struct font *, uint16_t *, uint8_t, uint16_t, uint16_t);
-void font_bit_to_pix24(struct font *, uint8_t *, uint8_t, uint32_t, uint32_t);
-void font_bit_to_pix32(struct font *, uint32_t *, uint8_t, uint32_t, uint32_t);
+void font_bit_to_pix4(struct font *, uint8_t *, uint32_t, uint8_t, uint8_t);
+void font_bit_to_pix8(struct font *, uint8_t *, uint32_t, uint8_t, uint8_t);
+void font_bit_to_pix16(struct font *, uint16_t *, uint32_t, uint16_t, uint16_t);
+void font_bit_to_pix24(struct font *, uint8_t *, uint32_t, uint32_t, uint32_t);
+void font_bit_to_pix32(struct font *, uint32_t *, uint32_t, uint32_t, uint32_t);
 
 #ifdef __cplusplus
 }