[pacman-dev] System hook dir contains a double slash
Hi all. In `alpm_initialize`, there's sprintf(hookdir, "%s%s", myhandle->root, SYSHOOKDIR); where `SYSHOOKDIR` is by default `"/usr/share/libalpm/hooks/"` (defined by `-DSYSHOOKDIR=\"@datarootdir@/libalpm/hooks/\"` in `AM_CPPFLAGS`). This means that the resulting `hookdir` is `"//usr/share/libalpm/hooks/"`, or `"/something/else//usr/share/libalpm/hooks/"` if `--root /something/else` is passed on command line. If you need a reason for changing this (other than programmer's tidiness), know that this causes trouble in Cygwin/MSYS2 as paths starting with `//` have special meaning. I can send a patch, but I'm not sure what's the best way to change it. How about sprintf(hookdir, "%s%s", myhandle->root, SYSHOOKDIR + 1); with a corresponding change in the allocation above it and a comment explaining the magic number? It seems that `root` will always end in a slash and `SYSHOOKDIR` will always start with one, so I picked the one easier to remove. -- David Macek
On 26/11/15 08:19, David Macek wrote:
Hi all.
In `alpm_initialize`, there's
sprintf(hookdir, "%s%s", myhandle->root, SYSHOOKDIR);
where `SYSHOOKDIR` is by default `"/usr/share/libalpm/hooks/"` (defined by `-DSYSHOOKDIR=\"@datarootdir@/libalpm/hooks/\"` in `AM_CPPFLAGS`).
This means that the resulting `hookdir` is `"//usr/share/libalpm/hooks/"`, or `"/something/else//usr/share/libalpm/hooks/"` if `--root /something/else` is passed on command line.
If you need a reason for changing this (other than programmer's tidiness), know that this causes trouble in Cygwin/MSYS2 as paths starting with `//` have special meaning.
I can send a patch, but I'm not sure what's the best way to change it. How about
sprintf(hookdir, "%s%s", myhandle->root, SYSHOOKDIR + 1);
with a corresponding change in the allocation above it and a comment explaining the magic number? It seems that `root` will always end in a slash and `SYSHOOKDIR` will always start with one, so I picked the one easier to remove.
That seems fine. Adjust the malloc too. A
The path of the default system hook directory was created by concatenating `myhandle->root` (usually "/"), and SYSHOOKDIR (usually "/usr/share/libalpm/hooks/"), resulting in "//usr/share/libalpm/hooks/". Fix this by skipping the initial slash from SYSHOOKDIR. --- lib/libalpm/alpm.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c index 0798c0b..54dfade 100644 --- a/lib/libalpm/alpm.c +++ b/lib/libalpm/alpm.c @@ -65,8 +65,11 @@ alpm_handle_t SYMEXPORT *alpm_initialize(const char *root, const char *dbpath, goto cleanup; } - MALLOC(hookdir, strlen(myhandle->root) + strlen(SYSHOOKDIR) + 1, goto cleanup); - sprintf(hookdir, "%s%s", myhandle->root, SYSHOOKDIR); + /* to contatenate myhandle->root (ends with a slash) with SYSHOOKDIR (starts + * with a slash) correctly, we skip SYSHOOKDIR[0]; the regular +1 therefore + * disappears from the allocation */ + MALLOC(hookdir, strlen(myhandle->root) + strlen(SYSHOOKDIR), goto cleanup); + sprintf(hookdir, "%s%s", myhandle->root, SYSHOOKDIR + 1); myhandle->hookdirs = alpm_list_add(NULL, hookdir); /* set default database extension */ -- 2.6.2.windows.1 -- David Macek
participants (2)
-
Allan McRae
-
David Macek