From 9f4b4c975a5425eaabcc6e10e432d86a3d26fb83 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Sat, 4 Jun 2016 09:30:41 +0200 Subject: [PATCH] files: prevent dereferencing a possible (although very unlikely) NULL Don't catch the NULL earlier, because we do want an error message when opening the lockfile fails. --- src/files.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/files.c b/src/files.c index 4da3aeba..ccf1f2a2 100644 --- a/src/files.c +++ b/src/files.c @@ -252,7 +252,8 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi snprintf(&lockdata[2], 11, "nano %s", VERSION); strncpy(&lockdata[28], mypwuid->pw_name, 16); strncpy(&lockdata[68], myhostname, 31); - strncpy(&lockdata[108], origfilename, 768); + if (origfilename != NULL) + strncpy(&lockdata[108], origfilename, 768); if (modified == TRUE) lockdata[1007] = 0x55;