s3-utils: Correctly handle getenv() for the later system() call.
authorAndreas Schneider <asn@samba.org>
Mon, 10 Dec 2012 13:06:32 +0000 (14:06 +0100)
committerGünther Deschner <gd@samba.org>
Wed, 12 Dec 2012 14:00:02 +0000 (15:00 +0100)
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>
source3/utils/interact.c

index 39ec7071760960ee451aa5c78a49cfc3172bf810..6d753dd012eb1d0b9c82e600a8641f1983916baa 100644 (file)
 #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;
 }