From 4169f7f2c20034a1886ff9a2e76a0daf76907363 Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Tue, 17 Apr 2007 03:43:59 +0000 Subject: [PATCH] in get_real_dir_from_tilde(), fix segfault when dealing with directory names that begin with "~", but that aren't users' home directories git-svn-id: svn://svn.savannah.gnu.org/nano/branches/nano_2_0_branch/nano@4072 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 5 +++++ src/files.c | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 114faac4..546e7078 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,9 @@ CVS code - +- files.c: + get_real_dir_from_tilde() + - Fix segfault when dealing with directory names that begin with + "~", but that aren't users' home directories. (DLR, found by + Justin Fletcher) - doc/syntax/asm.nanorc, doc/syntax/c.nanorc, doc/syntax/sh.nanorc: - Copy the regex that highlights trailing whitespace from doc/syntax/java.nanorc to these files, as it's also useful in diff --git a/src/files.c b/src/files.c index 90060277..68d760e6 100644 --- a/src/files.c +++ b/src/files.c @@ -1979,7 +1979,7 @@ char *real_dir_from_tilde(const char *buf) if (buf[0] == '~') { size_t i; - const char *tilde_dir; + const char *tilde_dir = NULL; /* Figure out how much of the str we need to compare. */ for (i = 1; buf[i] != '/' && buf[i] != '\0'; i++) @@ -1997,7 +1997,8 @@ char *real_dir_from_tilde(const char *buf) } while (userdata != NULL && strncmp(userdata->pw_name, buf + 1, i - 1) != 0); endpwent(); - tilde_dir = userdata->pw_dir; + if (userdata != NULL) + tilde_dir = userdata->pw_dir; } if (tilde_dir != NULL) { -- 2.39.5