[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 25/29: src/libs/libgroff/string.cpp: Check malloc return.
From: |
G. Branden Robinson |
Subject: |
[groff] 25/29: src/libs/libgroff/string.cpp: Check malloc return. |
Date: |
Tue, 26 Apr 2022 06:40:19 -0400 (EDT) |
gbranden pushed a commit to branch master
in repository groff.
commit 36edfbadb0edf858d638cd2ed3c793566e545789
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Tue Apr 26 11:12:54 2022 +1000
src/libs/libgroff/string.cpp: Check malloc return.
* src/libs/libgroff/string.cpp (string::extract): Check return value of
`malloc()` for nullity, and only poke into the buffer returned if it
is valid. Discovered while troubleshooting Savannah #62366.
Also update editor aid comments; drop old-style Emacs file-local
variable setting.
---
ChangeLog | 7 +++++++
src/libs/libgroff/string.cpp | 18 ++++++++++++------
2 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 208c4104..a82860f8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2022-04-26 G. Branden Robinson <g.branden.robinson@gmail.com>
+
+ * src/libs/libgroff/string.cpp (string::extract): Check return
+ value of `malloc()` for nullity, and only poke into the buffer
+ returned if it is valid. Discovered while troubleshooting
+ Savannah #62366.
+
2022-04-23 Bertrand Garrigues <bertrand.garrigues@laposte.net>
gnulib: replace non-recursive-gnulib-prefix-hack with
diff --git a/src/libs/libgroff/string.cpp b/src/libs/libgroff/string.cpp
index 2392d16e..33c0565c 100644
--- a/src/libs/libgroff/string.cpp
+++ b/src/libs/libgroff/string.cpp
@@ -1,4 +1,3 @@
-// -*- C++ -*-
/* Copyright (C) 1989-2020 Free Software Foundation, Inc.
Written by James Clark (jjc@jclark.com)
@@ -293,11 +292,13 @@ char *string::extract() const
if (p[i] == '\0')
nnuls++;
char *q =(char*)malloc(n + 1 - nnuls);
- char *r = q;
- for (i = 0; i < n; i++)
- if (p[i] != '\0')
- *r++ = p[i];
- *r = '\0';
+ if (q != 0 /* nullptr */) {
+ char *r = q;
+ for (i = 0; i < n; i++)
+ if (p[i] != '\0')
+ *r++ = p[i];
+ *r = '\0';
+ }
return q;
}
@@ -346,3 +347,8 @@ string as_string(int i)
return string(buf);
}
+// Local Variables:
+// fill-column: 72
+// mode: C++
+// End:
+// vim: set cindent noexpandtab shiftwidth=2 textwidth=72:
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 25/29: src/libs/libgroff/string.cpp: Check malloc return.,
G. Branden Robinson <=