Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 359538 - [GTK] os.c:13161:2: warning: format not a string literal and no format arguments [-Wformat-security]
Summary: [GTK] os.c:13161:2: warning: format not a string literal and no format argume...
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.7.1   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 4.6 M7   Edit
Assignee: Markus Keller CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-30 05:26 EDT by أحمد المحمودي CLA
Modified: 2016-04-27 06:48 EDT (History)
6 users (show)

See Also:


Attachments
Fix FTBFS with -Werror=format-security compiler flag set (823 bytes, patch)
2011-09-30 05:26 EDT, أحمد المحمودي CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description أحمد المحمودي CLA 2011-09-30 05:26:28 EDT
Created attachment 204356 [details]
Fix FTBFS with -Werror=format-security compiler flag set

Eclipse build id or SWT version: SWT 3.7.1

 Platform(s) tested on: Debian unstable

Snippet title: Fix FTBFS with -Werror=format-security compiler flag set

Snippet code: 

--- a/os.c
+++ b/os.c
@@ -10830,7 +10830,7 @@
 	jintLong rc = 0;
 	OS_NATIVE_ENTER(env, that, _1gtk_1message_1dialog_1new_FUNC);
 	if (arg4) if ((lparg4 = (*env)->GetByteArrayElements(env, arg4, NULL)) == NULL) goto fail;
-	rc = (jintLong)gtk_message_dialog_new((GtkWindow *)arg0, (GtkDialogFlags)arg1, (GtkMessageType)arg2, (GtkButtonsType)arg3, (const gchar *)lparg4);
+	rc = (jintLong)gtk_message_dialog_new((GtkWindow *)arg0, (GtkDialogFlags)arg1, (GtkMessageType)arg2, (GtkButtonsType)arg3, "%s", (const gchar *)lparg4);
 fail:
 	if (arg4 && lparg4) (*env)->ReleaseByteArrayElements(env, arg4, lparg4, 0);
 	OS_NATIVE_EXIT(env, that, _1gtk_1message_1dialog_1new_FUNC);
Comment 1 Felipe Heidrich CLA 2011-09-30 17:09:18 EDT
Can you explain the problem ?

Note that os.c is auto-generate, changing this code directly is wrong.
You need to change the OS.java from where the os.c file generated from.
Comment 2 Grant Gayed CLA 2011-10-03 10:29:37 EDT
This is referring to the warning that is spewed when compiling the swt lib.
Comment 3 Markus Keller CLA 2016-03-23 14:10:17 EDT
Here's the native build warning:

     [exec] os.c: In function ‘Java_org_eclipse_swt_internal_gtk_OS__1gtk_1message_1dialog_1new’:
     [exec] os.c:13161:2: warning: format not a string literal and no format arguments [-Wformat-security]
     [exec]   rc = (jintLong)gtk_message_dialog_new((GtkWindow *)arg0, (GtkDialogFlags)arg1, (GtkMessageType)arg2, (GtkButtonsType)arg3, (const gchar *)lparg4);
     [exec]   ^


The hack for bug 77983 was to add MessageBox#fixPercent(String), but that's a lot of unnecessary code.

The right fix is to remove MessageBox#fixPercent(String) and instead call gtk_message_dialog_new () with "%s" and the actual message as separate arguments.
Comment 5 Alexander Kurtakov CLA 2016-03-23 14:51:50 EDT
(In reply to Markus Keller from comment #4)
> Fixed with
> http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/
> ?id=b85b74162ec3dcda5668021f61b12b395db3fd74

Should format-security be added to CFLAGS to make sure this doesn't happen in the future?
Comment 6 Markus Keller CLA 2016-03-24 06:15:16 EDT
(In reply to Alexander Kurtakov from comment #5)
> Should format-security be added to CFLAGS to make sure this doesn't happen
> in the future?

No, see https://fedoraproject.org/wiki/Format-Security-FAQ . The warning was actually helpful to reveal this problem and fix it the right way.
Comment 7 Alexander Kurtakov CLA 2016-03-24 06:23:44 EDT
(In reply to Markus Keller from comment #6)
> (In reply to Alexander Kurtakov from comment #5)
> > Should format-security be added to CFLAGS to make sure this doesn't happen
> > in the future?
> 
> No, see https://fedoraproject.org/wiki/Format-Security-FAQ . The warning was
> actually helpful to reveal this problem and fix it the right way.

So I'm proposing adding -Werror=format-security as this page suggests so we ensure that there is compile failure to prevent such issues in the future.
Comment 8 Sravan Kumar Lakkimsetti CLA 2016-04-27 04:28:47 EDT
Verified on Ubuntu Mate 16.04 with I20160426-1615