segfault in GCRYCTL_SET_THREAD_CBS

View: New views
3 Messages — Rating Filter:   Alert me  

segfault in GCRYCTL_SET_THREAD_CBS

by Daniel Kahn Gillmor-7 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The attached simple program tries to initialize gcrypt with pthread
support.  On my debian system (testing/unstable, libgcrypt11 1.4.4-4)
this triggers a segfault during the call to
gcry_control(GCRYCTL_SET_THREAD_CBS).

What am i doing wrong?  What have i missed?

        --dkg

#include <gcrypt.h>
#include <pthread.h>
#include <errno.h>
#include <stdio.h>


GCRY_THREAD_OPTION_PTHREAD_IMPL;

int main() {
  int val, ix;
  const char* ciphers[] = { "aes", "arcfour", "twofish", "des" };
  gcry_error_t ret;

  ret = gcry_control(GCRYCTL_SET_THREAD_CBS, gcry_threads_pthread);
  printf("%d: %s/%s\n",
         gcry_err_code(ret),
         gcry_strsource(ret),
         gcry_strerror(ret));
  if (!gcry_check_version (GCRYPT_VERSION))
    return 12;

  for (ix = 0; ix < sizeof(ciphers)/sizeof(ciphers[0]) ; ix++) {
    val = gcry_cipher_map_name (ciphers[ix]);
    printf("%s: %d\n", ciphers[ix], val);
  }

 return 0;
}

#!/usr/bin/make -f

main: main.c
        gcc -o main -g --pedantic -Wall `libgcrypt-config --cflags --libs` -lpthread main.c


_______________________________________________
Gcrypt-devel mailing list
Gcrypt-devel@...
http://lists.gnupg.org/mailman/listinfo/gcrypt-devel

signature.asc (909 bytes) Download Attachment

Re: segfault in GCRYCTL_SET_THREAD_CBS

by Werner Koch :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, 27 Oct 2009 23:50, dkg@... said:

-   ret = gcry_control(GCRYCTL_SET_THREAD_CBS, gcry_threads_pthread);
+   ret = gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);

This is the usual problem with general purpose ioctl-alike fucntions:
You don't have any type checking.  I added examples to the docs.

Salam-Shalom,

   Werner

--
Die Gedanken sind frei.  Ausnahmen regelt ein Bundesgesetz.


_______________________________________________
Gcrypt-devel mailing list
Gcrypt-devel@...
http://lists.gnupg.org/mailman/listinfo/gcrypt-devel

Re: segfault in GCRYCTL_SET_THREAD_CBS

by Daniel Kahn Gillmor-7 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 10/28/2009 09:54 AM, Werner Koch wrote:
> On Tue, 27 Oct 2009 23:50, dkg@... said:
>
> -   ret = gcry_control(GCRYCTL_SET_THREAD_CBS, gcry_threads_pthread);
> +   ret = gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
>
> This is the usual problem with general purpose ioctl-alike fucntions:
> You don't have any type checking.  I added examples to the docs.

Thanks, Werner.  That does fix it for me, and it seems obvious in
retrospect ;)  I suspect having the examples in the docs will be useful.

Regards,

        --dkg



_______________________________________________
Gcrypt-devel mailing list
Gcrypt-devel@...
http://lists.gnupg.org/mailman/listinfo/gcrypt-devel

signature.asc (909 bytes) Download Attachment