Changeset 8611


Ignore:
Timestamp:
Jun 4, 2009, 3:52:54 PM (13 years ago)
Author:
charles
Message:

(trunk libT) fix potential permissions headache when saving json/benc files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/bencode.c

    r8604 r8611  
    1919#include <string.h>
    2020
    21 #include <sys/types.h> /* open() */
    22 #include <sys/stat.h> /* open() */
    23 #include <fcntl.h> /* open() */
    2421#include <locale.h>
    2522#include <unistd.h> /* close() */
     
    3835#ifndef ENODATA
    3936 #define ENODATA EIO
    40 #endif
    41 
    42 #ifndef O_BINARY
    43  #define O_BINARY 0
    4437#endif
    4538
     
    15421535{
    15431536    int err = 0;
    1544     int fd = open( filename, O_CREAT|O_WRONLY|O_TRUNC|O_BINARY );
    1545 
    1546     if( fd < 0 )
     1537    FILE * fp = fopen( filename, "wb+" );
     1538
     1539    if( fp == NULL )
    15471540    {
    15481541        err = errno;
     
    15571550        while( !err && EVBUFFER_LENGTH( buf ) )
    15581551        {
    1559             if( evbuffer_write( buf, fd ) == -1 )
     1552            if( evbuffer_write( buf, fileno(fp) ) == -1 )
    15601553            {
    15611554                err = errno;
     
    15681561            tr_dbg( "tr_bencToFile saved \"%s\"", filename );
    15691562        evbuffer_free( buf );
    1570         close( fd );
     1563        fclose( fp );
    15711564    }
    15721565
Note: See TracChangeset for help on using the changeset viewer.