[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 15/17: [libgroff]: Clear string storage before using it.
From: |
G. Branden Robinson |
Subject: |
[groff] 15/17: [libgroff]: Clear string storage before using it. |
Date: |
Sat, 17 Feb 2024 22:08:44 -0500 (EST) |
gbranden pushed a commit to branch master
in repository groff.
commit 6f3a812c03728bca15faaec3466b241c1beb0464
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Sat Feb 17 18:25:27 2024 -0600
[libgroff]: Clear string storage before using it.
* src/libs/libgroff/string.cpp (string::string): When constructing a new
string from a pointer to char, if the pointed-to-string doesn't
exactly fit the storage reserved for it, populate the storage with
nulls bytes before copying, to avoid reads of garbage heap memory.
While debugging, I was seeing stuff like this and it worried me.
grops:<standard input>:4: debug: GBR: created new font resource
'ZapfDingbats-ReversemU'
grops:<standard input>:4: debug: GBR: created new font resource
'Symbol-Slanted'
grops:<standard input>:4: debug: GBR: created new font resource
'FreeEuro�뭨�'
grops:<standard input>:4: debug: GBR: created new font resource
'Symbol-Slanted'
grops:<standard input>:4: debug: GBR: created new font resource
'ZapfDingbats-Reverse'
grops:<standard input>:4: debug: GBR: created new font resource
'FreeEuro�kJø¿½'
grops:<standard input>:4: debug: GBR: created new font resource
'Symbol-Slanted'
grops:<standard input>:4: debug: GBR: created new font resource
'ZapfDingbats-Reverse'
grops:<standard input>:4: debug: GBR: created new font resource
'FreeEuro�kա'
grops:<standard input>:4: debug: GBR: created new font resource
'Symbol-Slanted'
grops:<standard input>:4: debug: GBR: created new font resource
'ZapfDingbats-Reverse'
grops:<standard input>:4: debug: GBR: created new font resource
'FreeEuro�KH�q'
As shown, the garbage bytes change with each run of grops.
It seems like sooner or later, something bad will come of that.
Now, the same messages look like this, consistently:
grops:<standard input>:4: debug: GBR: created new font resource
'ZapfDingbats-Reverse'
grops:<standard input>:4: debug: GBR: created new font resource
'Symbol-Slanted'
grops:<standard input>:4: debug: GBR: created new font resource 'FreeEuro'
---
ChangeLog | 8 ++++++++
src/libs/libgroff/string.cpp | 2 ++
2 files changed, 10 insertions(+)
diff --git a/ChangeLog b/ChangeLog
index 8891546ea..ca1390983 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-02-17 G. Branden Robinson <g.branden.robinson@gmail.com>
+
+ * src/libs/libgroff/string.cpp (string::string): When
+ constructing a new string from a pointer to char, if the
+ pointed-to-string doesn't exactly fit the storage reserved for
+ it, populate the storage with nulls bytes before copying, to
+ avoid reads of garbage heap memory.
+
2024-02-17 G. Branden Robinson <g.branden.robinson@gmail.com>
* src/devices/grops/psrm.cpp (resource::resource): Spell "file
diff --git a/src/libs/libgroff/string.cpp b/src/libs/libgroff/string.cpp
index 0633db526..b62e131bb 100644
--- a/src/libs/libgroff/string.cpp
+++ b/src/libs/libgroff/string.cpp
@@ -103,6 +103,8 @@ string::string(const char *p)
else {
len = strlen(p);
ptr = salloc(len, &sz);
+ if (len < sz)
+ memset(ptr, 0, sz);
if (len != 0)
memcpy(ptr, p, len);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 15/17: [libgroff]: Clear string storage before using it.,
G. Branden Robinson <=