Hardening.

develop
Petr Mrázek 2011-11-01 13:06:27 +01:00
parent 98cab0e9ad
commit f0417e12dd
5 changed files with 51 additions and 46 deletions

@ -25,7 +25,7 @@ set(DF_VERSION_MINOR "31")
set(DF_VERSION_PATCH "25") set(DF_VERSION_PATCH "25")
set(DF_VERSION "${DF_VERSION_MAJOR}.${DF_VERSION_MINOR}.${DF_VERSION_PATCH}") set(DF_VERSION "${DF_VERSION_MAJOR}.${DF_VERSION_MINOR}.${DF_VERSION_PATCH}")
set(DFHACK_RELEASE "7") set(DFHACK_RELEASE "7b")
## where to install things (after the build is done, classic 'make install' or package structure) ## where to install things (after the build is done, classic 'make install' or package structure)
# the dfhack libraries will be installed here: # the dfhack libraries will be installed here:

@ -410,18 +410,9 @@ bool Core::Init()
p = new DFHack::Process(vif); p = new DFHack::Process(vif);
vinfo = p->getDescriptor(); vinfo = p->getDescriptor();
if(!vinfo) if(!vinfo || !p->isIdentified())
{ {
cerr << "Couldn't retrieve version information.\n"; cerr << "Not a known DF version. DFHack will now deactivate.\n";
errorstate = true;
delete p;
p = NULL;
return false;
}
if (!p->isIdentified())
{
cerr << "Couldn't identify this version of DF.\n";
errorstate = true; errorstate = true;
delete p; delete p;
p = NULL; p = NULL;

@ -48,28 +48,14 @@ Process::Process(VersionInfoFactory * known_versions)
const char * exe_link_name = "/proc/self/exe"; const char * exe_link_name = "/proc/self/exe";
const char * cwd_name = "/proc/self/cwd"; const char * cwd_name = "/proc/self/cwd";
const char * cmdline_name = "/proc/self/cmdline"; const char * cmdline_name = "/proc/self/cmdline";
char target_name[1024];
int target_result; int target_result;
identified = false; identified = false;
my_descriptor = 0; my_descriptor = 0;
// resolve /proc/self/exe link
target_result = readlink(exe_link_name, target_name, sizeof(target_name)-1);
if (target_result == -1)
{
cerr << "Failed to readlink(/proc/self/exe)\n";
return;
}
// make sure we have a null terminated string...
target_name[target_result] = 0;
// is this the regular linux DF?
if (strstr(target_name, "dwarfort.exe") != 0 || strstr(target_name,"Dwarf_Fortress") != 0)
{
md5wrapper md5; md5wrapper md5;
// get hash of the running DF process // get hash of the running DF process
string hash = md5.getHashFromFile(target_name); string hash = md5.getHashFromFile(exe_link_name);
// create linux process, add it to the vector // create linux process, add it to the vector
VersionInfo * vinfo = known_versions->getVersionInfoByMD5(hash); VersionInfo * vinfo = known_versions->getVersionInfoByMD5(hash);
if(vinfo) if(vinfo)
@ -80,13 +66,19 @@ Process::Process(VersionInfoFactory * known_versions)
} }
else else
{ {
char * wd = getcwd(NULL, 0);
cerr << "Unable to retrieve version information.\n"; cerr << "Unable to retrieve version information.\n";
cerr << "File: " << exe_link_name << endl;
cerr << "MD5: " << hash << endl;
cerr << "working dir: " << wd << endl;
free(wd);
} }
} }
else
{ Process::~Process()
cerr << "This isn't DF.\n"; {
} // destroy our copy of the memory descriptor
delete my_descriptor;
} }
string Process::doReadClassName (void * vptr) string Process::doReadClassName (void * vptr)

@ -24,7 +24,8 @@
//basic includes //basic includes
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <errno.h>
#include <string.h>
//my includes //my includes
#include "md5wrapper.h" #include "md5wrapper.h"
#include "md5.h" #include "md5.h"
@ -118,16 +119,33 @@ std::string md5wrapper::getHashFromFile(std::string filename)
//open file //open file
if ((file = fopen (filename.c_str(), "rb")) == NULL) if ((file = fopen (filename.c_str(), "rb")) == NULL)
{ {
return "-1"; return "file unreadable.";
} }
//init md5 //init md5
md5->MD5Init (&context); md5->MD5Init (&context);
//read the filecontent //read the filecontent
while ( (len = fread (buffer, 1, 1024, file)) ) while (1)
{
errno = 0;
len = fread (buffer, 1, 1024, file);
if(len != 1024)
{
int err = ferror(file);
//FIXME: check errno here.
if(err)
{
fclose(file);
return strerror(err);
}
if(feof(file))
{ {
md5->MD5Update (&context, buffer, len); md5->MD5Update (&context, buffer, len);
break;
}
}
md5->MD5Update (&context, buffer, len);
} }
/* /*

@ -78,10 +78,14 @@ command_result cleanmap (Core * c, bool snow, bool mud)
{ {
DFHack::t_spattervein * vein = splatter[i]; DFHack::t_spattervein * vein = splatter[i];
// filter snow // filter snow
if(!snow && vein->mat1 == water_idx && vein->matter_state == DFHack::state_powder) if(!snow
&& vein->mat1 == DFHack::Materials::WATER
&& vein->matter_state == DFHack::state_powder)
continue; continue;
// filter mud // filter mud
if(!mud && vein->mat1 == mud_idx && vein->matter_state == DFHack::state_solid) if(!mud
&& vein->mat1 == DFHack::Materials::MUD
&& vein->matter_state == DFHack::state_solid)
continue; continue;
Mapz->RemoveBlockEvent(x,y,z,(t_virtual *) vein); Mapz->RemoveBlockEvent(x,y,z,(t_virtual *) vein);
cleaned = true; cleaned = true;