corrupt trustdb caused by commandline?

David Shaw dshaw at jabberwocky.com
Tue May 9 19:13:52 CEST 2006


On Mon, May 08, 2006 at 09:11:49PM -0400, Atom Smasher wrote:
> this is weird...
> 
> i can run this:
> 	gpg --list-public-keys smasher ; echo $?
> all day long, and everything is fine (returns 0).
> 
> but when i close stdout:
> 	gpg --list-public-keys smasher 1>&- ; echo $?
> 
> it works once and corrupts my trustdb. running it again returns "2".
> 
>   gpg: /home/atom/.gnupg/trustdb.gpg: invalid record type 112 at recnum 1
> 
> if i change the "1" to a "2" (closing stderr instead of stdout), it works 
> fine. if i omit the "1" and leave it implied (still closing stdout) it 
> still causes problems.

Good one.  Open up your trustdb.gpg in a text editor to see what
happened. ;)

> i've only noticed this since upgrading to 1.4.3. i was previously running 
> 1.4.2 and the didn't have any problems with the exact same command.

I'm not sure why you didn't have the problem in 1.4.2.  It should
happen there as well.

Try this patch.

David
-------------- next part --------------
Index: gpg.c
===================================================================
--- gpg.c	(revision 4131)
+++ gpg.c	(working copy)
@@ -1625,6 +1625,23 @@
     log_error("unknown trust model `%s'\n",model);
 }
 
+static void
+reopen_std(void)
+{
+#ifdef HAVE_STAT
+  struct stat statbuf;
+
+  if(fstat(STDIN_FILENO,&statbuf)==-1 && errno==EBADF)
+    open("/dev/null",O_RDONLY);
+
+  if(fstat(STDOUT_FILENO,&statbuf)==-1 && errno==EBADF)
+    open("/dev/null",O_WRONLY);
+
+  if(fstat(STDERR_FILENO,&statbuf)==-1 && errno==EBADF)
+    open("/dev/null",O_WRONLY);
+#endif
+}
+
 int
 main (int argc, char **argv )
 {
@@ -1675,6 +1692,7 @@
     opt.lock_once = 1;
 #endif /* __riscos__ */
 
+    reopen_std();
     trap_unaligned();
     secmem_set_flags( secmem_get_flags() | 2 ); /* suspend warnings */
     /* Please note that we may running SUID(ROOT), so be very CAREFUL


More information about the Gnupg-devel mailing list