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 788548 - Function parameter assigned the address of a local auto-variable in function id3v2_frames_to_tag_list
Function parameter assigned the address of a local auto-variable in function ...
Status: RESOLVED WONTFIX
Product: GStreamer
Classification: Platform
Component: gst-plugins-base
1.12.3
Other All
: Normal minor
: NONE
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2017-10-05 06:26 UTC by Ashish Kumar
Modified: 2018-01-19 20:46 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
[PATCH][Fix for] Function parameter assigned the address of a local auto-variable in function id3v2_frames_to_tag_list (1.02 KB, patch)
2017-10-06 04:47 UTC, Ashish Kumar
none Details | Review
[PATCH][Fix for] Function parameter assigned the address of a local auto-variable in function id3v2_frames_to_tag_list (1.31 KB, patch)
2017-10-06 05:05 UTC, Ashish Kumar
none Details | Review
[PATCH][Fix for] Function parameter assigned the address of a local auto-variable in function id3v2_frames_to_tag_list (1.51 KB, patch)
2017-10-06 05:17 UTC, Ashish Kumar
none Details | Review
[PATCH][Fix for] Function parameter assigned the address of a local auto-variable in function id3v2_frames_to_tag_list (1.75 KB, patch)
2017-10-06 05:42 UTC, Ashish Kumar
none Details | Review
[PATCH][Fix for] Function parameter assigned the address of a local auto-variable in function id3v2_frames_to_tag_list (2.01 KB, patch)
2017-10-06 06:20 UTC, Ashish Kumar
rejected Details | Review

Description Ashish Kumar 2017-10-05 06:26:06 UTC
In 
File : id3v2.c
Function : static gboolean id3v2_frames_to_tag_list (ID3TagsWorking * work, guint size)

Line No. 574
In statement 
 work->frame_id = frame_id;

Function parameter work->frame_id of type gchar * (pointer) is assigned local auto-variable frame_id which is defined as

Line No. 477: gchar frame_id[5] = "";

Function parameter is assigned the address of a local auto-variable. Local auto-variables are reserved from the stack which is freed when the function ends. The address is invalid after the function ends and it might 'leak' from the function through the parameter.

Solution: frame_id should be initialized as below :-

gchar *frame_id = g_malloc (5*sizeof(gchar));


Please let me know if I can submit a patch for the issue.
Comment 1 Tim-Philipp Müller 2017-10-05 09:45:27 UTC
work->frame_id is only accessed by functions called within the block where frame_id is valid. So maybe it's not the nicest code structure, but it's not clear to me there's an actual bug here.
Comment 2 Ashish Kumar 2017-10-06 04:47:43 UTC
Created attachment 361018 [details] [review]
[PATCH][Fix for] Function parameter assigned the address of a local auto-variable in function id3v2_frames_to_tag_list

The attached patch resolves the possibility of a bug and a gives a better assignment to the function parameter.
Please review and share the feedback
Comment 3 Ashish Kumar 2017-10-06 05:05:52 UTC
Created attachment 361019 [details] [review]
[PATCH][Fix for] Function parameter assigned the address of a local auto-variable in function id3v2_frames_to_tag_list

Please review this patch.
Comment 4 Ashish Kumar 2017-10-06 05:17:10 UTC
Created attachment 361020 [details] [review]
[PATCH][Fix for] Function parameter assigned the address of a local auto-variable in function id3v2_frames_to_tag_list
Comment 5 Ashish Kumar 2017-10-06 05:42:19 UTC
Created attachment 361021 [details] [review]
[PATCH][Fix for] Function parameter assigned the address of a local auto-variable in function id3v2_frames_to_tag_list
Comment 6 Ashish Kumar 2017-10-06 06:20:47 UTC
Created attachment 361024 [details] [review]
[PATCH][Fix for] Function parameter assigned the address of a local auto-variable in function id3v2_frames_to_tag_list
Comment 7 Tim-Philipp Müller 2017-10-06 07:21:47 UTC
I'm not in favour of this, sorry. It causes extra overhead without actually improving anything, it just makes your code checker happy. We still have an invalid (freed) pointer in the Works structure in the end.

If we want to make sure that the local memory isn't accessed after it goes away, we should set the field in the Works structure to NULL instead.
Comment 8 Tim-Philipp Müller 2018-01-19 20:45:59 UTC
Maybe this makes your checker happy:

commit a1af74feda8f4e5aeae97da2aebd43d2fe8432eb (HEAD -> master)
Author: Tim-Philipp Müller <tim@centricular.com>
Date:   Fri Jan 19 20:43:57 2018 +0000

    tag: id3v2: don't leak stack pointer outside of block where it's valid
    
    https://bugzilla.gnome.org/show_bug.cgi?id=788548
Comment 9 Tim-Philipp Müller 2018-01-19 20:46:20 UTC
Comment on attachment 361024 [details] [review]
[PATCH][Fix for] Function parameter assigned the address of a local auto-variable in function id3v2_frames_to_tag_list

As explained. Sorry :)