From ef5a2506702b79fadc8fee465231861cc20845ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Tue, 27 Apr 2021 12:13:33 +0300 Subject: [PATCH] Unify handling of getcwd(3) failure and don't rely on buffer contents after failed call --- chimera/head.c | 2 +- chimera/main.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/chimera/head.c b/chimera/head.c index f75fb45..70fc413 100644 --- a/chimera/head.c +++ b/chimera/head.c @@ -735,7 +735,7 @@ ChimeraRequest *lastresort; if (getcwd( base_url + 5, sizeof(base_url) - 5 ) == NULL) { perror("getcwd failed"); // Try using just the root of filesystem if we could not get cwd - strcat( base_url, "/" ) ; + strcpy( base_url + 5, "/" ) ; } strcat( base_url, "/" ) ; diff --git a/chimera/main.c b/chimera/main.c index d22f0c2..1ec1d13 100644 --- a/chimera/main.c +++ b/chimera/main.c @@ -79,7 +79,8 @@ char **argv; strcpy( base_url, "file:" ) ; if (getcwd( base_url + 5, sizeof(base_url) - 5 ) == NULL) { perror("getcwd failed"); - return 1; + // Try using just the root of filesystem if we could not get cwd + strcpy( base_url + 5, "/"); } strcat( base_url, "/" ) ;