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 742560 - Crash in terminal_screen_has_foreground_process()
Crash in terminal_screen_has_foreground_process()
Status: RESOLVED FIXED
Product: gnome-terminal
Classification: Core
Component: general
git master
Other Linux
: Normal critical
: ---
Assigned To: GNOME Terminal Maintainers
GNOME Terminal Maintainers
Depends on:
Blocks:
 
 
Reported: 2015-01-07 22:01 UTC by Egmont Koblinger
Modified: 2015-01-08 13:37 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Fix (478 bytes, patch)
2015-01-07 23:48 UTC, Egmont Koblinger
committed Details | Review

Description Egmont Koblinger 2015-01-07 22:01:16 UTC
https://bugzilla.redhat.com/show_bug.cgi?id=1179515

Program terminated with signal SIGSEGV, Segmentation fault.
  • #0 terminal_screen_has_foreground_process
    at terminal-screen.c line 1929

The code is

  gsize len;

[...]

  g_snprintf (filename, sizeof (filename), "/proc/%d/cmdline", fgpid);
  if (!g_file_get_contents (filename, &data, &len, NULL))
    return TRUE;

[...]

  for (i = 0; i < len - 1; i++)
    {
      if (data[i] == '\0')
        data[i] = ' ';
    }

My only guess is that g_file_get_contents() doesn't include the trailing \0 in len, and the file is empty. So len is 0 and is unsigned, len-1 is freaking huge, hence the loop runs wild. Does this make sense?
Comment 1 Egmont Koblinger 2015-01-07 23:48:27 UTC
Created attachment 294069 [details] [review]
Fix

Indeed len doesn't include the extra trailing '\0'.

Sometimes /proc/xx/cmdline is terminated by '\0' (most of the processes for me), sometimes it isn't (e.g. /proc/1/cmdline is "/sbin/init" without trailing '\0' for me, shipped by upstart). So I think the best is to prepare for both cases.
Comment 2 Egmont Koblinger 2015-01-08 13:37:31 UTC
Comment on attachment 294069 [details] [review]
Fix

Committed to master and 3-14.