[patch] Re: -Werror=format-security

Nirgal Vourgère <[email protected]> Tue, 8 Mar 2011 07:16:34 +0000
Newsgroups gmane.comp.db.mdb-tools.devel
Message-ID <[email protected]>
On Monday 07 March 2011 16:57:09 Dmitry Nikitin wrote:
> > Attached is a patch. Does it help?
> Probe the patch "g_warning.diff", but have'nt success, give next errors:
> (...)

Hello Dimitry

Attached is another more general patch about printf(string_that_may_contain_percent) problems.
It replaces g_warning.diff
Project now compiles OK here with gcc option -Werror=format-security
Can you test it?

------------------------------------------------------------------------------
What You Don't Know About Data Connectivity CAN Hurt You
This paper provides an overview of data connectivity, details
its effect on application quality, and explores various alternative
solutions. http://p.sf.net/sfu/progress-d2d

_______________________________________________
mdbtools-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mdbtools-dev
format-security (text/x-patch, 5.6 KB)
Index: mdbtools-0.6pre1/src/gmdb2/main2.c
===================================================================
--- mdbtools-0.6pre1.orig/src/gmdb2/main2.c
+++ mdbtools-0.6pre1/src/gmdb2/main2.c
@@ -102,7 +102,7 @@
 
 	gnome_help_display("gmdb.xml", NULL, &error);
 	if (error != NULL) {
-		g_warning (error->message);
+		g_warning ("%s", error->message);
 		g_error_free (error);
 	}
 
Index: mdbtools-0.6pre1/src/gmdb2/prefs.c
===================================================================
--- mdbtools-0.6pre1.orig/src/gmdb2/prefs.c
+++ mdbtools-0.6pre1/src/gmdb2/prefs.c
@@ -44,7 +44,7 @@
 
 	gnome_help_display("gmdb.xml", "gmdb-prefs", &error);
 	if (error != NULL) {
-		g_warning (error->message);
+		g_warning ("%s", error->message);
 		g_error_free (error);
 	}
 }
Index: mdbtools-0.6pre1/src/gmdb2/schema.c
===================================================================
--- mdbtools-0.6pre1.orig/src/gmdb2/schema.c
+++ mdbtools-0.6pre1/src/gmdb2/schema.c
@@ -165,7 +165,7 @@
 
 	gnome_help_display("gmdb.xml", "gmdb-schema", &error);
 	if (error != NULL) {
-		g_warning (error->message);
+		g_warning ("%s", error->message);
 		g_error_free (error);
 	}
 }
Index: mdbtools-0.6pre1/src/gmdb2/table_export.c
===================================================================
--- mdbtools-0.6pre1.orig/src/gmdb2/table_export.c
+++ mdbtools-0.6pre1/src/gmdb2/table_export.c
@@ -142,7 +142,7 @@
 
 	gnome_help_display("gmdb.xml", "gmdb-table-export", &error);
 	if (error != NULL) {
-		g_warning (error->message);
+		g_warning ("%s", error->message);
 		g_error_free (error);
 	}
 }
@@ -195,23 +195,23 @@
 		/* display column titles */
 		col=g_ptr_array_index(table->columns,i);
 		if (need_headers)  {
-			if (i>0) fprintf(outfile,delimiter);
+			if (i>0) fputs(delimiter, outfile);
 			gmdb_print_quote(outfile, need_quote, quotechar, delimiter, col->name);
-			fprintf(outfile,"%s", col->name);
+			fputs(col->name, outfile);
 			gmdb_print_quote(outfile, need_quote, quotechar, delimiter, col->name);
 		}
 	}
-	if (need_headers) fprintf(outfile,lineterm);
+	if (need_headers) fputs(lineterm, outfile);
 
 	/* fetch those rows! */
 	while(mdb_fetch_row(table)) {
 		for (i=0;i<table->num_cols;i++) {
-			if (i>0) fprintf(outfile,delimiter);
+			if (i>0) fputs(delimiter, outfile);
 			gmdb_print_quote(outfile, need_quote, quotechar, delimiter, bound_data[i]);
-			fprintf(outfile,"%s", bound_data[i]);
+			fputs(bound_data[i], outfile);
 			gmdb_print_quote(outfile, need_quote, quotechar, delimiter, bound_data[i]);
 		}
-		fprintf(outfile,lineterm);
+		fputs(lineterm, outfile);
 		rows++;
 	}
 
