[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 10/15: [libgroff]: Validate device, font files more.
From: |
G. Branden Robinson |
Subject: |
[groff] 10/15: [libgroff]: Validate device, font files more. |
Date: |
Fri, 17 Sep 2021 05:34:38 -0400 (EDT) |
gbranden pushed a commit to branch master
in repository groff.
commit c0d1bb281908a6ed0b55d71cfc3c29b9750c29a2
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Fri Sep 17 15:55:26 2021 +1000
[libgroff]: Validate device, font files more.
[libgroff]: Increase validation of device and font description files.
* src/libs/libgroff/font.cpp (font::load): Validate the syntax and value
of the `name` directive.
(font::load_desc): Issue distinct diagnostics for a `fonts` directive
that is missing arguments and for a first argument that can't be
interpreted as a valid number.
---
ChangeLog | 11 +++++++++++
src/libs/libgroff/font.cpp | 19 +++++++++++++++++--
2 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 873eac9..ec8eeb3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
2021-09-17 G. Branden Robinson <g.branden.robinson@gmail.com>
+ [libgroff]: Increase validation of device and font description
+ files.
+
+ * src/libs/libgroff/font.cpp (font::load): Validate the syntax
+ and value of the `name` directive.
+ (font::load_desc): Issue distinct diagnostics for a `fonts`
+ directive that is missing arguments and for a first argument
+ that can't be interpreted as a valid number.
+
+2021-09-17 G. Branden Robinson <g.branden.robinson@gmail.com>
+
[libgroff]: Make error reporting more flexible.
* src/libs/libgroff/error.cpp (do_error_with_file_and_line):
diff --git a/src/libs/libgroff/font.cpp b/src/libs/libgroff/font.cpp
index 934565a..da8ca25 100644
--- a/src/libs/libgroff/font.cpp
+++ b/src/libs/libgroff/font.cpp
@@ -785,6 +785,16 @@ bool font::load(int *not_found, bool head_only)
while (t.next_line()) {
p = strtok(t.buf, WS);
if (strcmp(p, "name") == 0) {
+ p = strtok(0, WS);
+ if (0 == p) {
+ t.error("'name' directive requires an argument");
+ return false;
+ }
+ if (strcmp(p, name) != 0) {
+ t.error("font description file name '%1' does not match 'name'"
+ " argument '%2'", name, p);
+ return false;
+ }
}
else if (strcmp(p, "spacewidth") == 0) {
p = strtok(0, WS);
@@ -1070,8 +1080,13 @@ bool font::load_desc()
}
else if (strcmp("fonts", p) == 0) {
p = strtok(0, WS);
- if (0 == p || sscanf(p, "%d", &nfonts) != 1 || nfonts <= 0) {
- t.error("argument to 'fonts' directive missing or invalid");
+ if (0 == p) {
+ t.error("'fonts' directive requires arguments");
+ return false;
+ }
+ if (sscanf(p, "%d", &nfonts) != 1 || nfonts <= 0) {
+ t.error("expected first argument to 'fonts' directive to be a"
+ " nonnegative number, got '%1'", p);
return false;
}
font_name_table = (const char **)new char *[nfonts+1];
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 10/15: [libgroff]: Validate device, font files more.,
G. Branden Robinson <=