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,87 +161,124 @@ static size_t fcopy( FILE *fpout, FILE *fpin ) ...@@ -163,87 +161,124 @@ 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" );
fprintf( fp, report_filename = (char*)calloc(1, 2048);
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<!DOCTYPE errormail:errormail PUBLIC \"-//OpenOffice.org//DTD ErrorMail 1.0//EN\" \"errormail.dtd\">\n"
"<errormail:errormail xmlns:errormail=\"http://openoffice.org/2002/errormail\" usertype=\"%s\">\n"
"<reportmail:mail xmlns:reportmail=\"http://openoffice.org/2002/reportmail\" version=\"1.1\" feedback=\"%s\" email=\"%s\">\n"
"<reportmail:title>%s</reportmail:title>\n"
"<reportmail:attachment name=\"description.txt\" media-type=\"text/plain\" class=\"UserComment\"/>\n"
"<reportmail:attachment name=\"stack.txt\" media-type=\"text/plain\" class=\"pstack output\"/>\n"
"</reportmail:mail>\n"
"<officeinfo:officeinfo xmlns:officeinfo=\"http://openoffice.org/2002/officeinfo\" build=\"%s\" platform=\"%s\" language=\"%s\" exceptiontype=\"%d\" product=\"%s\" procpath=\"%s\"/>\n"
,
pszUserType ? xml_encode( pszUserType ).c_str() : "",
xml_encode(rSettings.find( "CONTACT" )->second).c_str(),
xml_encode(rSettings.find( "EMAIL" )->second).c_str(),
xml_encode(rSettings.find( "TITLE" )->second).c_str(),
g_buildid.length() ? xml_encode( g_buildid ).c_str() : "unknown",
_INPATH,
g_strDefaultLanguage.c_str(),
g_signal,
g_strProductKey.length() ? xml_encode(g_strProductKey).c_str() : "unknown",
xml_encode(getprogramdir()).c_str()
);
struct utsname info;
memset( &info, 0, sizeof(info) );
uname( &info );
fprintf( fp, if(!report_filename)
"<systeminfo:systeminfo xmlns:systeminfo=\"http://openoffice.org/2002/systeminfo\">\n"
"<systeminfo:System name=\"%s\" version=\"%s\" build=\"%s\" locale=\"%s\"/>\n"
,
xml_encode( info.sysname ).c_str(),
xml_encode( info.version ).c_str(),
xml_encode( info.release ).c_str(),
xml_encode( getlocale() ).c_str()
);
fprintf( fp, "<systeminfo:CPU type=\"%s\"/>\n", xml_encode( info.machine ).c_str() );
fprintf( fp, "</systeminfo:systeminfo>\n" );
FILE *fpxml = fopen( g_strXMLFileName.c_str(), "r" );
if ( fpxml )
{ {
fcopy( fp, fpxml ); return NULL;
fclose( fpxml );
} }
strncpy( report_filename, P_tmpdir, 2047 );
strncat( report_filename, "/crashreport.XXXXXX", 2047 - strlen(report_filename));
FILE *fpchk = fopen( g_strChecksumFileName.c_str(), "r" ); int fd = mkstemp(report_filename);
if ( fpchk ) if(fd == -1)
{ {
fcopy( fp, fpchk ); free(report_filename);
fclose( fpchk ); return NULL;
} }
else
{
FILE* fp = fdopen(fd, "w");
const char* pszUserType = getenv( "STAROFFICE_USERTYPE" );
fprintf( fp,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<!DOCTYPE errormail:errormail PUBLIC \"-//OpenOffice.org//DTD ErrorMail 1.0//EN\" \"errormail.dtd\">\n"
"<errormail:errormail xmlns:errormail=\"http://openoffice.org/2002/errormail\" usertype=\"%s\">\n"
"<reportmail:mail xmlns:reportmail=\"http://openoffice.org/2002/reportmail\" version=\"1.1\" feedback=\"%s\" email=\"%s\">\n"
"<reportmail:title>%s</reportmail:title>\n"
"<reportmail:attachment name=\"description.txt\" media-type=\"text/plain\" class=\"UserComment\"/>\n"
"<reportmail:attachment name=\"stack.txt\" media-type=\"text/plain\" class=\"pstack output\"/>\n"
"</reportmail:mail>\n"
"<officeinfo:officeinfo xmlns:officeinfo=\"http://openoffice.org/2002/officeinfo\" build=\"%s\" platform=\"%s\" language=\"%s\" exceptiontype=\"%d\" product=\"%s\" procpath=\"%s\"/>\n"
,
pszUserType ? xml_encode( pszUserType ).c_str() : "",
xml_encode(rSettings.find( "CONTACT" )->second).c_str(),
xml_encode(rSettings.find( "EMAIL" )->second).c_str(),
xml_encode(rSettings.find( "TITLE" )->second).c_str(),
g_buildid.length() ? xml_encode( g_buildid ).c_str() : "unknown",
_INPATH,
g_strDefaultLanguage.c_str(),
g_signal,
g_strProductKey.length() ? xml_encode(g_strProductKey).c_str() : "unknown",
xml_encode(getprogramdir()).c_str()
);
struct utsname info;
fprintf( fp, "</errormail:errormail>\n" ); memset( &info, 0, sizeof(info) );
uname( &info );
fclose( fp ); fprintf( fp,
"<systeminfo:systeminfo xmlns:systeminfo=\"http://openoffice.org/2002/systeminfo\">\n"
"<systeminfo:System name=\"%s\" version=\"%s\" build=\"%s\" locale=\"%s\"/>\n"
,
xml_encode( info.sysname ).c_str(),
xml_encode( info.version ).c_str(),
xml_encode( info.release ).c_str(),
xml_encode( getlocale() ).c_str()
);
fprintf( fp, "<systeminfo:CPU type=\"%s\"/>\n", xml_encode( info.machine ).c_str() );
fprintf( fp, "</systeminfo:systeminfo>\n" );
FILE *fpxml = fopen( g_strXMLFileName.c_str(), "r" );
if ( fpxml )
{
fcopy( fp, fpxml );
fclose( fpxml );
}
return true; FILE *fpchk = fopen( g_strChecksumFileName.c_str(), "r" );
if ( fpchk )
{
fcopy( fp, fpchk );
fclose( fpchk );
}
fprintf( fp, "</errormail:errormail>\n" );
fclose( fp );
}
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" );
if ( fp ) description_filename = (char*)calloc(1, 2048);
if(!description_filename)
{ {
bSuccess = true; return NULL;
fprintf( fp, "\xEF\xBB\xBF" );
fprintf( fp, "%s\n", rSettings.find( "DESCRIPTION" )->second.c_str() );
fclose( fp );
} }
strncpy( description_filename, P_tmpdir, 2047 );
strncat( description_filename, "/crashreport.XXXXXX", 2047 - strlen(description_filename));
return bSuccess; int fd = mkstemp(description_filename);
if(fd == -1)
{
free(description_filename);
return NULL;
}
else
{
FILE* fp = fdopen(fd, "w");
if ( fp )
{
fprintf( fp, "\xEF\xBB\xBF" );
fprintf( fp, "%s\n", rSettings.find( "DESCRIPTION" )->second.c_str() );
fclose( fp );
}
}
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,30 +497,38 @@ bool send_crash_report( const boost::unordered_map< string, string >& rSettings ...@@ -458,30 +497,38 @@ 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)
if ( fptemp )
{ {
WriteSOAPRequest( fptemp ); FILE* fptemp = tmpfile();
fseek( fptemp, 0, SEEK_SET ); if ( fptemp )
{
bSuccess = SendHTTPRequest( WriteSOAPRequest( fptemp, report_filename, description_filename );
fptemp, fseek( fptemp, 0, SEEK_SET );
REPORT_SERVER, REPORT_PORT,
bUseProxy ? pProxyServer : NULL, bSuccess = SendHTTPRequest(
uProxyPort ? uProxyPort : 8080 fptemp,
); REPORT_SERVER, REPORT_PORT,
bUseProxy ? pProxyServer : NULL,
fclose( fptemp ); uProxyPort ? uProxyPort : 8080
);
fclose( fptemp );
}
}
if(description_filename)
{
unlink( description_filename);
free( description_filename);
}
if(report_filename)
{
unlink( report_filename);
free( report_filename);
} }
unlink( g_szDescriptionFile );
unlink( g_szReportFile );
return bSuccess; return bSuccess;
} }
...@@ -980,25 +1027,28 @@ int main( int argc, char** argv ) ...@@ -980,25 +1027,28 @@ 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();
sPreviewFile += "/";
sPreviewFile += string(PRVFILE);
FILE *fpout = fopen( sPreviewFile.c_str(), "w+" );
if ( fpout )
{ {
FILE *fpin = fopen( g_szReportFile, "r" ); string sPreviewFile = get_home_dir();
if ( fpin ) sPreviewFile += "/";
sPreviewFile += string(PRVFILE);
FILE *fpout = fopen( sPreviewFile.c_str(), "w+" );
if ( fpout )
{ {
fcopy( fpout, fpin ); FILE *fpin = fopen( report_filename, "r" );
fclose( fpin ); if ( fpin )
{
fcopy( fpout, fpin );
fclose( fpin );
}
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