Bug 117183 - strlen() on random pointer
Summary: strlen() on random pointer
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: system-config-securitylevel
Version: rawhide
Hardware: All
OS: Linux
high
medium
Target Milestone: ---
Assignee: Brent Fox
QA Contact:
URL:
Whiteboard:
Keywords:
: 122069 (view as bug list)
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2004-03-01 11:14 UTC by d.binderman
Modified: 2007-11-30 22:10 UTC (History)
2 users (show)

(edit)
Clone Of:
(edit)
Last Closed: 2004-03-05 15:27:02 UTC


Attachments (Terms of Use)
strlen() patch (589 bytes, patch)
2004-03-02 13:06 UTC, Robert Vojta
no flags Details | Diff

Description d.binderman 2004-03-01 11:14:17 UTC
Description of problem:

I just tried to compile Core2 Test1 package
system-config-securitylevel-1.3.1-1

The compiler said

1.

lokkit.c(254): remark #592: variable "ret" is used before its value is set

The source code is

        char *ret;
        struct servent *service;

        memset(tmp,'\0', 256);
        service = getservbyport(htons(port->port), port->proto);
        if (service) {
                snprintf(tmp, 255, "%s:%s", service->s_name, port->proto);
        } else {
                snprintf(tmp, 255, "%d:%s", port->port, port->proto);
        }
        ret = calloc((orig ? strlen(orig) : 0) + strlen(ret) + 2,
sizeof(char));

Doing strlen() on uninit memory is deeply unwise.

I'm not sure what the fix is for this.



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


How reproducible:


Steps to Reproduce:
1.
2.
3.
  
Actual results:


Expected results:


Additional info:

Comment 1 Robert Vojta 2004-03-02 13:01:51 UTC
> ret = calloc((orig ? strlen(orig) : 0) + strlen(ret) + 2, sizeof(char));

> Doing strlen() on uninit memory is deeply unwise.

  You're right.

> I'm not sure what the fix is for this.

  It's just a mistake ... Brent, please, change the strlen(ret) to the
strlen(tmp) on line 254 in the lokkit.c file.






Comment 2 Robert Vojta 2004-03-02 13:06:26 UTC
Created attachment 98182 [details]
strlen() patch

Very simple patch fixing this bug.

Comment 3 Brent Fox 2004-03-05 15:27:02 UTC
Should be fixed in system-config-securitylevel-1.3.4-1.  Thanks for
the patch.

Comment 4 Brent Fox 2004-06-24 19:08:05 UTC
*** Bug 122069 has been marked as a duplicate of this bug. ***


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