[LyX/master] Return false on invalid input in Font::fromString()

Juergen Spitzmueller spitz at lyx.org
Sun Jun 9 06:09:56 UTC 2024


commit 2a9648fc4c58a007f7ddb4012d608666f8cc2ec8
Author: Juergen Spitzmueller <spitz at lyx.org>
Date:   Sun Jun 9 08:09:01 2024 +0200

    Return false on invalid input in Font::fromString()
    
    Fixes crash with invalid font-update lfun
---
 src/Font.cpp | 12 ++++++++++++
 src/Text.cpp |  2 +-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/Font.cpp b/src/Font.cpp
index a4ae35727f..748a8df92c 100644
--- a/src/Font.cpp
+++ b/src/Font.cpp
@@ -695,18 +695,26 @@ bool Font::fromString(string const & data, bool & toggle)
 
 		if (token == "family") {
 			int const next = lex.getInteger();
+			if (next == -1)
+				return false;
 			bits_.setFamily(FontFamily(next));
 
 		} else if (token == "series") {
 			int const next = lex.getInteger();
+			if (next == -1)
+				return false;
 			bits_.setSeries(FontSeries(next));
 
 		} else if (token == "shape") {
 			int const next = lex.getInteger();
+			if (next == -1)
+				return false;
 			bits_.setShape(FontShape(next));
 
 		} else if (token == "size") {
 			int const next = lex.getInteger();
+			if (next == -1)
+				return false;
 			bits_.setSize(FontSize(next));
 		// FIXME: shall style be handled there? Probably not.
 		} else if (token == "emph" || token == "underbar"
@@ -716,6 +724,8 @@ bool Font::fromString(string const & data, bool & toggle)
 			|| token == "nospellcheck") {
 
 			int const next = lex.getInteger();
+			if (next == -1)
+				return false;
 			FontState const misc = FontState(next);
 
 			if (token == "emph")
@@ -739,6 +749,8 @@ bool Font::fromString(string const & data, bool & toggle)
 
 		} else if (token == "color") {
 			int const next = lex.getInteger();
+			if (next == -1)
+				return false;
 			bits_.setColor(ColorCode(next));
 
 		/**
diff --git a/src/Text.cpp b/src/Text.cpp
index f9c1037ad3..8b50d9e9cd 100644
--- a/src/Text.cpp
+++ b/src/Text.cpp
@@ -5989,7 +5989,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 			toggleAndShow(cur, this, font, toggleall);
 			cur.message(bformat(_("Text properties applied: %1$s"), props));
 		} else
-			LYXERR0("Invalid argument of textstyle-update");
+			cur.message(_("Invalid argument of textstyle-update"));
 		break;
 	}
 


More information about the lyx-cvs mailing list