RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 996793 - compiling curl example sendrecv.c with -O0 NULLs a variable.
Summary: compiling curl example sendrecv.c with -O0 NULLs a variable.
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: gcc
Version: 6.4
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: Jakub Jelinek
QA Contact: qe-baseos-tools-bugs
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2013-08-14 00:29 UTC by Leonard den Ottolander
Modified: 2014-04-21 17:02 UTC (History)
3 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2013-08-14 14:58:04 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Leonard den Ottolander 2013-08-14 00:29:12 UTC
Description of problem:

Try compiling the libcurl-devel-7.19.7-37 example sendrecv.c:

$ gcc sendrecv.c -lcurl -o sendrecv

(implicit -O0)

Compile and linking go well but executing the resulting binary fails. After the call to curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, &sockfd) the parameter curl is set to NULL, making the following curl_easy_send() fail.

I first suspected this to be a curl bug but this seems not to be the case.

When using another optimization level (say -O1 or -O2) the resulting binary behaves as expected.


Version-Release number of selected component (if applicable):

gcc-4.4.7-3.el6.x86_64

Comment 2 Marek Polacek 2013-08-14 04:29:49 UTC
Please provide preprocessed testcase.

Comment 3 Leonard den Ottolander 2013-08-14 11:42:08 UTC
What do you mean by a preprocessed test case? Do you want me to send you a precompiled binary?

The file sendrecv.c can be found in libcurl-devel-7.19.7-36.el6_4.x86_64.rpm under /usr/share/doc/libcurl-devel-7.19.7.

If you build the file as per the above instructions you will see that on execution the resulting binary terminates with the message "Error: A libcurl function was given a bad argument". This is caused by the parameter curl having been set to NULL and being passed to curl_easy_send() as such. (You can verify that the error is caused by having been passed a NULL value from the curl sources.)

This setting to NULL is something the compiler does, it does NOT happen in curl. I added some printfs in various curl functions to verify this. The variable curl is still set when leaving curl_easy_getinfo() but unset right after returning on line 71 in sendrecv.c.

Building the same file with -O1 or -O2 results in a correct binary.

Comment 4 Marek Polacek 2013-08-14 11:52:53 UTC
No, I need the sendrecv.i file generated by adding -save-temps to the command line options.  This preprocessed file should fail with -O0, but work with -O, as you say.

For more info see http://gcc.gnu.org/bugs/ .

Comment 5 Jakub Jelinek 2013-08-14 14:58:04 UTC
That testcase is just invalid.  If you look at curl.h, you'll see that
for CURLINFO_LASTSOCKET (and many others) you need to call it with address of a long variable, but it is called with address of sockfd which has type int rather than long.  So there is buffer overflow in the program.

Comment 6 Leonard den Ottolander 2013-08-14 17:46:42 UTC
Thanks for clearing this up. Indeed using a long for sockfd fixes the issue. So this is a bug in curl after all, even if just in an example.

Comparing the example in curl-7.32.0 shows the issue is indeed fixed upstream. sockfd is now of type curl_socket_t.


Note You need to log in before you can comment on or make changes to this bug.