This is an automatic generated email to let you know that the following patch 
were queued:

Subject: edid-decode: fix extract_string(): check for non-space after newline
Author:  Hans Verkuil <hverkuil-ci...@xs4all.nl>
Date:    Mon Jan 29 12:51:11 2024 +0100

The newline character is supposed to terminate the string and
the remainder should be padded with spaces. But some EDIDs
have more text after the newline, which is invalid. It is
probably an attempt to have two lines of text.

Check for this specific case and issue a warning.

Signed-off-by: Hans Verkuil <hverkuil-ci...@xs4all.nl>

 parse-base-block.cpp | 30 ++++++++++++++----------------
 1 file changed, 14 insertions(+), 16 deletions(-)

---

diff --git a/parse-base-block.cpp b/parse-base-block.cpp
index fc0c1b19c7f2..192b6896c006 100644
--- a/parse-base-block.cpp
+++ b/parse-base-block.cpp
@@ -493,29 +493,27 @@ void edid_state::detailed_cvt_descriptor(const char 
*prefix, const unsigned char
 char *extract_string(const unsigned char *x, unsigned len)
 {
        static char s[EDID_PAGE_SIZE];
-       int seen_newline = 0;
+       bool seen_newline = false;
        unsigned i;
 
        memset(s, 0, sizeof(s));
 
        for (i = 0; i < len; i++) {
-               if (isgraph(x[i])) {
-                       s[i] = x[i];
-               } else if (!seen_newline) {
-                       if (x[i] == 0x0a) {
-                               seen_newline = 1;
-                               if (!i)
-                                       fail("Empty string.\n");
-                               else if (s[i - 1] == 0x20)
-                                       fail("One or more trailing spaces.\n");
-                       } else if (x[i] == 0x20) {
-                               s[i] = x[i];
-                       } else {
-                               fail("Non-printable character.\n");
+               if (seen_newline) {
+                       if (x[i] != 0x20) {
+                               fail("Non-space after newline.\n");
                                return s;
                        }
-               } else if (x[i] != 0x20) {
-                       fail("Non-space after newline.\n");
+               } else if (isgraph(x[i]) || x[i] == 0x20) {
+                       s[i] = x[i];
+               } else if (x[i] == 0x0a) {
+                       seen_newline = true;
+                       if (!i)
+                               fail("Empty string.\n");
+                       else if (s[i - 1] == 0x20)
+                               fail("One or more trailing spaces.\n");
+               } else {
+                       fail("Non-printable character.\n");
                        return s;
                }
        }
_______________________________________________
linuxtv-commits mailing list -- linuxtv-commits@linuxtv.org
To unsubscribe send an email to linuxtv-commits-le...@linuxtv.org
%(web_page_url)slistinfo/%(_internal_name)s

Reply via email to