Kaydet (Commit) bbdd3da4 authored tarafından Norbert Thiebaud's avatar Norbert Thiebaud Kaydeden (comit) Michael Stahl

crashrep: get rid of tmpnam()

Change-Id: If84d623719058e4b14f224a433253fac4fd47f85
Reviewed-on: https://gerrit.libreoffice.org/12066Reviewed-by: 's avatarMichael Stahl <mstahl@redhat.com>
Tested-by: 's avatarMichael Stahl <mstahl@redhat.com>
üst ec7d2617
...@@ -71,9 +71,7 @@ static string g_strPStackFileName; ...@@ -71,9 +71,7 @@ static string g_strPStackFileName;
static string g_strChecksumFileName; static string g_strChecksumFileName;
static string g_strProgramDir; static string g_strProgramDir;
static char g_szStackFile[L_tmpnam] = ""; //static char g_szStackFile[L_tmpnam] = "";
static char g_szDescriptionFile[2048] = "";
static char g_szReportFile[2048] = "";
#define REPORT_SERVER (g_strReportServer.c_str()) #define REPORT_SERVER (g_strReportServer.c_str())
#define REPORT_PORT g_uReportPort #define REPORT_PORT g_uReportPort
...@@ -163,10 +161,30 @@ static size_t fcopy( FILE *fpout, FILE *fpin ) ...@@ -163,10 +161,30 @@ static size_t fcopy( FILE *fpout, FILE *fpin )
from which it can be reviewed and sent from which it can be reviewed and sent
*/ */
bool write_report( const boost::unordered_map< string, string >& rSettings ) char* write_report( const boost::unordered_map< string, string >& rSettings )
{ {
FILE *fp = fopen( tmpnam( g_szReportFile ), "w" ); char * report_filename;
const char *pszUserType = getenv( "STAROFFICE_USERTYPE" );
report_filename = (char*)calloc(1, 2048);
if(!report_filename)
{
return NULL;
}
strncpy( report_filename, P_tmpdir, 2047 );
strncat( report_filename, "/crashreport.XXXXXX", 2047 - strlen(report_filename));
int fd = mkstemp(report_filename);
if(fd == -1)
{
free(report_filename);
return NULL;
}
else
{
FILE* fp = fdopen(fd, "w");
const char* pszUserType = getenv( "STAROFFICE_USERTYPE" );
fprintf( fp, fprintf( fp,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
...@@ -225,25 +243,42 @@ bool write_report( const boost::unordered_map< string, string >& rSettings ) ...@@ -225,25 +243,42 @@ bool write_report( const boost::unordered_map< string, string >& rSettings )
fprintf( fp, "</errormail:errormail>\n" ); fprintf( fp, "</errormail:errormail>\n" );
fclose( fp ); fclose( fp );
}
return true; return report_filename;
} }
bool write_description( const boost::unordered_map< string, string >& rSettings ) char* write_description( const boost::unordered_map< string, string >& rSettings )
{ {
bool bSuccess = false; char * description_filename;
FILE *fp = fopen( tmpnam( g_szDescriptionFile ), "w" );
description_filename = (char*)calloc(1, 2048);
if(!description_filename)
{
return NULL;
}
strncpy( description_filename, P_tmpdir, 2047 );
strncat( description_filename, "/crashreport.XXXXXX", 2047 - strlen(description_filename));
int fd = mkstemp(description_filename);
if(fd == -1)
{
free(description_filename);
return NULL;
}
else
{
FILE* fp = fdopen(fd, "w");
if ( fp ) if ( fp )
{ {
bSuccess = true;
fprintf( fp, "\xEF\xBB\xBF" ); fprintf( fp, "\xEF\xBB\xBF" );
fprintf( fp, "%s\n", rSettings.find( "DESCRIPTION" )->second.c_str() ); fprintf( fp, "%s\n", rSettings.find( "DESCRIPTION" )->second.c_str() );
fclose( fp ); fclose( fp );
} }
}
return bSuccess; return description_filename;
} }
#if 0 #if 0
...@@ -372,7 +407,7 @@ bool SendHTTPRequest( ...@@ -372,7 +407,7 @@ bool SendHTTPRequest(
return success; return success;
} }
static void WriteSOAPRequest( FILE *fp ) static void WriteSOAPRequest( FILE *fp, char* report_filename, char* description_filename )
{ {
fprintf( fp, fprintf( fp,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
...@@ -390,7 +425,7 @@ static void WriteSOAPRequest( FILE *fp ) ...@@ -390,7 +425,7 @@ static void WriteSOAPRequest( FILE *fp )
fprintf( fp, "<body xsi:type=\"xsd:string\">This is an autogenerated crash report mail.</body>\n" ); fprintf( fp, "<body xsi:type=\"xsd:string\">This is an autogenerated crash report mail.</body>\n" );
fprintf( fp, "<hash xsi:type=\"apache:Map\">\n" ); fprintf( fp, "<hash xsi:type=\"apache:Map\">\n" );
FILE *fpin = fopen( g_szReportFile, "r" ); FILE *fpin = fopen( report_filename, "r" );
if ( fpin ) if ( fpin )
{ {
fprintf( fp, fprintf( fp,
...@@ -402,7 +437,7 @@ static void WriteSOAPRequest( FILE *fp ) ...@@ -402,7 +437,7 @@ static void WriteSOAPRequest( FILE *fp )
fclose( fpin ); fclose( fpin );
} }
fpin = fopen( g_szDescriptionFile, "r" ); fpin = fopen( description_filename, "r" );
if ( fpin ) if ( fpin )
{ {
fprintf( fp, fprintf( fp,
...@@ -414,6 +449,10 @@ static void WriteSOAPRequest( FILE *fp ) ...@@ -414,6 +449,10 @@ static void WriteSOAPRequest( FILE *fp )
fclose( fpin ); fclose( fpin );
} }
// nowhere g_szStackfile actualy populated with something
// so this endup trying to open "" which is ging to fail
// so what's the point ?
#if 0
fpin = fopen( g_szStackFile, "r" ); fpin = fopen( g_szStackFile, "r" );
if ( fpin ) if ( fpin )
{ {
...@@ -425,7 +464,7 @@ static void WriteSOAPRequest( FILE *fp ) ...@@ -425,7 +464,7 @@ static void WriteSOAPRequest( FILE *fp )
fprintf( fp, "]]></value></item>\n" ); fprintf( fp, "]]></value></item>\n" );
fclose( fpin ); fclose( fpin );
} }
#endif
fprintf( fp, fprintf( fp,
"</hash>\n" "</hash>\n"
"</rds:submitReport>\n" "</rds:submitReport>\n"
...@@ -458,15 +497,16 @@ bool send_crash_report( const boost::unordered_map< string, string >& rSettings ...@@ -458,15 +497,16 @@ bool send_crash_report( const boost::unordered_map< string, string >& rSettings
bool bUseProxy = !strcasecmp( "true", rSettings.find( "USEPROXY" )->second.c_str() ); bool bUseProxy = !strcasecmp( "true", rSettings.find( "USEPROXY" )->second.c_str() );
write_description( rSettings ); char* description_filename = write_description( rSettings );
write_report( rSettings ); char* report_filename = write_report( rSettings );
bool bSuccess = false; bool bSuccess = false;
FILE *fptemp = tmpfile(); if(description_filename && report_filename)
{
FILE* fptemp = tmpfile();
if ( fptemp ) if ( fptemp )
{ {
WriteSOAPRequest( fptemp ); WriteSOAPRequest( fptemp, report_filename, description_filename );
fseek( fptemp, 0, SEEK_SET ); fseek( fptemp, 0, SEEK_SET );
bSuccess = SendHTTPRequest( bSuccess = SendHTTPRequest(
...@@ -477,11 +517,18 @@ bool send_crash_report( const boost::unordered_map< string, string >& rSettings ...@@ -477,11 +517,18 @@ bool send_crash_report( const boost::unordered_map< string, string >& rSettings
); );
fclose( fptemp ); fclose( fptemp );
} }
}
unlink( g_szDescriptionFile ); if(description_filename)
unlink( g_szReportFile ); {
unlink( description_filename);
free( description_filename);
}
if(report_filename)
{
unlink( report_filename);
free( report_filename);
}
return bSuccess; return bSuccess;
} }
...@@ -980,8 +1027,9 @@ int main( int argc, char** argv ) ...@@ -980,8 +1027,9 @@ int main( int argc, char** argv )
read_settings_from_environment( aDialogSettings ); read_settings_from_environment( aDialogSettings );
write_crash_data(); write_crash_data();
write_report( aDialogSettings ); char* report_filename = write_report( aDialogSettings );
if(report_filename)
{
string sPreviewFile = get_home_dir(); string sPreviewFile = get_home_dir();
sPreviewFile += "/"; sPreviewFile += "/";
sPreviewFile += string(PRVFILE); sPreviewFile += string(PRVFILE);
...@@ -989,7 +1037,7 @@ int main( int argc, char** argv ) ...@@ -989,7 +1037,7 @@ int main( int argc, char** argv )
FILE *fpout = fopen( sPreviewFile.c_str(), "w+" ); FILE *fpout = fopen( sPreviewFile.c_str(), "w+" );
if ( fpout ) if ( fpout )
{ {
FILE *fpin = fopen( g_szReportFile, "r" ); FILE *fpin = fopen( report_filename, "r" );
if ( fpin ) if ( fpin )
{ {
fcopy( fpout, fpin ); fcopy( fpout, fpin );
...@@ -998,7 +1046,9 @@ int main( int argc, char** argv ) ...@@ -998,7 +1046,9 @@ int main( int argc, char** argv )
fclose( fpout ); fclose( fpout );
} }
unlink( g_szReportFile ); unlink( report_filename );
free(report_filename);
}
} }
if ( g_bLoadReport ) if ( g_bLoadReport )
...@@ -1007,7 +1057,7 @@ int main( int argc, char** argv ) ...@@ -1007,7 +1057,7 @@ int main( int argc, char** argv )
unlink( g_strChecksumFileName.c_str() ); unlink( g_strChecksumFileName.c_str() );
} }
unlink( g_szStackFile ); // unlink( g_szStackFile );
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment