linux-fbdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yiyuan GUO <yguoaz@gmail.com>
To: deller@gmx.de
Cc: geert@linux-m68k.org, linux-parisc@vger.kernel.org,
	dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org,
	yguoaz@gmail.com
Subject: [PATCH v2] video/logo: protect against divide by zero when reading image
Date: Thu, 13 May 2021 19:42:09 +0800	[thread overview]
Message-ID: <20210513114209.60457-1-yguoaz@gmail.com> (raw)
In-Reply-To: <alpine.DEB.2.22.394.2105121353530.1204552@ramsan.of.borg>

In video/logo/pnmtologo.c, the function read_image can read from the
image file an integer 0 and pass it to function get_number255, leading
to a divide by zero problem.

Signed-off-by: Yiyuan GUO <yguoaz@gmail.com>
---
 drivers/video/logo/pnmtologo.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/video/logo/pnmtologo.c b/drivers/video/logo/pnmtologo.c
index 4718d7895..d9e8d1d5b 100644
--- a/drivers/video/logo/pnmtologo.c
+++ b/drivers/video/logo/pnmtologo.c
@@ -116,6 +116,16 @@ static unsigned int get_number(FILE *fp)
     return val;
 }
 
+static unsigned int get_maxval(FILE *fp)
+{
+    unsigned int maxval = get_number(fp);
+
+    if (!maxval)
+	die("%s: invalid maxval zero\n", filename);
+
+    return maxval;
+}
+
 static unsigned int get_number255(FILE *fp, unsigned int maxval)
 {
     unsigned int val = get_number(fp);
@@ -182,7 +192,7 @@ static void read_image(void)
 
 	case '2':
 	    /* Plain PGM */
-	    maxval = get_number(fp);
+	    maxval = get_maxval(fp);
 	    for (i = 0; i < logo_height; i++)
 		for (j = 0; j < logo_width; j++)
 		    logo_data[i][j].red = logo_data[i][j].green =
@@ -191,7 +201,7 @@ static void read_image(void)
 
 	case '3':
 	    /* Plain PPM */
-	    maxval = get_number(fp);
+	    maxval = get_maxval(fp);
 	    for (i = 0; i < logo_height; i++)
 		for (j = 0; j < logo_width; j++) {
 		    logo_data[i][j].red = get_number255(fp, maxval);
-- 
2.25.1


      reply	other threads:[~2021-05-13 11:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20210512054843.54883-1-yguoaz@gmail.com>
2021-05-12 12:03 ` [PATCH] " Geert Uytterhoeven
2021-05-13 11:42   ` Yiyuan GUO [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210513114209.60457-1-yguoaz@gmail.com \
    --to=yguoaz@gmail.com \
    --cc=deller@gmx.de \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=geert@linux-m68k.org \
    --cc=linux-fbdev@vger.kernel.org \
    --cc=linux-parisc@vger.kernel.org \
    --subject='Re: [PATCH v2] video/logo: protect against divide by zero when reading image' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).