gpgme 0.3.9 self-tests fail under Solaris due to NULL pointer dereferences

Dr.Stefan.Dalibor at bfa.de Dr.Stefan.Dalibor at bfa.de
Mon Sep 2 14:23:07 CEST 2002


Hi,
gpgme 0.3.9 fails to pass its self-tests under Solaris 8 (compiled
with Sun's SUNWspro cc) due to dereferencing NULL pointers:

1. In tests/gpg/t-keylist.c main() (line 150), a NULL value (in
   variable `pattern') is passed as string argument to fprintf()...
   this might be O.K. when using glibc, but Solaris fprintf() crashes.
   The fix is trivial (see hunk #1 of appended patch).

2. When testing for exiting w/o adding anything to the debug logs in
   gpgme/debug.c _gpgme_debug_add() (line 183) and _gpgme_debug_end()
   (line 201), only the value (not the content) of `line' is tested.
   But in _gpgme_debug_begin() (line 165), only the content of the
   char ** passed as argument `line' to all 3 functions is set to
   NULL if debugging is turned off.  Thus, `*line' is NULL and gpgme
   crashes when trying to dereference it e.g. in asprintf().

   I'm not sure if I understand this - as far as I can see, it makes
   12 of 14 self-tests fail under Solaris (maybe because passing NULL
   pointers to printf() and string functions works under Linux?), so
   I wonder how it could have remained unnoticed for so long (it was
   the same in 0.3.8).
   Anyway, if hunk #2 of the appended patch is applied, gpgme passes
   all self-tests.

Please CC me if replying to this mail, as I'm not subscribed to
gnupg-devel.

Thanks,
Stefan

--

diff -r -C 3 gpgme-0.3.9/tests/gpg/t-keylist.c gpgme-0.3.9-patched/tests/gpg/t-keylist.c
*** gpgme-0.3.9/tests/gpg/t-keylist.c     Fri Dec 14 02:24:47 2001
--- gpgme-0.3.9-patched/tests/gpg/t-keylist.c   Thu Aug 29 09:17:21 2002
***************
*** 147,153 ****
      fail_if_err (err);
      gpgme_set_keylist_mode (ctx, 1); /* no validity calculation */
      do {
!         fprintf (stderr, "** pattern=`%s'\n", pattern );
          doit ( ctx, pattern );
      } while ( loop );
      gpgme_release (ctx);
--- 147,153 ----
      fail_if_err (err);
      gpgme_set_keylist_mode (ctx, 1); /* no validity calculation */
      do {
!         fprintf (stderr, "** pattern=`%s'\n", pattern ? pattern : "<NULL>");
          doit ( ctx, pattern );
      } while ( loop );
      gpgme_release (ctx);
diff -r -C 3 gpgme-0.3.9/gpgme/debug.c gpgme-0.3.9-patched/gpgme/debug.c
*** gpgme-0.3.9/gpgme/debug.c Wed May  8 05:57:52 2002
--- gpgme-0.3.9-patched/gpgme/debug.c     Thu Aug 29 09:17:44 2002
***************
*** 180,186 ****
    char *toadd;
    char *result;

!   if (!line)
      return;

    va_start (arg_ptr, format);
--- 180,186 ----
    char *toadd;
    char *result;

!   if (!line || !*line)
      return;

    va_start (arg_ptr, format);
***************
*** 198,204 ****
  void
  _gpgme_debug_end (void **line)
  {
!   if (!line)
      return;

    /* The smallest possible level is 1, so force logging here by
--- 198,204 ----
  void
  _gpgme_debug_end (void **line)
  {
!   if (!line || !*line)
      return;

    /* The smallest possible level is 1, so force logging here by





More information about the Gnupg-devel mailing list