More format string fixes for 1.2.3

Florian Weimer fw at deneb.enyo.de
Tue Dec 16 23:08:07 CET 2003


Only the changes to g10/tdbio.c could be critical (I haven't examined
the calling code, so I'm not sure).  The util/argparse.c changes are
there to prevent further warnings.  The code there still is pretty much
i18n-resistant.

The configure.ac change should add some protection for the future.
Funny that this helpful GCC warning is so rarely used.

There are a few remaining false positives which a hard to fix (the
second one in g10/passphrase.c screams after linking against -liberty,
to get asprintf(), BTW).

--- orig/configure.ac
+++ mod/configure.ac
@@ -867,7 +867,7 @@
 
 if test "$GCC" = yes; then
     if test "$USE_MAINTAINER_MODE" = "yes"; then
-        CFLAGS="$CFLAGS -Wall -Wcast-align -Wshadow -Wstrict-prototypes"
+        CFLAGS="$CFLAGS -Wall -Wcast-align -Wshadow -Wstrict-prototypes -Wformat -Wformat-nonliteral"
     else
         CFLAGS="$CFLAGS -Wall"
     fi
--- orig/g10/tdbio.c
+++ mod/g10/tdbio.c
@@ -753,8 +753,7 @@
     hashrec += msb / ITEMS_PER_HTBL_RECORD;
     rc = tdbio_read_record( hashrec, &rec, RECTYPE_HTBL );
     if( rc ) {
-	log_error( db_name, "upd_hashtable: read failed: %s\n",
-							g10_errstr(rc) );
+	log_error( "upd_hashtable: read failed: %s\n", g10_errstr(rc) );
 	return rc;
     }
 
@@ -763,8 +762,8 @@
 	rec.r.htbl.item[msb % ITEMS_PER_HTBL_RECORD] = newrecnum;
 	rc = tdbio_write_record( &rec );
 	if( rc ) {
-	    log_error( db_name, "upd_hashtable: write htbl failed: %s\n",
-							    g10_errstr(rc) );
+	    log_error( "upd_hashtable: write htbl failed: %s\n",
+							     g10_errstr(rc) );
 	    return rc;
 	}
     }
@@ -860,7 +859,7 @@
 	    rc = tdbio_write_record( &rec );
 	    if( rc ) {
 		log_error( "upd_hashtable: write new hlst failed: %s\n",
-						  g10_errstr(rc) );
+					       		g10_errstr(rc) );
 		return rc;
 	    }
 	    /* update the hashtable record */
@@ -902,8 +901,8 @@
     hashrec += msb / ITEMS_PER_HTBL_RECORD;
     rc = tdbio_read_record( hashrec, &rec, RECTYPE_HTBL );
     if( rc ) {
-	log_error( db_name, "drop_from_hashtable: read failed: %s\n",
-							g10_errstr(rc) );
+	log_error( "drop_from_hashtable: read failed: %s\n",
+						g10_errstr(rc) );
 	return rc;
     }
 
@@ -915,7 +914,7 @@
 	rec.r.htbl.item[msb % ITEMS_PER_HTBL_RECORD] = 0;
 	rc = tdbio_write_record( &rec );
 	if( rc )
-	    log_error( db_name, "drop_from_hashtable: write htbl failed: %s\n",
+	    log_error( "drop_from_hashtable: write htbl failed: %s\n",
 							    g10_errstr(rc) );
 	return rc;
     }
@@ -944,7 +943,7 @@
 		    rec.r.hlst.rnum[i] = 0; /* drop */
 		    rc = tdbio_write_record( &rec );
 		    if( rc )
-			log_error( db_name, "drop_from_hashtable: write htbl failed: %s\n",
+			log_error( "drop_from_hashtable: write htbl failed: %s\n",
 									g10_errstr(rc) );
 		    return rc;
 		}
