]> granicus.if.org Git - procps-ng/commitdiff
top: properly handle an improper $HOME environment variable
authorJim Warner <james.warner@comcast.net>
Fri, 13 Jan 2012 22:07:40 +0000 (16:07 -0600)
committerCraig Small <csmall@enc.com.au>
Wed, 8 Feb 2012 09:57:30 +0000 (20:57 +1100)
Since its inception, this top has improperly handled an
empty HOME environment variable.  Under those conditions
a path to the root directory would have been constructed.

That caused no real harm upon startup since the display
defaults would have been employed.  However, except for
root, it would have been impossible to save the rc file.

This commit keeps the promise made in the documentation.

top/top.c

index ae0596571cfbecede295aff9dbd066a6bc2ef370..856d856068bd942aaa65a44773f33e0fe25df483 100644 (file)
--- a/top/top.c
+++ b/top/top.c
@@ -2148,13 +2148,13 @@ static void configs_read (void) {
    RCF_t rcdef = DEF_RCFILE;
 #endif
    float tmp_delay = DEF_DELAY;
-   char fbuf[LRGBUFSIZ];
+   char fbuf[LRGBUFSIZ], *p;
    FILE *fp;
    int i, x;
    char id;
 
-   if (!getenv("HOME")) snprintf(Rc_name, sizeof(Rc_name), ".%src", Myname);
-   else snprintf(Rc_name, sizeof(Rc_name), "%s/.%src", getenv("HOME"), Myname);
+   p = getenv("HOME");
+   snprintf(Rc_name, sizeof(Rc_name), "%s/.%src", (p && *p) ? p : ".", Myname);
 
    fp = fopen(SYS_RCFILESPEC, "r");
    if (fp) {