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 740052 - Crash in the dLeyna plugin
Crash in the dLeyna plugin
Status: RESOLVED FIXED
Product: grilo
Classification: Other
Component: plugins
0.2.x
Other Linux
: Normal normal
: ---
Assigned To: grilo-maint
grilo-maint
Depends on:
Blocks:
 
 
Reported: 2014-11-13 08:47 UTC by Alberto Garcia
Modified: 2014-11-27 16:04 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
dleyna: Remove redefinition (820 bytes, patch)
2014-11-13 08:57 UTC, Juan A. Suarez Romero
reviewed Details | Review
dleyna: Fix crash determining local IPv6 address (924 bytes, patch)
2014-11-17 08:19 UTC, Juan A. Suarez Romero
committed Details | Review
dleyna: Handle broken /proc/net/tcp file (917 bytes, patch)
2014-11-27 15:02 UTC, Bastien Nocera
needs-work Details | Review
dleyna: Handle broken /proc/net/tcp file (1.18 KB, patch)
2014-11-27 16:00 UTC, Bastien Nocera
committed Details | Review

Description Alberto Garcia 2014-11-13 08:47:31 UTC
The dLeyna plugin can crash Grilo.

Look at this code from grl-dleyna-utils.c:

  /* ... */
  status = g_io_channel_read_line (file, &line, NULL, NULL, NULL);
  while (status == G_IO_STATUS_NORMAL) {
    char *line;
    int j, k, l;
    /* 4*8 for IP, 4 for port, 1 for :, 1 for NUL */
    char buffer[4*8 + 4 + 1 + 1];
    guint32 ip[4];
    guint16 port;
    guint32 all_ipv6[4] = { 0, 0, 0, 0 };

    j = 0;

    /* skip leading space */
    while (line[j] == ' ')
      j++;
  /* ... */


The "skip leading space" part is supposed to parse the line previously
read with g_io_channel_read_line(), however we are redefining the
'line' variable inside the while loop. I wonder how come this does not
crash more often.

On top of that, the " while(line[j] == ' ') j++ " bit is not checking
for the string terminator, so that's also a place for bad surprises.
Comment 1 Juan A. Suarez Romero 2014-11-13 08:57:30 UTC
Created attachment 290613 [details] [review]
dleyna: Remove redefinition
Comment 2 Alberto Garcia 2014-11-13 08:58:09 UTC
> On top of that, the " while(line[j] == ' ') j++ " bit is not
> checking for the string terminator

The problem is actually in the " while (line[j] != ' ') j++ " that
comes next, but my point is that I don't think it's a good idea to
make this kind of assumptions when reading from an external file, even
when its format is not supposed to change.
Comment 3 Bastien Nocera 2014-11-15 15:28:55 UTC
I'd take a patch with a test, which we could feed broken files to. At the very least a file that triggers crashes with the above problems.
Comment 4 Bastien Nocera 2014-11-15 15:30:11 UTC
Review of attachment 290613 [details] [review]:

The commit message in this patch is pretty useless.

How about:
"
dleyna: Fix possible crasher determining local IPv6 address

Avoid a crash when determining the local IPv6 address due to a shadowed variable
"
Comment 5 Juan A. Suarez Romero 2014-11-17 08:19:10 UTC
Created attachment 290835 [details] [review]
dleyna: Fix crash determining local IPv6 address

Avoid a crash when determining the local IPv6 address due to a shadowed
variable.
Comment 6 Bastien Nocera 2014-11-18 18:51:46 UTC
Review of attachment 290835 [details] [review]:

Looks good.
Comment 7 Juan A. Suarez Romero 2014-11-18 19:10:21 UTC
Pushed
Comment 8 Bastien Nocera 2014-11-19 11:46:09 UTC
This isn't fixed.
Comment 9 Juan A. Suarez Romero 2014-11-19 14:35:50 UTC
(In reply to comment #8)
> This isn't fixed.

Are you still able to reproduce it?
Comment 10 Bastien Nocera 2014-11-19 15:36:32 UTC
The:
while(line[j] == ' ') j++
code is still problematic.
Comment 11 Juan A. Suarez Romero 2014-11-19 16:24:22 UTC
Right, though it is not causing the crash. But could be a problem if in the future the kernel just change the format of that file.
Comment 12 Bastien Nocera 2014-11-19 16:43:53 UTC
I think it best to either fix it, or make sure the bug is documented in the source if we ever hit it again.
Comment 13 Bastien Nocera 2014-11-27 15:02:11 UTC
Created attachment 291659 [details] [review]
dleyna: Handle broken /proc/net/tcp file

Don't crash if we reach the end of the line when skipping the first
field of /proc/net/tcp
Comment 14 Juan A. Suarez Romero 2014-11-27 15:15:50 UTC
Review of attachment 291659 [details] [review]:

This is done for is_our_user_ipv4(), but we need to do it also in is_our_user_ipv6()
Comment 15 Bastien Nocera 2014-11-27 16:00:29 UTC
Created attachment 291668 [details] [review]
dleyna: Handle broken /proc/net/tcp file

Don't crash if we reach the end of the line when skipping the first
field of /proc/net/tcp
Comment 16 Bastien Nocera 2014-11-27 16:04:51 UTC
Attachment 291668 [details] pushed as 465c58c - dleyna: Handle broken /proc/net/tcp file