Index: mdbtools-0.6pre1/src/gmdb2/sql.c
===================================================================
--- mdbtools-0.6pre1.orig/src/gmdb2/sql.c
+++ mdbtools-0.6pre1/src/gmdb2/sql.c
@@ -104,17 +104,17 @@
 	if (need_headers)  {
 		while (col = g_list_nth_data(glist, i)) {
 			gchar *title;
-			if (i>0) fprintf(outfile,delimiter);
+			if (i>0) fputs(delimiter, outfile);
 			title = g_strdup(gtk_tree_view_column_get_title(col));
 			gmdb_print_quote(outfile, need_quote, quotechar,
 				delimiter, title);
-			fprintf(outfile,"%s", title);
+			fputs(title, outfile);
 			gmdb_print_quote(outfile, need_quote, quotechar,
 				delimiter, title);
 			g_free(title);
 			i++;
 		}
-		fprintf(outfile,lineterm);
+		fputs(lineterm, outfile);
 		g_list_free(glist);
 	}
 
@@ -126,16 +126,16 @@
 		rows++;
 		n_columns = gtk_tree_model_get_n_columns(GTK_TREE_MODEL(store));
 		for (i=0; i < n_columns; i++) {
-			if (i>0) fprintf(outfile,delimiter);
+			if (i>0) fputs(delimiter, outfile);
 			gtk_tree_model_get_value(GTK_TREE_MODEL(store), 
 					&iter, i, &value);
 			str = (gchar *) g_value_get_string(&value);
 			gmdb_print_quote(outfile, need_quote, quotechar, delimiter, str);
-			fprintf(outfile,"%s", str);
+			fputs(str, outfile);
 			gmdb_print_quote(outfile, need_quote, quotechar, delimiter, str);
 			g_value_unset(&value);
 		}
-		fprintf(outfile,lineterm);
+		fputs(lineterm, outfile);
 	} while (gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter));
 
 	fclose(outfile);
@@ -433,7 +433,7 @@
 	if (mdb_sql_has_error(sql)) {
 		GtkWidget* dlg = gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_toplevel (w)),
 		    GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_WARNING, GTK_BUTTONS_CLOSE,
-		    mdb_sql_last_error(sql));
+		    "%s", mdb_sql_last_error(sql));
 		gtk_dialog_run (GTK_DIALOG (dlg));
 		gtk_widget_destroy (dlg);
 		mdb_sql_reset(sql);
Index: mdbtools-0.6pre1/src/util/mdb-export.c
===================================================================
--- mdbtools-0.6pre1.orig/src/util/mdb-export.c
+++ mdbtools-0.6pre1/src/util/mdb-export.c
@@ -205,10 +205,10 @@
 		for (j=0; j<table->num_cols; j++) {
 			col=g_ptr_array_index(table->columns,j);
 			if (j)
-				fprintf(stdout,delimiter);
-			fprintf(stdout,"%s", sanitize ? sanitize_name(col->name) : col->name);
+				fputs(delimiter, stdout);
+			fputs(sanitize ? sanitize_name(col->name) : col->name, stdout);
 		}
-		fprintf(stdout,"\n");
+		fputs("\n", stdout);
 	}
 
 	while(mdb_fetch_row(table)) {
@@ -222,16 +222,16 @@
 			fprintf(stdout, "INSERT INTO %s%s (", namespace, quoted_name);
 			free(quoted_name);
 			for (j=0;j<table->num_cols;j++) {
-				if (j>0) fprintf(stdout, ", ");
+				if (j>0) fputs(", ", stdout);
 				col=g_ptr_array_index(table->columns,j);
 				if (sanitize)
 					quoted_name = sanitize_name(col->name);
 				else
 					quoted_name = mdb->default_backend->quote_schema_name(NULL, col->name);
-				fprintf(stdout,"%s", quoted_name);
+				fputs(quoted_name, stdout);
 				free(quoted_name);
 			} 
-			fprintf(stdout, ") VALUES (");
+			fputs(") VALUES (", stdout);
 		}
 
 		for (j=0;j<table->num_cols;j++) {