After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 680215 - Don't silently accept extra arguments to C functions
Don't silently accept extra arguments to C functions
Status: RESOLVED FIXED
Product: gjs
Classification: Bindings
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gjs-maint
gjs-maint
Depends on:
Blocks:
 
 
Reported: 2012-07-19 00:27 UTC by Jasper St. Pierre (not reading bugmail)
Modified: 2017-04-04 01:41 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
GLib: Don't pass extra arguments to constructors (1.97 KB, patch)
2012-07-19 00:27 UTC, Jasper St. Pierre (not reading bugmail)
committed Details | Review
function: Reject cases where we pass too many arguments (1.55 KB, patch)
2012-07-19 00:28 UTC, Jasper St. Pierre (not reading bugmail)
rejected Details | Review
function: Correct argument counting for array arguments (1.24 KB, patch)
2012-08-07 17:59 UTC, Jasper St. Pierre (not reading bugmail)
committed Details | Review
function: Warn when passing extra arguments to a function (4.32 KB, patch)
2017-04-03 01:49 UTC, Philip Chimento
committed Details | Review

Description Jasper St. Pierre (not reading bugmail) 2012-07-19 00:27:55 UTC
This is a bug waiting to happen, or in some cases, a bug that
already exists. I have patches to make gnome-shell "work" again, but
there may be other, unspotted scenarios.
Comment 1 Jasper St. Pierre (not reading bugmail) 2012-07-19 00:27:58 UTC
Created attachment 219175 [details] [review]
GLib: Don't pass extra arguments to constructors
Comment 2 Jasper St. Pierre (not reading bugmail) 2012-07-19 00:28:00 UTC
Created attachment 219176 [details] [review]
function: Reject cases where we pass too many arguments

We shouldn't be ignoring arguments that the user passed to a
function. This is just a bug waiting to happen.
Comment 3 Colin Walters 2012-07-19 00:45:40 UTC
The standard JavaScript language lets you do this; I assume that was the rationale for allowing it.

Maybe there's an argument for a new GJS_LINT=1 environment variable or something, but this would be pretty gratutious breakage for people.
Comment 4 Jasper St. Pierre (not reading bugmail) 2012-07-19 01:00:28 UTC
(In reply to comment #3)
> The standard JavaScript language lets you do this; I assume that was the
> rationale for allowing it.

JavaScript also lets you pass fewer or no arguments at all, and they will automatically be filled in with 'undefined's.
Comment 5 Colin Walters 2012-07-19 15:28:56 UTC
(In reply to comment #4)
> (In reply to comment #3)
> > The standard JavaScript language lets you do this; I assume that was the
> > rationale for allowing it.
> 
> JavaScript also lets you pass fewer or no arguments at all, and they will
> automatically be filled in with 'undefined's.

True; but we couldn't mimic that behavior really without triggering g_return_if_fail()s at a minimum, an in a lot of cases segfault.  Clearly not the same thing as silently doing nothing with extra arguments.

I'm not going to say that it's better to ignore arguments though; the point is more that it'd be *really painful* to switch to throwing an error now.
Comment 6 Jasper St. Pierre (not reading bugmail) 2012-08-07 17:58:48 UTC
I think there would be a burst of initial pain, and then a lot of relief. And the overrides patch can certainly go in.
Comment 7 Jasper St. Pierre (not reading bugmail) 2012-08-07 17:59:21 UTC
Created attachment 220589 [details] [review]
function: Correct argument counting for array arguments

For an (out) array length argument, we were accidentally subtracting
it from the expected argc.
Comment 8 Colin Walters 2012-08-07 18:45:51 UTC
Review of attachment 219175 [details] [review]:

Ok.
Comment 9 Colin Walters 2012-08-07 19:13:34 UTC
Review of attachment 220589 [details] [review]:

The commit message is wrong; we *should* subtract an (out) length from the expected js argc, but we weren't doing it, correct?
Comment 10 Colin Walters 2012-08-07 19:14:30 UTC
(In reply to comment #6)
> I think there would be a burst of initial pain, and then a lot of relief.

So...doing this this late in the 3.6 cycle seems very dangerous to me.  How about instead a transition period where we just g_printerr() or something?
Comment 11 Jasper St. Pierre (not reading bugmail) 2012-08-07 19:30:56 UTC
Review of attachment 220589 [details] [review]:

No; we should never subtract an (out) parameter from the number of parameters that need to be passed into a C function, length or not.
Comment 12 Colin Walters 2012-08-07 19:34:14 UTC
Review of attachment 220589 [details] [review]:

Yeah, sorry, I read the patch backwards.
Comment 13 Jasper St. Pierre (not reading bugmail) 2012-08-07 20:44:36 UTC
Attachment 219175 [details] pushed as ce0a129 - GLib: Don't pass extra arguments to constructors
Attachment 220589 [details] pushed as 4d31cc9 - function: Correct argument counting for array arguments
Comment 14 Jasper St. Pierre (not reading bugmail) 2012-10-03 16:36:26 UTC
I think we should do this for 3.8. I've removed all the issues with gnome-shell, gnome-documents, and sushi over the course of time. I've been running with this patch since a little before I filed it, and I haven't encountered any issues since.
Comment 15 Philip Chimento 2017-04-03 01:47:03 UTC
Review of attachment 219176 [details] [review]:

Going to take Colin's approach for now, of warning rather than throwing. Once that's been in for a while, then we can consider doing something like this.
Comment 16 Philip Chimento 2017-04-03 01:49:57 UTC
Created attachment 349157 [details] [review]
function: Warn when passing extra arguments to a function

We should not silently ignore arguments that a user passes to a GI
function. Instead, print a warning. Silently ignoring them can lead to
hard-to-track-down bugs.
Comment 17 Cosimo Cecchi 2017-04-03 17:08:52 UTC
Review of attachment 349157 [details] [review]:

Thanks, looks good.
Comment 18 Philip Chimento 2017-04-04 01:41:22 UTC
Pushed with one small amendment: JS_ReportWarning() instead of g_warning()
so that we get a file and line number in the message.

Attachment 349157 [details] pushed as ab0c97b - function: Warn when passing extra arguments to a function