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 603997 - Unconditional use of PATH_MAX causes FTBFS
Unconditional use of PATH_MAX causes FTBFS
Status: RESOLVED FIXED
Product: gnome-applets
Classification: Other
Component: multiload
git master
Other Linux
: Normal normal
: ---
Assigned To: gnome-applets Maintainers
gnome-applets Maintainers
Depends on:
Blocks:
 
 
Reported: 2009-12-07 16:22 UTC by Emilio Pozuelo Monfort
Modified: 2014-08-28 12:48 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
[PATCH] Bug 603997: Don't unconditionally use PATH_MAX (1.78 KB, patch)
2009-12-07 16:25 UTC, Emilio Pozuelo Monfort
none Details | Review
[PATCH] Bug 603997: Don't unconditionally use PATH_MAX, take 2 (1.83 KB, patch)
2009-12-08 11:06 UTC, Emilio Pozuelo Monfort
none Details | Review

Description Emilio Pozuelo Monfort 2009-12-07 16:22:18 UTC
Hi,

The multiload applet unconditionally uses PATH_MAX, which is not guaranteed to be defined by POSIX, and causes a build failure on platforms that don't define it. This happens e.g. on GNU/Hurd. The attached patch changes the code to use dynamic allocation to achieve the same result, making the code more portable and secure.
Comment 1 Emilio Pozuelo Monfort 2009-12-07 16:25:21 UTC
Created attachment 149270 [details] [review]
[PATCH] Bug 603997: Don't unconditionally use PATH_MAX

Subject: [PATCH] Bug 603997: Don't unconditionally use PATH_MAX

Since PATH_MAX is not guaranteed to be defined, unconditionally
using it will cause a build failure on platforms that don't define
it. So stop using it and use dynamic allocation to achieve the same
result.
Comment 2 Daniel Macks 2009-12-08 04:23:28 UTC
You're malloc()ing a string pointer, then writing to it and then assuming that string will have a certain content without checking that the malloc actually worked. Sounds like somewhere between a security flaw and an unpredictable runtime result. Does Hurd have MAXPATHLEN (see Bug #454777 solution to similar problem in a different package)?
Comment 3 Emilio Pozuelo Monfort 2009-12-08 11:06:30 UTC
Created attachment 149322 [details] [review]
[PATCH] Bug 603997: Don't unconditionally use PATH_MAX, take 2

(In reply to comment #2)
> You're malloc()ing a string pointer, then writing to it and then assuming that
> string will have a certain content without checking that the malloc actually
> worked. Sounds like somewhere between a security flaw and an unpredictable
> runtime result.

Oh right. Well if the malloc fails, it will return NULL, and then we will segfault when passing NULL to sprintf... and we don't want that!

> Does Hurd have MAXPATHLEN (see Bug #454777 solution to similar
> problem in a different package)?

It doesn't. Though that bug is the other way round AFAICS (they were using MAXPATHLEN and look for PATH_MAX now), but none is guaranteed to be defined, since there may be no path limit :)

This new patch checks for the malloc return value and returns FALSE if malloc fails to allocate memory.
Comment 4 Emilio Pozuelo Monfort 2009-12-21 08:20:08 UTC
So does this look right now? Can we get it in for 2.29.4?
Comment 5 Emilio Pozuelo Monfort 2010-02-09 00:56:58 UTC
I'd love to get this patch in before 2.30. Can somebody review it?
Comment 6 Emilio Pozuelo Monfort 2010-04-14 23:41:52 UTC
Ping? Can I commit this?
Comment 7 Daniel Macks 2010-04-15 12:16:24 UTC
I think missing "%s" in strlen ("/sys/class/net//device") in the malloc call.
Comment 8 Emilio Pozuelo Monfort 2010-04-15 12:49:32 UTC
(In reply to comment #7)
> I think missing "%s" in strlen ("/sys/class/net//device") in the malloc call.

That's intentional, since that's a strlen("/sys/class/net//device") + strlen(device), where device would be the %s that is missing. That's since it's for a malloc, the sprintf calls later are fine and have enough space thanks to the above code.
Comment 9 Daniel Macks 2010-04-15 13:03:10 UTC
Oops, yeah, now I see what's happening there. All looks sensible to me.
Comment 10 Emilio Pozuelo Monfort 2010-04-26 09:37:41 UTC
(In reply to comment #9)
> Oops, yeah, now I see what's happening there. All looks sensible to me.

Is that an 'ok to push'?
Comment 11 Daniel Macks 2010-04-26 14:15:29 UTC
I don't have commit-bits and I'm not a gnome-applets developer lead, so I don't have actual power to push. But I would if I did.
Comment 12 Alberts Muktupāvels 2014-08-28 12:47:05 UTC
I committed your previous patch as I took it from debian and only then looked at this bug.
Comment 13 Alberts Muktupāvels 2014-08-28 12:48:05 UTC
This problem has been fixed in the development version. The fix will be available in the next major software release. Thank you for your bug report.