Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#3914 closed Bug (fixed)

strlsize() passes variable of incompatible type to the tr_formatter_size_B()

Reported by: taem Owned by: jordan
Priority: Normal Milestone: 2.20
Component: libtransmission Version: 2.13
Severity: Minor Keywords: trunk
Cc:

Description

Hi,

In daemon/remote.c, strlsize() passes int64_t variable to the tr_formatter_size_B()'s argument 'bytes' which is uint64_t.

static char*
strlsize( char * buf, int64_t bytes, size_t buflen )
{
    if( !bytes )
        tr_strlcpy( buf, "None", buflen );
    else
        tr_formatter_size_B( buf, bytes, buflen );

    return buf;
}
char*
tr_formatter_size_B( char * buf, uint64_t bytes, size_t buflen )
{
    return formatter_get_size_str( &size_units, buf, bytes, buflen );
}

For example, in the following code, 'i' variable can hold -1 according to the RPC spec.

if( tr_bencDictFindInt( args,  "download-dir-free-space", &i ) ) 
    printf( "  Download directory free space: %s\n",  strlsize( buf, i, sizeof buf ) );

Change History (6)

comment:1 follow-up: Changed 12 years ago by jordan

I'm surprised gcc didn't complain about that. taem, does patch look right to you?

http://fpaste.org/UPZr/

comment:2 in reply to: ↑ 1 Changed 12 years ago by taem

Replying to jordan:

I'm surprised gcc didn't complain about that. taem, does patch look right to you?

http://fpaste.org/UPZr/

Patch is OK. But if 'download-dir-free-space' is -1, transmission-remote outputs following:

Download directory free space: -0.00 KiB

comment:3 Changed 12 years ago by taem

With your patch of course.

comment:4 Changed 12 years ago by taem

I'm not sure what should be there instead -0.00 KiB. Maybe put some check for the -1 in:

if( tr_bencDictFindInt( args,  "download-dir-free-space", &i ) ) 
    printf( "  Download directory free space: %s\n",  strlsize( buf, i, sizeof buf ) );

comment:5 Changed 12 years ago by jordan

  • Milestone changed from None Set to 2.20
  • Resolution set to fixed
  • Status changed from new to closed
  • Version set to 2.13

Fixed in r11714.

Thanks for reporting this, taem

comment:6 Changed 12 years ago by jordan

  • Severity changed from Normal to Minor
Note: See TracTickets for help on using tickets.