gbranden pushed a commit to branch master
in repository groff.
commit 39745aee1c07cf0fb0b21cf0bacfc9946fd9e9f0
Author: G. Branden Robinson <[email protected]>
AuthorDate: Mon Nov 8 07:12:30 2021 +1100
[libgroff]: Make `strsave()` more robust.
* src/libs/libgroff/strsave.cpp (strsave): Call `strcpy()` only if
`malloc()` did not return a null pointer. Problem noted by Ingo
Schwarze.
Also update editor aid comments, dropping old-style Emacs file-local
variable.
---
ChangeLog | 6 ++++++
src/libs/libgroff/strsave.cpp | 9 +++++++--
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 9758a40..d8511fc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2021-11-08 G. Branden Robinson <[email protected]>
+
+ * src/libs/libgroff/strsave.cpp (strsave): Call `strcpy()` only
+ if `malloc()` did not return a null pointer. Problem noted by
+ Ingo Schwarze.
+
2021-11-07 G. Branden Robinson <[email protected]>
* src/libs/libgroff/fontfile.cpp (font::open_file): Don't open
diff --git a/src/libs/libgroff/strsave.cpp b/src/libs/libgroff/strsave.cpp
index 2b660a8..95a529b 100644
--- a/src/libs/libgroff/strsave.cpp
+++ b/src/libs/libgroff/strsave.cpp
@@ -1,4 +1,3 @@
-// -*- C++ -*-
/* Copyright (C) 1989-2020 Free Software Foundation, Inc.
Written by James Clark ([email protected])
@@ -29,7 +28,13 @@ char *strsave(const char *s)
if (s == 0)
return 0;
char *p = (char*)malloc(strlen(s) + 1);
- strcpy(p, s);
+ if (p != 0)
+ strcpy(p, s);
return p;
}
+// Local Variables:
+// fill-column: 72
+// mode: C++
+// End:
+// vim: set cindent noexpandtab shiftwidth=2 textwidth=72:
_______________________________________________
Groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit