terra-sync / cnc

Seamless Database Replication tool
GNU General Public License v3.0
4 stars 2 forks source link

log: fix path parsing #70

Closed panosfol closed 1 month ago

charmitro commented 1 month ago

Panagiotis Foliadis @.***> writes:

From e80fbe32e402f5dce38046a4c1b4636077f6f7ee Mon Sep 17 00:00:00 2001 From: Panagiotis Foliadis @.***> Date: Tue, 21 May 2024 21:27:09 +0300 Subject: [PATCH] log: fix path parsing

Add a check to make sure the user-defined logpath is correctly appended with the '/' character, which is needed for the correct creation of directories.

Signed-off-by: Panagiotis Foliadis @.***>

src/log.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/log.c b/src/log.c index 79ab8b8..f635782 100644 --- a/src/log.c +++ b/src/log.c @@ -69,7 +69,16 @@ int construct_log_filepath(const char *config_filepath, char **log_filepath) } else { // else we iterate through the path and create each parent directory needed char path[PATH_MAX + 1];

  • snprintf(path, sizeof(path), "%s", config_filepath);
  • int length;
  • /* This is to ensure that the user-provided path is correctly terminated with
    • the '/' character, which is needed to build the directories
  • */
  • length = snprintf(path, sizeof(path), "%s", config_filepath);
  • if (path[length - 1] != '/') {
  • strncat(path, "/", length);
  • }

This is redundant, we can just append our "/" and be done with it.

From the POSIX-Standard 1 we can see under "General Concepts" -> "Pathname Resolution" that, If a pathname begins with two successive characters, the first component following the leading characters may be interpreted in an implementation-defined manner, although more than two leading characters shall be treated as a single character.

+ if (*path != '/') { pr_error( "Please provide an absolute path for log filepath\n");