]> git.neil.brown.name Git - edlib.git/commitdiff
lib-renderline: handle garbage better in cvt()
authorNeilBrown <neil@brown.name>
Sat, 19 Aug 2023 22:39:41 +0000 (08:39 +1000)
committerNeilBrown <neil@brown.name>
Sun, 20 Aug 2023 22:47:07 +0000 (08:47 +1000)
cvt() shouldn't assume a well-formatted string, and must always quite
when it sees EOL.

Signed-off-by: NeilBrown <neil@brown.name>
lib-renderline.c

index 1708c1b08129a03274f618b17ca3747df694d3f2..501155bf39acda7091016f01c6c15850a76d660c 100644 (file)
@@ -1229,15 +1229,18 @@ static char *cvt(char *str safe)
                if (c[0] != '<')
                        continue;
                if (c[1] == '/') {
-                       c[0] = ack;
-                       c[1] = ack;
-                       c[2] = etx;
-                       c += 2;
+                       while (*c && *c != '>')
+                               *c++ = ack;
+                       if (!*c)
+                               break;
+                       *c = etx;
                        continue;
                }
                c[0] = soh;
                while (c[0] && c[1] != '>')
                        c++;
+               if (!c[0])
+                       break;
                c[1] = stx;
        }
        return str;