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 788882 - Audit usages of meta_window_get_monitor indexing directly into an array
Audit usages of meta_window_get_monitor indexing directly into an array
Status: RESOLVED FIXED
Product: gnome-shell
Classification: Core
Component: general
unspecified
Other Mac OS
: Normal normal
: ---
Assigned To: gnome-shell-maint
gnome-shell-maint
Depends on:
Blocks: 788834
 
 
Reported: 2017-10-12 14:55 UTC by Sam Spilsbury
Modified: 2018-06-28 16:35 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
windowMenu: Check return value of meta_window_get_monitor (3.48 KB, patch)
2017-10-12 14:59 UTC, Sam Spilsbury
none Details | Review
layout: Remove unused code (1.11 KB, patch)
2017-10-12 14:59 UTC, Sam Spilsbury
none Details | Review
windowManager: Check the return value of meta_window_get_monitor (1.32 KB, patch)
2017-10-13 00:43 UTC, Sam Spilsbury
committed Details | Review
layout: Remove focusMonitor as it is unused (857 bytes, patch)
2017-10-13 00:44 UTC, Sam Spilsbury
committed Details | Review
keyboard: Handle case where keyboardMonitor is unset (1.24 KB, patch)
2017-10-13 00:44 UTC, Sam Spilsbury
committed Details | Review

Description Sam Spilsbury 2017-10-12 14:55:15 UTC
As discussed in https://bugzilla.gnome.org/show_bug.cgi?id=788834 , `meta_window_get_monitor` might be called on an unmanaged window, and so it needs to return a value as opposed to crashing. There are some cases where we take the return value and use it to index directly into an array of monitors. This was dangerous since the return value is int and negative values are permitted (and will occur in the former case).
Comment 1 Sam Spilsbury 2017-10-12 14:59:17 UTC
Created attachment 361426 [details] [review]
windowMenu: Check return value of meta_window_get_monitor
Comment 2 Sam Spilsbury 2017-10-12 14:59:44 UTC
Created attachment 361427 [details] [review]
layout: Remove unused code
Comment 3 Florian Müllner 2017-10-12 19:07:09 UTC
Review of attachment 361426 [details] [review]:

In addition to the nit below, please use the full bugzilla URL in commit message (we'll probably migrate to gitlab soon, so #12345 will become ambiguous)

::: js/ui/windowMenu.js
@@ +132,3 @@
+          // meta_window_get_monitor can return -1, so handle that case
+          // appropriately.
+          if (monitorIndex !== -1) {

Nit: We now end up with two separators and an empty section in between. Better as far as I can see (also in terms of indentation levels):

let nMonitors = screen.get_n_monitors();
let monitorIndex = window.get_monitor();
if (nMonitors > 1 && monitorIndex > -1) {
  // unchanged
}
Comment 4 Florian Müllner 2017-10-12 19:07:18 UTC
Review of attachment 361427 [details] [review]:

::: js/ui/layout.js
@@ -548,3 @@
     },
 
-    get focusIndex() {

This one isn't unused
Comment 5 Sam Spilsbury 2017-10-13 00:43:30 UTC
Created attachment 361468 [details] [review]
windowManager: Check the return value of meta_window_get_monitor

Makes the indentation nicer (though I note that in that section of the code, the indentation is actually incorrect anyway, maybe this should be fixed with a followup?)
Comment 6 Sam Spilsbury 2017-10-13 00:44:29 UTC
Created attachment 361469 [details] [review]
layout: Remove focusMonitor as it is unused

focusIndex however, is still used (as a property, which I must not have picked up on).
Comment 7 Sam Spilsbury 2017-10-13 00:44:51 UTC
Created attachment 361470 [details] [review]
keyboard: Handle case where keyboardMonitor is unset
Comment 8 Marco Trevisan (Treviño) 2017-11-17 18:23:29 UTC
Review of attachment 361468 [details] [review]:

I think this is all good...
Comment 9 Marco Trevisan (Treviño) 2017-11-17 18:23:41 UTC
Review of attachment 361468 [details] [review]:

I think this is all good...
Comment 10 Marco Trevisan (Treviño) 2017-11-17 18:24:02 UTC
Review of attachment 361470 [details] [review]:

Ack
Comment 11 Jonas Ådahl 2017-12-19 05:51:52 UTC
Review of attachment 361468 [details] [review]:

Was this path ever hit? I don't think its needed: if there are any monitors, a window will always fallback to be assigned to one of them.
Comment 12 Jonas Ådahl 2017-12-19 05:54:20 UTC
Review of attachment 361469 [details] [review]:

Florian said this is still used (I suspect in extension(s)). Better just return null if focusIndex was -1.
Comment 13 Florian Müllner 2017-12-19 18:34:30 UTC
(In reply to Jonas Ådahl from comment #12)
> Review of attachment 361469 [details] [review] [review]:
> 
> Florian said this is still used (I suspect in extension(s)).

No, that was about focusIndex (which is still used for now in keyboard.js).

focusMonitor may of course be used by extensions, but:
 - I don't actually know (none of ours in the gnome-shell-extensions module do)
 - replacing layoutManager.focusMonitor with layoutManager.monitors[layoutManager.focusIndex] looks easy enough

So while I'm not in favor of blindly removing anything we are not using ourselves, I'm not opposed to remove this particular property.
Comment 14 Jonas Ådahl 2017-12-20 04:05:48 UTC
Review of attachment 361469 [details] [review]:

> So while I'm not in favor of blindly removing anything we are not using ourselves, I'm not opposed to remove this particular property.

Alright. Marking as acn then.
Comment 15 Marco Trevisan (Treviño) 2018-06-28 16:31:22 UTC
Fixed with commit c9bf72c5, commit 19e864ed, commit 84d2d3fe, commit 87894696, commit 996dd741