mirror of
https://github.com/transmission/transmission
synced 2025-03-06 11:38:21 +00:00
(trunk libT) fix potential permissions headache when saving json/benc files
This commit is contained in:
parent
5898c8b276
commit
ab56a2f7f7
1 changed files with 4 additions and 11 deletions
|
@ -18,9 +18,6 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <sys/types.h> /* open() */
|
|
||||||
#include <sys/stat.h> /* open() */
|
|
||||||
#include <fcntl.h> /* open() */
|
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include <unistd.h> /* close() */
|
#include <unistd.h> /* close() */
|
||||||
|
|
||||||
|
@ -39,10 +36,6 @@
|
||||||
#define ENODATA EIO
|
#define ENODATA EIO
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef O_BINARY
|
|
||||||
#define O_BINARY 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
***
|
***
|
||||||
**/
|
**/
|
||||||
|
@ -1541,9 +1534,9 @@ int
|
||||||
tr_bencToFile( const tr_benc * top, tr_fmt_mode mode, const char * filename )
|
tr_bencToFile( const tr_benc * top, tr_fmt_mode mode, const char * filename )
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
int fd = open( filename, O_CREAT|O_WRONLY|O_TRUNC|O_BINARY );
|
FILE * fp = fopen( filename, "wb+" );
|
||||||
|
|
||||||
if( fd < 0 )
|
if( fp == NULL )
|
||||||
{
|
{
|
||||||
err = errno;
|
err = errno;
|
||||||
tr_err( _( "Couldn't open \"%1$s\": %2$s" ),
|
tr_err( _( "Couldn't open \"%1$s\": %2$s" ),
|
||||||
|
@ -1556,7 +1549,7 @@ tr_bencToFile( const tr_benc * top, tr_fmt_mode mode, const char * filename )
|
||||||
|
|
||||||
while( !err && EVBUFFER_LENGTH( buf ) )
|
while( !err && EVBUFFER_LENGTH( buf ) )
|
||||||
{
|
{
|
||||||
if( evbuffer_write( buf, fd ) == -1 )
|
if( evbuffer_write( buf, fileno(fp) ) == -1 )
|
||||||
{
|
{
|
||||||
err = errno;
|
err = errno;
|
||||||
tr_err( _( "Couldn't save file \"%1$s\": %2$s" ),
|
tr_err( _( "Couldn't save file \"%1$s\": %2$s" ),
|
||||||
|
@ -1567,7 +1560,7 @@ tr_bencToFile( const tr_benc * top, tr_fmt_mode mode, const char * filename )
|
||||||
if( !err )
|
if( !err )
|
||||||
tr_dbg( "tr_bencToFile saved \"%s\"", filename );
|
tr_dbg( "tr_bencToFile saved \"%s\"", filename );
|
||||||
evbuffer_free( buf );
|
evbuffer_free( buf );
|
||||||
close( fd );
|
fclose( fp );
|
||||||
}
|
}
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
|
|
Loading…
Add table
Reference in a new issue