tags 715857 + patch
stop

The cause of this bug is that eblook assumes that the
HOME environment variable is always set: it dereferences
the return value of getenv("HOME") without checking that
it is non-NULL.

You can easily reproduce the segfault by running
$ env -u HOME eblook

The following patch causes eblook to exit cleanly if
HOME is unset, rather than segfault. (This eliminates the
segfault without changing program behavior; alternatively,
it could use getpwent to locate the HOME directory)

--- eblook.c.orig
+++ eblook.c
@@ -133,6 +133,7 @@
 int pclose_pager (FILE *);
 #endif
 
+static char *get_homedir (void);
 char *read_command (char *, size_t, FILE *);
 int excute_command (char *);
 int parse_command_line (char *, char *[]);
@@ -494,7 +495,7 @@
         strcpy (buff, USER_INIT_FILE);
       }
 #else  /* !DOS_FILE_PATH */
-      strcpy (buff, getenv ("HOME"));
+      strcpy (buff, get_homedir ());
       strcat (buff, USER_INIT_FILE + 1);
 #endif /* DOS_FILE_PATH */
     } else {
@@ -519,7 +520,7 @@
        strcpy (buff, HIST_FILE);
       }
 #else  /* !DOS_FILE_PATH */
-      strcpy (buff, getenv ("HOME"));
+      strcpy (buff, get_homedir ());
       strcat (buff, HIST_FILE + 1);
 #endif /* DOS_FILE_PATH */
     } else {
@@ -647,6 +648,17 @@
   return 0;
 }
 
+static char *
+get_homedir (void)
+{
+  char *homedir = getenv ("HOME");
+  if (!homedir) {
+    xfprintf (stderr, "can't find home directory\n");
+    exit (1);
+  }
+  return homedir;
+}
+
 char *
 read_command (command_line, size, stream)
      char *command_line;


-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to