diff --git a/SConstruct b/SConstruct index 437547c10469b89543a52aff04ccf79f8022f069..2eb231368d1cbcf75e96cd03583b8de36c92be82 100644 --- a/SConstruct +++ b/SConstruct @@ -9,9 +9,9 @@ env=Environment() # default build options -env.Replace(CFLAGS="-fPIC -Wall ") -env.Replace(CXXFLAGS="-fPIC -Wall ") -env.Replace(LINKFLAGS="-fPIC -Wall ") +env.Replace(CFLAGS="-fPIC -Wall -Werror ") +env.Replace(CXXFLAGS="-fPIC -Wall -Werror ") +env.Replace(LINKFLAGS="-fPIC -Wall -Werror ") # parse arguments env.Replace(SECURITY_TRANSFORMS_HOME=os.environ['SECURITY_TRANSFORMS_HOME']) diff --git a/libIRDB/include/utils.hpp b/libIRDB/include/utils.hpp index b9a2899c5facee5dd2653ec9bcfbb8b933cb8d91..224f26a3d06de28cc0af03bed8ce9993ed7389d9 100644 --- a/libIRDB/include/utils.hpp +++ b/libIRDB/include/utils.hpp @@ -100,23 +100,24 @@ template<class T> inline T strtoint(std::string s) template <typename IterType, typename Funct> inline Funct for_randomOrder_each(const IterType &b, const IterType & e, const Funct &callback) { - std::map<int,const typename std::iterator_traits<IterType>::value_type *> m; - for_each(b,e, [&](const typename std::iterator_traits<IterType>::value_type & o) - { - while(true) - { - int rn=rand(); - if(m.find(rn)==m.end()) - { - m[rn]=&o; - break; - } - } - }); - for_each(m.begin(), m.end(), [&](const std::pair<int,const typename std::iterator_traits<IterType>::value_type *> &p) - { - callback(*p.second); - }); + std::map<int,const typename std::iterator_traits<IterType>::value_type *> m; + for_each(b,e, [&](const typename std::iterator_traits<IterType>::value_type & o) + { + while(true) + { + int rn=rand(); + if(m.find(rn)==m.end()) + { + m[rn]=&o; + break; + } + } + }); + for_each(m.begin(), m.end(), [&](const std::pair<int,const typename std::iterator_traits<IterType>::value_type *> &p) + { + callback(*p.second); + }); + return callback; } #endif diff --git a/libIRDB/src/core/SConscript b/libIRDB/src/core/SConscript index 2c45161c39a575d74a1e339ea5e2a08e1fd8ee21..c1251720c086064332b08ab6a369ecf028e2ae83 100644 --- a/libIRDB/src/core/SConscript +++ b/libIRDB/src/core/SConscript @@ -39,10 +39,10 @@ cpppath=''' . $SECURITY_TRANSFORMS_HOME/include/ $SECURITY_TRANSFORMS_HOME/libIRDB/include/ - $SECURITY_TRANSFORMS_HOME/beaengine/include - $SECURITY_TRANSFORMS_HOME/beaengine/beaengineSources/Includes/ $SECURITY_TRANSFORMS_HOME/libcapstone/include/ ''' +# $SECURITY_TRANSFORMS_HOME/beaengine/include +# $SECURITY_TRANSFORMS_HOME/beaengine/beaengineSources/Includes/ globs=glob.glob(os.environ['SECURITY_TRANSFORMS_HOME']+'/libcapstone/zipr_unpack/*.o') diff --git a/libIRDB/src/core/file.cpp b/libIRDB/src/core/file.cpp index addefcdf891aa9ad3e24e9b76f7424541f1b3b3c..b7560f892ea421811aeafb8bbfb2b78c37b0f98b 100644 --- a/libIRDB/src/core/file.cpp +++ b/libIRDB/src/core/file.cpp @@ -29,6 +29,8 @@ using namespace libIRDB; using namespace std; +static void ignore_result(int /* res */) { } + File_t::File_t(const db_id_t &myfile_id, const db_id_t &my_orig_fid, const std::string &myurl, @@ -80,7 +82,7 @@ void File_t::CreateTables() ehcss_table_name+" "+ tmpfile; - system(command.c_str()); + ignore_result(system(command.c_str())); std::ifstream t(tmpfile.c_str()); diff --git a/libIRDB/src/core/instruction.cpp b/libIRDB/src/core/instruction.cpp index f6ec551cf0a527ed00352e9043e1a48fee706a20..27a990218f4f83a65ef03faa8d418a325497700c 100644 --- a/libIRDB/src/core/instruction.cpp +++ b/libIRDB/src/core/instruction.cpp @@ -30,6 +30,9 @@ using namespace libIRDB; using namespace std; +static void ignore_result(int /* res */) { } + + Instruction_t::Instruction_t() : BaseObj_t(NULL), my_address(NULL), @@ -112,9 +115,9 @@ bool Instruction_t::Assemble(string assembly) //remove any preexisting assembly or nasm generated files string command = "rm -f " + assemblyFile; - system(command.c_str()); + ignore_result(system(command.c_str())); command = "rm -f "+assemblyFile+".bin"; - system(command.c_str()); + ignore_result(system(command.c_str())); ofstream asmFile; asmFile.open(assemblyFile.c_str()); @@ -129,7 +132,7 @@ bool Instruction_t::Assemble(string assembly) asmFile.close(); command = "nasm " + assemblyFile + " -o "+ binaryOutputFile; - system(command.c_str()); + ignore_result(system(command.c_str())); ifstream binreader; unsigned int filesize; diff --git a/libIRDB/test/read_ehframe.cpp b/libIRDB/test/read_ehframe.cpp index fa4186d57a69fc40be7d51c7dad7e1641ea6f018..5fef4dc7a5d1ea9df6354827d0ef66771f0c7234 100644 --- a/libIRDB/test/read_ehframe.cpp +++ b/libIRDB/test/read_ehframe.cpp @@ -785,8 +785,12 @@ void linear_search_fdes (struct object *ob, fde *this_fde, int offset) if (encoding == DW_EH_PE_absptr) { - pc_begin = ((_Unwind_Ptr *) this_fde->pc_begin)[0]; - pc_range = ((_Unwind_Ptr *) this_fde->pc_begin)[1]; + //pc_begin = ((_Unwind_Ptr *) this_fde->pc_begin)[0]; + auto my_pc_begin=(_Unwind_Ptr*)(this_fde->pc_begin); + memcpy(&pc_begin, my_pc_begin, sizeof(_Unwind_Ptr)); + //pc_range = ((_Unwind_Ptr *) this_fde->pc_begin)[1]; + memcpy(&pc_range, my_pc_begin+1, sizeof(_Unwind_Ptr)); + if(getenv("EH_VERBOSE")) { cout<<"absptr pc_begin 0x"<<std::hex<<(pc_begin+offset)<<"\t"; diff --git a/libStructDiv/src/filebased.cpp b/libStructDiv/src/filebased.cpp index 8843cd22c6cdd5b623fd80a8a8751e66d913351b..67fdfa51931044686e8f5eca7bba41712121848a 100644 --- a/libStructDiv/src/filebased.cpp +++ b/libStructDiv/src/filebased.cpp @@ -18,6 +18,9 @@ using namespace std; using namespace libStructDiv; +void ignore_result(int /* res */ ) {} + + template<typename T> std::string toString(const T& value) { std::ostringstream oss; @@ -73,7 +76,7 @@ FileBased_StructuredDiversity_t::FileBased_StructuredDiversity_t(string key, int } cout<<"Initing shared path: "<<m_shared_dir<<endl<<"Contents:"<<endl; string ls_cmd="ls "+m_shared_dir; - system(ls_cmd.c_str()); + ignore_result(system(ls_cmd.c_str())); #else assert(0); // filesystem sharing not implement on non-linux platforms yet #endif diff --git a/tools/spasm/spasm.cpp b/tools/spasm/spasm.cpp index d9ac1d01001df183af596812144d98276c22a3d0..acb9f8b471476a5ac5465e41c5b694b462979cf2 100755 --- a/tools/spasm/spasm.cpp +++ b/tools/spasm/spasm.cpp @@ -38,14 +38,14 @@ #include <stdlib.h> #include <sys/types.h> #include <unistd.h> - - #include "elfio/elfio.hpp" - #include "ben_lib.h" using namespace std; +void ignore_result(int /* res */) { } + + static string regularAddressRegex = "0x[[:xdigit:]]+"; static string offsetAddressRegex = "[a-zA-Z0-9\\._-]+[[:blank:]]*[+][[:blank:]]*0x[[:xdigit:]]+|[a-zA-Z0-9\\._]+[[:blank:]]*[+][[:blank:]]*[[:xdigit:]]+"; @@ -153,7 +153,7 @@ static uintptr_t getSymbolAddress(const string &symbolFilename, const string &sy FILE *fp = popen(command.c_str(), "r"); - fscanf(fp,"%s", address); + ignore_result(fscanf(fp,"%s", address)); string addressString = string(address); //TODO: throw exception if address is not found. @@ -389,11 +389,11 @@ static void assemble(const string &assemblyFile, int bits) //remove any preexisting assembly or nasm generated files string command = "rm -f " + assemblyFile; - system(command.c_str()); + ignore_result(system(command.c_str())); command = "rm -f "+assemblyFile+".bin"; - system(command.c_str()); + ignore_result(system(command.c_str())); command = "rm -f "+assemblyFile+".map"; - system(command.c_str()); + ignore_result(system(command.c_str())); ofstream asmFile; @@ -508,7 +508,7 @@ static void assemble(const string &assemblyFile, int bits) //TODO: check if system fails, make a func call to handle system command = "nasm -O1 -w-number-overflow " + assemblyFile + " -o "+assemblyFile+".bin"; cout<<"Running nasm ("<<command<<")..."; - system(command.c_str()); + ignore_result(system(command.c_str())); cout<<"Done!"<<endl; diff --git a/tools/transforms/PNTransformDriver.cpp b/tools/transforms/PNTransformDriver.cpp index 6bca7926edb6855423546679637abd061ca1dfa0..6b0bba2c696744959d75330312ea5ad6a3d97f1f 100644 --- a/tools/transforms/PNTransformDriver.cpp +++ b/tools/transforms/PNTransformDriver.cpp @@ -39,6 +39,8 @@ #include <sys/wait.h> +void ignore_result(int /* res */ ) { } + #ifndef PATH_MAX #define PATH_MAX 4096 #endif @@ -2131,7 +2133,7 @@ bool PNTransformDriver::Validate(FileIR_t *virp, string name) rm_command+=bin_filename + " "; rm_command+=map_filename + " "; - system(rm_command.c_str()); // don't bother with an error check. + ignore_result(system(rm_command.c_str())); // don't bother with an error check. return (retval == 0); } diff --git a/xform/rewriter.cpp b/xform/rewriter.cpp index 5c79a40192685cbf343b52121870780f4a47b4ce..0a826ebf1011134f0c5d352203cfdae3038946ff 100644 --- a/xform/rewriter.cpp +++ b/xform/rewriter.cpp @@ -36,6 +36,10 @@ using namespace std; using namespace libIRDB; +template <class T> +void ignore_result(T /* res */) { } + + Rewriter::Rewriter(char *p_elfPath, char *p_annotationFilePath) { m_elfReader = new ElfReader(p_elfPath); @@ -110,12 +114,12 @@ void Rewriter::readAnnotationFile(char p_filename[]) do { - fscanf(fin, "%p%d", (void**)&addr, &size_type_u.size); + ignore_result(fscanf(fin, "%p%d", (void**)&addr, &size_type_u.size)); if(feof(fin)) // deal with blank lines at the EOF break; - fscanf(fin, "%s%s", type,scope); + ignore_result(fscanf(fin, "%s%s", type,scope)); int annot_type; if(size_type_u.type<-255) @@ -143,7 +147,7 @@ void Rewriter::readAnnotationFile(char p_filename[]) funclist_hash_key_t *flhk=(funclist_hash_key_t*)spri_allocate_type(sizeof(funclist_hash_key_t)); funclist_hash_value_t *flhv=(funclist_hash_value_t*)spri_allocate_type(sizeof(funclist_hash_value_t)); - fscanf(fin,"%s", name); + ignore_result(fscanf(fin,"%s", name)); flhk->name=spri_strdup(name); flhv->pc=addr; // fprintf(stderr, "Adding name=%s pc=%x to funclist hash table\n", flhk->name, flhv->pc); @@ -154,7 +158,7 @@ void Rewriter::readAnnotationFile(char p_filename[]) fn->setSize(size_type_u.size); fn->setName(name); // wahoo::Function *fn = new wahoo::Function(name, addr, size_type_u.size); - fgets(remainder, sizeof(remainder), fin); + ignore_result(fgets(remainder, sizeof(remainder), fin)); if (strstr(remainder, "FUNC_SAFE")) fn->setSafe(); else @@ -176,12 +180,12 @@ void Rewriter::readAnnotationFile(char p_filename[]) while(1) // loop until found ZZ { - fscanf(fin, "%s", zz); + ignore_result(fscanf(fin, "%s", zz)); if(strcmp("ZZ", zz)==0) break; reg_num=atoi(zz); - fscanf(fin,"%d%d", ®_offset, ®_type); + ignore_result(fscanf(fin,"%d%d", ®_offset, ®_type)); assert(reg_num==reg); frame_restore_hash_add_reg_restore(addr,reg_num,reg_offset,reg_type); reg++; @@ -190,7 +194,7 @@ void Rewriter::readAnnotationFile(char p_filename[]) else if(strcmp(scope,"MMSAFENESS")==0) { char safeness[1000]; - fscanf(fin, "%s", safeness); + ignore_result(fscanf(fin, "%s", safeness)); if(strcmp(safeness, "SAFE") == 0) { // @@ -222,7 +226,7 @@ void Rewriter::readAnnotationFile(char p_filename[]) /* found function declaration */ assert(strcmp(scope,"STACK")==0); /* remaining parameters are "esp + <const> <name>" */ - fscanf(fin, "%s%s%d%s", esp, plus, &offset, name); + ignore_result(fscanf(fin, "%s%s%d%s", esp, plus, &offset, name)); if(strcmp(name, "ReturnAddress")==0) { @@ -296,7 +300,7 @@ void Rewriter::readAnnotationFile(char p_filename[]) val->size = size_type_u.size; Hashtable_put(instrmaps_hash,key,val); - fgets(remainder, sizeof(remainder), fin); + ignore_result(fgets(remainder, sizeof(remainder), fin)); // this is a *potential* stack deallocation instruction only if ((strstr(remainder,"leave") && strstr(remainder,"EFLAGS")) || (strstr(remainder,"pop" ) && strstr(remainder,"ebp" )) @@ -319,7 +323,7 @@ void Rewriter::readAnnotationFile(char p_filename[]) else if (strcmp(scope, "BELONGTO") == 0) { app_iaddr_t func_addr; - fscanf(fin, "%p", (void**)&func_addr); + ignore_result(fscanf(fin, "%p", (void**)&func_addr)); instrmap_hash_key_t* key = (instrmap_hash_key_t*)spri_allocate_type(sizeof(instrmap_hash_key_t)); instrmap_hash_value_t* val = (instrmap_hash_value_t*)spri_allocate_type(sizeof(instrmap_hash_value_t)); key->pc = addr; @@ -330,7 +334,7 @@ void Rewriter::readAnnotationFile(char p_filename[]) // rely on the fact that INST BELONGTO is the first INST annotation in a MEDS file (warning: but it is not required to be there) // assert(m_functions[func_addr]); - (void)ensureFunctionExists(func_addr); + ignore_result(ensureFunctionExists(func_addr)); wahoo::Instruction* instr = new wahoo::Instruction(addr, -1, m_functions[func_addr]); m_instructions[addr] = instr; @@ -359,7 +363,7 @@ void Rewriter::readAnnotationFile(char p_filename[]) case -1: /* no meta data updates */ /* remaining params: <reason> comment */ { - fgets(remainder, sizeof(remainder), fin); + ignore_result(fgets(remainder, sizeof(remainder), fin)); // this is a *potential* stack deallocation instruction only if (strstr(remainder,"add") && strstr(remainder,"esp") && strstr(remainder,"1stSrcVia2ndSrc") @@ -441,11 +445,11 @@ MEDS doesn't mark this as a stack reference assert(strcmp(scope,"STACK")==0 || strcmp(scope,"GLOBAL")==0); /* remaining params are <const> <field> <real_const_if_global> <comment> */ - fscanf(fin, "%d%s", &the_const, field); + ignore_result(fscanf(fin, "%d%s", &the_const, field)); if( strcmp(type,"PTRIMMEDESP2")==0 || strcmp(type,"PTRIMMEDABSOLUTE")==0 ) - fscanf(fin, "%x", &real_const); + ignore_result(fscanf(fin, "%x", &real_const)); else real_const=the_const; @@ -488,7 +492,7 @@ MEDS doesn't mark this as a stack reference // see if we can pick up access to local variables // and access to arguments off esp - fgets(remainder, sizeof(remainder), fin); + ignore_result(fgets(remainder, sizeof(remainder), fin)); if (strstr(remainder, "var_") || (strstr(remainder, "arg_") && strstr(remainder, "[esp"))) { @@ -510,7 +514,7 @@ MEDS doesn't mark this as a stack reference else if(strcmp(scope,"GLOBAL")==0) { /* remaining params id, addr, parent/child, name */ - fscanf(fin, "%d%p%s", &id, (void**)&addr, parent_child); + ignore_result(fscanf(fin, "%d%p%s", &id, (void**)&addr, parent_child)); if(strcmp(parent_child, "PARENT")==0) { @@ -528,7 +532,7 @@ MEDS doesn't mark this as a stack reference int esp_offset; /* remaining params id, addr, parent/child, name */ - fscanf(fin, "%d%s%s%d%s%s", &id, esp, plus, &esp_offset, parent_child, name); + ignore_result(fscanf(fin, "%d%s%s%d%s%s", &id, esp, plus, &esp_offset, parent_child, name)); assert(strcmp(esp, "esp")==0 && strcmp(plus,"+")==0); @@ -537,7 +541,7 @@ MEDS doesn't mark this as a stack reference /* add to the stackref hashtable, also record the id->stackref mapping so we can * can easily lookup the id for any fields we find. */ - (void)add_stack_ref(addr,size_type_u.size, esp_offset); + ignore_result(add_stack_ref(addr,size_type_u.size, esp_offset)); // @todo: record frame size @@ -562,7 +566,7 @@ any esp access outside this region (esp + K) >= (esp + size) can be xformed 80482fd 4 DATAREF STACK 3125 esp + 32 CHILDOF 3122 OFFSET 32 LOCALVAR var_1C 80482fd 4 DATAREF STACK 3126 esp + 36 CHILDOF 3122 OFFSET 36 LOCALVAR var_18 */ - fgets(remainder, sizeof(remainder), fin); + ignore_result(fgets(remainder, sizeof(remainder), fin)); if (strstr(remainder,"OutArgsRegion")) { //fprintf(stderr," found OutArgsRegion @ 0x%08x\n", addr); @@ -612,7 +616,7 @@ any esp access outside this region (esp + K) >= (esp + size) can be xformed fprintf(stderr, "Fatal, Unknown type at line %d\n", line); } - fgets(remainder, sizeof(remainder), fin); + ignore_result(fgets(remainder, sizeof(remainder), fin)); line++; } while(!feof(fin)); fclose(fin); @@ -641,16 +645,16 @@ void Rewriter::readElfFile(char p_filename[]) void* tmp=NULL; - fscanf(pin, "%p", &tmp); + ignore_result(fscanf(pin, "%p", &tmp)); addr=(app_iaddr_t)tmp; - fgets(buf,sizeof(buf),pin); + ignore_result(fgets(buf,sizeof(buf),pin)); do { if(m_instructions[addr]==NULL) m_instructions[addr]=new wahoo::Instruction(addr,-1,NULL); - fscanf(pin,"%p", &tmp); + ignore_result(fscanf(pin,"%p", &tmp)); addr=(app_iaddr_t)tmp; - fgets(buf,sizeof(buf),pin); + ignore_result(fgets(buf,sizeof(buf),pin)); } while(!feof(pin)); pclose(pin);