Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed path expansion for gpg_home_dir

  • Loading branch information...
commit 8ea634463285b89d1881744c4d9af8aba3330369 1 parent 8ee1931
@akerl authored
Showing with 10 additions and 0 deletions.
  1. +10 −0 lib/fko_encryption.c
View
10 lib/fko_encryption.c
@@ -32,6 +32,7 @@
#include "fko.h"
#include "cipher_funcs.h"
#include "base64.h"
+#include <wordexp.h>
#if HAVE_LIBGPGME
#include "gpgme_funcs.h"
@@ -653,6 +654,14 @@ fko_set_gpg_home_dir(fko_ctx_t ctx, const char *gpg_home_dir)
if(!CTX_INITIALIZED(ctx))
return(FKO_ERROR_CTX_NOT_INITIALIZED);
+ /* Ensure we're working with the expanded path
+ */
+ wordexp_t expanded_form;
+ if( !wordexp(gpg_home_dir, &expanded_form, WRDE_SHOWERR) ){
+ gpg_home_dir = strdup(expanded_form.we_wordv[0]);
+ wordfree(&expanded_form);
+ }
+
/* If we are unable to stat the given dir, then return with error.
*/
if(stat(gpg_home_dir, &st) != 0)
@@ -662,6 +671,7 @@ fko_set_gpg_home_dir(fko_ctx_t ctx, const char *gpg_home_dir)
return(FKO_ERROR_GPGME_BAD_HOME_DIR);
ctx->gpg_home_dir = strdup(gpg_home_dir);
+ free(gpg_home_dir);
if(ctx->gpg_home_dir == NULL)
return(FKO_ERROR_MEMORY_ALLOCATION);

1 comment on commit 8ea6344

@mrash

Hello Les,

Minor comment on the above - gpg_home_dir doesn't point to heap allocated memory, so calling free() against it results in the following from valgrind:

Invalid free() / delete / delete[] / realloc()
at 0x4C2A739: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x4E36ED3: fko_set_gpg_home_dir (fko_encryption.c:665)
by 0x10AC29: main (fwknop.c:243)
Address 0x7feffeee4 is on thread 1's stack

Please sign in to comment.
Something went wrong with that request. Please try again.