summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@samba.org>2012-12-10 14:06:32 +0100
committerGünther Deschner <gd@samba.org>2012-12-12 15:00:02 +0100
commitf670cae69d85a8bfc14ab7d9cd38ab0e568e6929 (patch)
treee6c84ab48043c9d53ae11e69b096fa016a1e9ad3
parent34a18865d6d2acd05e93fc728510896e69449d79 (diff)
downloadsamba-f670cae69d85a8bfc14ab7d9cd38ab0e568e6929.tar.gz
samba-f670cae69d85a8bfc14ab7d9cd38ab0e568e6929.tar.bz2
samba-f670cae69d85a8bfc14ab7d9cd38ab0e568e6929.zip
s3-utils: Correctly handle getenv() for the later system() call.
The returned string of getenv() has an unknown size. You need to store the result always in a char array with a certain size to make sure we don't feed tainted data to the next function call. Found by Coverity. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Günther Deschner <gd@samba.org>
-rw-r--r--source3/utils/interact.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/source3/utils/interact.c b/source3/utils/interact.c
index 39ec707176..6d753dd012 100644
--- a/source3/utils/interact.c
+++ b/source3/utils/interact.c
@@ -31,16 +31,19 @@
#include <termios.h>
static const char* get_editor(void) {
- static const char* editor = NULL;
- if (editor == NULL) {
- editor = getenv("VISUAL");
- if (editor == NULL) {
- editor = getenv("EDITOR");
+ static char editor[64] = {0};
+
+ if (editor[0] == '\0') {
+ const char *tmp = getenv("VISUAL");
+ if (tmp == NULL) {
+ tmp = getenv("EDITOR");
}
- if (editor == NULL) {
- editor = "vi";
+ if (tmp == NULL) {
+ tmp = "vi";
}
+ snprintf(editor, sizeof(editor), "%s", tmp);
}
+
return editor;
}