@@ -991,7 +990,7 @@
     hashrec += msb / ITEMS_PER_HTBL_RECORD;
     rc = tdbio_read_record( hashrec, rec, RECTYPE_HTBL );
     if( rc ) {
-	log_error( db_name, "lookup_hashtable failed: %s\n", g10_errstr(rc) );
+	log_error( "lookup_hashtable failed: %s\n", g10_errstr(rc) );
 	return rc;
     }
 
@@ -1001,14 +1000,14 @@
 
     rc = tdbio_read_record( item, rec, 0 );
     if( rc ) {
-	log_error( db_name, "hashtable read failed: %s\n", g10_errstr(rc) );
+	log_error( "hashtable read failed: %s\n", g10_errstr(rc) );
 	return rc;
     }
     if( rec->rectype == RECTYPE_HTBL ) {
 	hashrec = item;
 	level++;
 	if( level >= keylen ) {
-	    log_error( db_name, "hashtable has invalid indirections\n");
+	    log_error( "hashtable has invalid indirections\n");
 	    return G10ERR_TRUSTDB;
 	}
 	goto next_level;
--- orig/keyserver/gpgkeys_hkp.c
+++ mod/keyserver/gpgkeys_hkp.c
@@ -268,14 +268,14 @@
 
 	  if(gotit)
 	    {
-	      fprintf(output,line);
+	      fputs(line,output);
 	      if(strcmp(line,"-----END PGP PUBLIC KEY BLOCK-----\n")==0)
 		break;
 	    }
 	  else
 	    if(strcmp(line,"-----BEGIN PGP PUBLIC KEY BLOCK-----\n")==0)
 	      {
-		fprintf(output,line);
+		fputs(line,output);
 		gotit=1;
 	      }
 	}
--- orig/util/argparse.c
+++ mod/util/argparse.c
@@ -162,35 +162,36 @@
 
 	if( filename ) {
 	    if( arg->r_opt == -6 )
-		s = "%s:%u: argument not expected\n";
+		s = "argument not expected";
 	    else if( arg->r_opt == -5 )
-		s = "%s:%u: read error\n";
+		s = "read error";
 	    else if( arg->r_opt == -4 )
-		s = "%s:%u: keyword too long\n";
+		s = "keyword too long";
 	    else if( arg->r_opt == -3 )
-		s = "%s:%u: missing argument\n";
+		s = "missing argument";
 	    else if( arg->r_opt == -7 )
-		s = "%s:%u: invalid command\n";
+		s = "invalid command";
 	    else if( arg->r_opt == -10 )
-		s = "%s:%u: invalid alias definition\n";
+		s = "invalid alias definition";
 	    else
-		s = "%s:%u: invalid option\n";
-	    log_error(s, filename, *lineno );
+		s = "invalid option";
+	    log_error("%s:%u:%s\n", filename, *lineno, s );
 	}
 	else {
 	    if( arg->r_opt == -3 )
-		s = "Missing argument for option \"%.50s\"\n";
+		s = "Missing argument for option ";
 	    else if( arg->r_opt == -6 )
-		s = "Option \"%.50s\" does not expect an argument\n";
+		s = "Option does not expect an argument: ";
 	    else if( arg->r_opt == -7 )
-		s = "Invalid command \"%.50s\"\n";
+		s = "Invalid command: ";
 	    else if( arg->r_opt == -8 )
-		s = "Option \"%.50s\" is ambiguous\n";
+		s = "Option is ambiguous: ";
 	    else if( arg->r_opt == -9 )
-		s = "Command \"%.50s\" is ambiguous\n";
+		s = "Command is ambiguous: ";
 	    else
-		s = "Invalid option \"%.50s\"\n";
-	    log_error(s, arg->internal.last? arg->internal.last:"[??]" );
+		s = "Invalid option: ";
+	    log_error("%s: \"%.50s\"\n", s,
+		      arg->internal.last? arg->internal.last:"[??]" );
 	}
 	if( arg->err != 1 || arg->r_opt == -5 )
 	    exit(2);



More information about the Gnupg-devel mailing list