Changeset 1562


Ignore:
Timestamp:
Mar 12, 2007, 12:04:11 AM (15 years ago)
Author:
joshe
Message:

Don't use sprintf, strcpy, or strcat.

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/cli/transmissioncli.c

    r1537 r1562  
    113113    {
    114114        static char env[11];
    115         sprintf( env, "TR_DEBUG=%d", verboseLevel );
     115        snprintf( env, sizeof env, "TR_DEBUG=%d", verboseLevel );
    116116        putenv( env );
    117117    }
  • trunk/gtk/util.c

    r1515 r1562  
    282282
    283283const char *
    284 addactionname(guint flag) {
    285   static char name[6];
    286 
    287   if(TR_TORNEW_SAVE_COPY & flag)
    288     strcpy(name, "copy");
    289   else if(TR_TORNEW_SAVE_MOVE & flag)
    290     strcpy(name, "move");
    291   else
    292     strcpy(name, "leave");
    293 
    294   return name;
     284addactionname( guint flag )
     285{
     286    static char name[6];
     287
     288    snprintf( name, sizeof name, "%s",
     289              ( TR_TORNEW_SAVE_COPY & flag ? "copy" :
     290              ( TR_TORNEW_SAVE_MOVE & flag ? "move" :
     291                                             "leave" ) ) );
     292
     293    return name;
    295294}
    296295
     
    324323            if( NULL == getcwd( wd, MAX_PATH_LENGTH + 1 ) )
    325324            {
    326                 strcpy( wd, "." );
     325                snprintf( wd, MAX_PATH_LENGTH + 1, "." );
    327326            }
    328327        }
  • trunk/libtransmission/metainfo.c

    r1538 r1562  
    116116    for( i = 0; i < SHA_DIGEST_LENGTH; i++ )
    117117    {
    118         sprintf( inf->hashString + i * 2, "%02x", inf->hash[i] );
     118        snprintf( inf->hashString + i * 2, sizeof( inf->hashString ) - i * 2,
     119                  "%02x", inf->hash[i] );
    119120    }
    120121
     
    495496    int  newlen = 6;
    496497    char * slash, * scrape;
    497    
     498    size_t scrapelen, used;
     499
    498500    slash = strrchr( announce, '/' );
    499501    if( NULL == slash )
     
    508510    }
    509511
    510     scrape = calloc( strlen( announce ) - oldlen + newlen + 1, 1 );
    511     strncat( scrape, announce, slash - announce );
    512     strcat(  scrape, new );
    513     strcat(  scrape, slash + oldlen );
     512    scrapelen = strlen( announce ) - oldlen + newlen;
     513    scrape = calloc( scrapelen + 1, 1 );
     514    if( NULL == scrape )
     515    {
     516        return NULL;
     517    }
     518    assert( ( size_t )( slash - announce ) < scrapelen );
     519    memcpy( scrape, announce, slash - announce );
     520    used = slash - announce;
     521    strncat( scrape, new, scrapelen - used );
     522    used += newlen;
     523    assert( strlen( scrape ) == used );
     524    if( used < scrapelen )
     525    {
     526        assert( strlen( slash + oldlen ) == scrapelen - used );
     527        strncat( scrape, slash + oldlen, scrapelen - used );
     528    }
    514529
    515530    return scrape;
  • trunk/libtransmission/peer.c

    r1534 r1562  
    114114
    115115    va_start( args, msg );
    116     sprintf( string, "%08x:%04x ",
     116    snprintf( string, sizeof string, "%08x:%04x ",
    117117             (uint32_t) peer->addr.s_addr, peer->port );
    118118    vsnprintf( &string[14], sizeof( string ) - 14, msg, args );
  • trunk/libtransmission/torrent.c

    r1537 r1562  
    128128    for( i = 0; i < SHA_DIGEST_LENGTH; i++ )
    129129    {
    130         sprintf( &tor->escapedHashString[3*i], "%%%02x", inf->hash[i] );
     130        snprintf( &tor->escapedHashString[3*i],
     131                  sizeof( tor->escapedHashString ) - 3 * i,
     132                  "%%%02x", inf->hash[i] );
    131133    }
    132134
  • trunk/libtransmission/transmission.c

    r1463 r1562  
    4444       characters, where xx is the major version number and yy the
    4545       minor version number (Azureus-style) */
    46     sprintf( h->id, "-TR%02d%02d-", VERSION_MAJOR, VERSION_MINOR );
     46    snprintf( h->id, sizeof h->id, "-TR%02d%02d-",
     47              VERSION_MAJOR, VERSION_MINOR );
    4748    for( i = 8; i < 20; i++ )
    4849    {
Note: See TracChangeset for help on using the changeset viewer.