Invalid return from gpgme_op_keylist_next() + more

Werner Koch wk at
Wed Jun 25 03:20:50 CEST 2008

On Wed, 25 Jun 2008 01:35, nico-gnupg-dev-0 at said:

> C8697FED921C4699: nico schottelius <telmich at eof-1> (0)
> err=117456895

$ gpg-error 117456895
117456895 = (7, 16383) = (GPG_ERR_SOURCE_GPGME, GPG_ERR_EOF) = (GPGME, End of file)

>    gerr = gpgme_op_keylist_start(g_context, "nico schottelius", 0);
>    if(gerr != GPG_ERR_NO_ERROR) return 11;

It is better to write

     if (!gerr)
        return MAGIC_NUMBER;

But well it is a bit of personal taste.

>    i=0;
>    while((gerr = gpgme_op_keylist_next(g_context, &g_recipient[0])) !=
>    GPG_ERR_EOF) {

Replace this by:

     while ( (gerr = gpgme_op_keylist_next(g_context, &g_recipient[0])),
             gpg_err_code (gerr) != GPG_ERR_EOF )

>       printf("err=%d\n", gerr);
>       if(gerr == GPG_ERR_INV_VALUE) {
>          printf("invalid pointer\n");
>          return 15;
>       } else if(gerr == GPG_ERR_ENOMEM) {
>          printf("no mem\n");
>          return 16;
>       }
>       printf ("%s: %s <%s> (%d)\n", g_recipient[0]->subkeys->keyid, g_recipient[0]->uids->name, g_recipient[0]->uids->email, i);

You missed to check all return cods, thus the dereference segfaults.

> Why does gpgme_op_keylist_next return 117456895? Looks like something is overwritten.

A gpg-error code is made up of an error location and the error number,
thus you need to use gpg_err_code() to extract the error code.

> Btw, in the infopage on my Debian lenny system of gpgme is no success return
> code for gpgme_op_keylist_start() documentated.

Success is always 0.

> Additionally, there is a broken example in the infopage:

Thanks for noting.  I have fixed the example.  It still used the old API.

> - why are there contextless and contextdependent functions? it would make life easier
>   to have only contextdependent functions -> less confusing

I do not understand what you mean.  If we need a context we use a
context, if there is no need for a context we don't require a dummy

> - I am missing really simple functions. Imho encrypting a text for a person
>   should be possible in two lines of code:
>    gpgme_init(&context);
>    gpgme_encrypt(context, char *fingerprint, void *datain, gpgme_data_t *dataencrypted)

Crypto is not that easy and hackers like to come up with there own code;
we don't want to bore them :-).

> - The documentation is missing a 5 minutes tutorial, that explains how to
>    sign, encrypt, both,
>    check sig, decrypt, both

You can't do that in 5 minutes.  If you can, please write one.

> - How to build gpgme from svn? I just git-svn cloned it, and ran automake:

What about reading README.SVN ?

> PS: What's the reason that gives a 403?
>    (which is referred to by

Missing alias in boa.conf.  We are looking for a sysadmin...



Die Gedanken sind frei.  Auschnahme regelt ein Bundeschgesetz.

More information about the Gnupg-devel mailing list