From 1a913bddd98eed5c7db902ef4ff26138112265b7 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Wed, 2 May 2018 21:21:07 +0100 Subject: [PATCH] Fix realpath() usage for nonexistant files. --- src/mosquitto_passwd.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/mosquitto_passwd.c b/src/mosquitto_passwd.c index 1b479a4f..33a1cc0b 100644 --- a/src/mosquitto_passwd.c +++ b/src/mosquitto_passwd.c @@ -444,8 +444,16 @@ int main(int argc, char *argv[]) #else password_file = realpath(password_file_tmp, NULL); if(!password_file){ - fprintf(stderr, "Error reading password file: %s\n", strerror(errno)); - return 1; + if(errno == ENOENT){ + password_file = strdup(password_file_tmp); + if(!password_file){ + fprintf(stderr, "Error: Out of memory.\n"); + return 1; + } + }else{ + fprintf(stderr, "Error reading password file: %s\n", strerror(errno)); + return 1; + } } #endif