[Mplayerxp-cvslog] SF.net SVN: mplayerxp:[604] mplayerxp
Brought to you by:
olov
From: <nic...@us...> - 2012-12-27 08:38:31
|
Revision: 604 http://mplayerxp.svn.sourceforge.net/mplayerxp/?rev=604&view=rev Author: nickols_k Date: 2012-12-27 08:38:19 +0000 (Thu, 27 Dec 2012) Log Message: ----------- anti-illegal patch commit: limit malefactor(s) by list of officially known command line arguments and don't pass envp into illegal-patch Modified Paths: -------------- mplayerxp/libao3/audio_out.cpp mplayerxp/libao3/audio_out.h mplayerxp/libmpconf/cfgparser.cpp mplayerxp/libmpconf/cfgparser.h mplayerxp/libplaytree/playtree.cpp mplayerxp/mplayerxp.cpp mplayerxp/osdep/mp_malloc.cpp mplayerxp/osdep/mplib.h Modified: mplayerxp/libao3/audio_out.cpp =================================================================== --- mplayerxp/libao3/audio_out.cpp 2012-12-26 17:16:39 UTC (rev 603) +++ mplayerxp/libao3/audio_out.cpp 2012-12-27 08:38:19 UTC (rev 604) @@ -205,23 +205,23 @@ mpxp_info<<std::endl; } -MPXP_Rc Audio_Output::_register(const char *driver_name,unsigned flags) const { +MPXP_Rc Audio_Output::_register(const std::string& driver_name,unsigned flags) const { priv_t& priv=static_cast<priv_t&>(opaque); unsigned i; - if(!driver_name) { + if(driver_name.empty()) { priv.info=audio_out_drivers[0]; priv.driver=audio_out_drivers[0]->query_interface(subdevice?subdevice:""); } else for (i=0; audio_out_drivers[i] != &audio_out_null; i++) { const ao_info_t *info = audio_out_drivers[i]; - if(strcmp(info->short_name,driver_name) == 0){ + if(info->short_name==driver_name){ priv.info = audio_out_drivers[i]; priv.driver = audio_out_drivers[i]->query_interface(subdevice?subdevice:""); break; } } - if(priv.driver->open(flags)==MPXP_Ok) return MPXP_Ok; + if(priv.driver) { if(priv.driver->open(flags)==MPXP_Ok) return MPXP_Ok; } return MPXP_False; } Modified: mplayerxp/libao3/audio_out.h =================================================================== --- mplayerxp/libao3/audio_out.h 2012-12-26 17:16:39 UTC (rev 603) +++ mplayerxp/libao3/audio_out.h 2012-12-27 08:38:19 UTC (rev 604) @@ -34,7 +34,7 @@ virtual ~Audio_Output(); static void print_help(); - virtual MPXP_Rc _register(const char *driver_name,unsigned flags) const; + virtual MPXP_Rc _register(const std::string& driver_name,unsigned flags) const; virtual const ao_info_t* get_info() const; virtual MPXP_Rc configure(unsigned rate,unsigned channels,unsigned format) const; virtual unsigned buffersize() const; Modified: mplayerxp/libmpconf/cfgparser.cpp =================================================================== --- mplayerxp/libmpconf/cfgparser.cpp 2012-12-26 17:16:39 UTC (rev 603) +++ mplayerxp/libmpconf/cfgparser.cpp 2012-12-27 08:38:19 UTC (rev 604) @@ -695,40 +695,39 @@ } namespace mpxp { -MPXP_Rc mpxp_parse_command_line(m_config_t& config, int argc, char **argv, char **envp) +MPXP_Rc mpxp_parse_command_line(m_config_t& config, const std::vector<std::string>& argv) { - int i; + size_t i,siz=argv.size(); int tmp; - char *opt; + std::string opt; int no_more_opts = 0; - UNUSED(envp); if (init_conf(config, COMMAND_LINE) == -1) return MPXP_False; if(config.last_parent == NULL) config.last_parent = config.pt; /* in order to work recursion detection properly in parse_config_file */ ++config.recursion_depth; - for (i = 1; i < argc; i++) { + for (i = 1; i < siz; i++) { //next: opt = argv[i]; - if(strcmp(opt,"--help")==0) { + if(opt=="--help") { show_help(); exit(0); } - if(strcmp(opt,"--long-help")==0) { + if(opt=="--long-help") { show_long_help(); exit(0); } /* check for -- (no more options id.) except --help! */ - if ((*opt == '-') && (*(opt+1) == '-')) { + if (opt[0] == '-' && opt[1] == '-') { no_more_opts = 1; - if (i+1 >= argc) { + if (i+1 >= siz) { mpxp_err<<"You added '--' but no filenames presented!"<<std::endl; goto err_out; } continue; } - if((opt[0] == '{') && (opt[1] == '\0')) { + if(opt[0] == '{' && opt[1] == '\0') { play_tree_t* entry = play_tree_new(); UNSET_GLOBAL(config); if(config.last_entry == NULL) { @@ -741,7 +740,7 @@ continue; } - if((opt[0] == '}') && (opt[1] == '\0')) { + if(opt[0] == '}' && opt[1] == '\0') { if( ! config.last_parent || ! config.last_parent->parent) { mpxp_err<<"too much }-"<<std::endl; goto err_out; @@ -751,30 +750,25 @@ continue; } - if ((no_more_opts == 0) && (*opt == '-') && (*(opt+1) != 0)) /* option */ { + if (no_more_opts == 0 && opt[0] == '-' && opt.length()>1) /* option */ { /* remove leading '-' */ - char *assign,*item,*parm; - unsigned sz; - opt++; + size_t pos; + std::string item,parm; + pos=1; mpxp_dbg2<<"this_option: "<<opt<<std::endl; parm = argv[i+1]; - item=opt; - assign = strchr(opt,'='); - if(assign) { - sz=assign-opt; - item = new char [sz+1]; - memcpy(item,opt,sz); - item[sz]='\0'; - parm = mp_strdup(assign+1); + item=opt.substr(pos); + pos = item.find('='); + if(pos!=std::string::npos) { + parm=item.substr(pos+1); + item=item.substr(0,pos); } - tmp = m_config_set_option(config, std::string(item?item:""), std::string(parm?parm:"")); - if(!tmp && assign) mpxp_err<<"Option '"<<item<<"' doesn't require arguments"<<std::endl; - if(assign) { - delete item; - delete parm; + tmp = m_config_set_option(config, item, parm); + if(!tmp && pos!=std::string::npos) { + mpxp_err<<"Option '"<<item<<"' doesn't require arguments"<<std::endl; + goto err_out; } - if(!tmp && assign) goto err_out; switch (tmp) { case ERR_NOT_AN_OPTION: @@ -790,15 +784,14 @@ <<"' while parsing option: '"<<opt<<"'"<<std::endl; goto err_out; default: - i += tmp; - if(assign) i--; + if(pos==std::string::npos) i++; break; } } else /* filename */ { play_tree_t* entry = play_tree_new(); mpxp_dbg2<<"Adding file "<<argv[i]<<std::endl; play_tree_add_file(entry,argv[i]); - if(strcasecmp(argv[i],"-") == 0) m_config_set_option(config,"use-stdin",NULL); + if(argv[i]=="-") m_config_set_option(config,"use-stdin",NULL); /* opt is not an option -> treat it as a filename */ UNSET_GLOBAL(config); // We start entry specific options if(config.last_entry == NULL) play_tree_set_child(config.last_parent,entry); Modified: mplayerxp/libmpconf/cfgparser.h =================================================================== --- mplayerxp/libmpconf/cfgparser.h 2012-12-26 17:16:39 UTC (rev 603) +++ mplayerxp/libmpconf/cfgparser.h 2012-12-27 08:38:19 UTC (rev 604) @@ -4,6 +4,8 @@ #ifndef __CFG_PARSER_H #define __CFG_PARSER_H 1 #include "xmpcore/xmp_enums.h" +#include <vector> +#include <string> namespace mpxp { struct libinput_t; @@ -90,7 +92,7 @@ * 1 otherwise */ namespace mpxp { - MPXP_Rc mpxp_parse_command_line(m_config_t& config, int argc, char **argv, char **envp); + MPXP_Rc mpxp_parse_command_line(m_config_t& config, const std::vector<std::string>& argv); } m_config_t& m_config_new(play_tree_t* pt,libinput_t&libinput); Modified: mplayerxp/libplaytree/playtree.cpp =================================================================== --- mplayerxp/libplaytree/playtree.cpp 2012-12-26 17:16:39 UTC (rev 603) +++ mplayerxp/libplaytree/playtree.cpp 2012-12-27 08:38:19 UTC (rev 604) @@ -226,7 +226,7 @@ } if(ni > 0) { - pt->params[n].value = val; + pt->params[ni].value = val; return; } Modified: mplayerxp/mplayerxp.cpp =================================================================== --- mplayerxp/mplayerxp.cpp 2012-12-26 17:16:39 UTC (rev 603) +++ mplayerxp/mplayerxp.cpp 2012-12-27 08:38:19 UTC (rev 604) @@ -395,7 +395,7 @@ if(mpxp_context().mconfig) m_config_free(mpxp_context().mconfig); mpxp_print_uninit(); mpxp_uninit_structs(); - if(!why.empty()) exit(0); + if(!why.empty()) ::exit(0); return; /* Still try coredump!!!*/ } @@ -1598,16 +1598,17 @@ return eof; } -static void mpxp_config_malloc(int argc,char *argv[]) +static void mpxp_config_malloc(const std::vector<std::string>& argv) { - int i; + size_t i,sz=argv.size(); mp_conf.malloc_debug=0; mp_malloc_e flg=MPA_FLG_RANDOMIZER; - for(i=0;i<argc;i++) { - if(strncmp(argv[i],"-core.malloc-debug",18)==0) { - char *p; - if((p=strchr(argv[i],'='))!=NULL) { - mp_conf.malloc_debug=atoi(p+1); + for(i=0;i<sz;i++) { + std::string s=argv[i]; + if(s.substr(0,18)=="-core.malloc-debug") { + size_t pos; + if((pos=s.find('='))!=std::string::npos) { + mp_conf.malloc_debug=::atoi(s.substr(pos+1).c_str()); } switch(mp_conf.malloc_debug) { default: @@ -1626,7 +1627,7 @@ /******************************************\ * MAIN MPLAYERXP FUNCTION !!! * \******************************************/ -int MPlayerXP(int argc,char* argv[], char *envp[]){ +int MPlayerXP(const std::vector<std::string>& argv){ mpxp_init_antiviral_protection(1); // mpxp_test_backtrace(); int i; @@ -1643,7 +1644,7 @@ int forced_subs_only=0; seek_args_t seek_args = { 0, DEMUX_SEEK_CUR|DEMUX_SEEK_SECONDS }; - mpxp_config_malloc(argc,argv); + mpxp_config_malloc(argv); // Yes, it really must be placed in stack or in very secret place PointerProtector<MPXPSecureKeys> ptr_protector; @@ -1674,7 +1675,7 @@ mp_register_options(m_config); parse_cfgfiles(m_config); - if(mpxp_parse_command_line(m_config, argc, argv, envp)!=MPXP_Ok) + if(mpxp_parse_command_line(m_config, argv)!=MPXP_Ok) exit_player("Error parse command line"); // error parsing cmdline if(!mp_conf.xp) { @@ -1718,8 +1719,9 @@ // Many users forget to include command line in bugreports... if(mp_conf.verbose){ + size_t sz=argv.size(); mpxp_info<<"CommandLine:"; - for(i=1;i<argc;i++) mpxp_info<<" '"<<argv[i]<<"'"; + for(i=1;i<sz;i++) mpxp_info<<" '"<<argv[i]<<"'"; mpxp_info<<std::endl; } @@ -2128,10 +2130,19 @@ } } // namespace mpxp -int main(int argc,char* argv[], char *envp[]) +int main(int argc,char* args[], char *envp[]) { + UNUSED(envp); try { - return MPlayerXP(argc,argv,envp); + std::vector<std::string> argv; + std::string str; + for(int i=0;i<argc;i++) { + str=args[i]; + argv.push_back(str); + } + return MPlayerXP(argv); + } catch(const std::string& what) { + std::cout<<"Exception '"<<what<<"'caught in module: MPlayerXP"<<std::endl; } catch(...) { std::cout<<"Exception caught in module: MPlayerXP"<<std::endl; } Modified: mplayerxp/osdep/mp_malloc.cpp =================================================================== --- mplayerxp/osdep/mp_malloc.cpp 2012-12-26 17:16:39 UTC (rev 603) +++ mplayerxp/osdep/mp_malloc.cpp 2012-12-27 08:38:19 UTC (rev 604) @@ -19,20 +19,20 @@ enum { Max_BackTraces=13 }; -typedef struct mp_slot_s { +struct mp_slot_t { any_t* page_ptr; size_t size; size_t ncalls; any_t* calls[Max_BackTraces]; -}mp_slot_t; +}; -typedef struct mp_slot_container_s { +struct mp_slot_container_t { mp_slot_t* slots; size_t nslots; size_t size; -}mp_slot_container_t; +}; -typedef struct priv_s { +struct priv_t { const char* argv0; unsigned rnd_limit; unsigned every_nth_call; @@ -43,7 +43,7 @@ mp_slot_container_t mallocs;/* not freed mallocs */ mp_slot_container_t reallocs; /* suspect reallocs */ mp_slot_container_t frees; /* suspect free */ -}priv_t; +}; static priv_t* priv=NULL; static any_t* prot_page_align(any_t *ptr) { return (any_t*)(((unsigned long)ptr)&(~(__VM_PAGE_SIZE__-1))); } @@ -403,12 +403,12 @@ } } /* ================== HEAD FUNCTIONS ======================= */ -void mp_init_malloc(const char *argv0,unsigned rnd_limit,unsigned every_nth_call,enum mp_malloc_e flags) +void mp_init_malloc(const std::string& argv0,unsigned rnd_limit,unsigned every_nth_call,enum mp_malloc_e flags) { ::srand(::time(0)); if(!priv) priv=(priv_t*)::malloc(sizeof(priv_t)); ::memset(priv,0,sizeof(priv_t)); - priv->argv0=argv0; + priv->argv0=::strdup(argv0.c_str()); priv->rnd_limit=rnd_limit; priv->every_nth_call=every_nth_call; priv->flags=flags; @@ -450,6 +450,7 @@ } if(done) mpxp_hint<<std::endl<<"For source lines you may also print in (gdb): list *0xADDRESS"<<std::endl; uninit_bt_cache(cache); + if(priv->argv0) ::free((void*)priv->argv0); ::free(priv); priv=NULL; } @@ -457,7 +458,7 @@ any_t* mp_malloc(size_t __size) { any_t* rb,*rnd_buff=NULL; - if(!priv) mp_init_malloc(NULL,1000,10,MPA_FLG_RANDOMIZER); + if(!priv) mp_init_malloc("",1000,10,MPA_FLG_RANDOMIZER); if(priv->every_nth_call && priv->rnd_limit && !priv->flags) { if(priv->total_calls%priv->every_nth_call==0) { rnd_buff=::malloc(::rand()%priv->rnd_limit); @@ -475,7 +476,7 @@ any_t* __FASTCALL__ mp_memalign (size_t boundary, size_t __size) { any_t* rb; - if(!priv) mp_init_malloc(NULL,1000,10,MPA_FLG_RANDOMIZER); + if(!priv) mp_init_malloc("",1000,10,MPA_FLG_RANDOMIZER); if(priv->flags&(MPA_FLG_BOUNDS_CHECK|MPA_FLG_BEFORE_CHECK)) rb=prot_memalign(boundary,__size); else if(priv->flags&MPA_FLG_BACKTRACE) rb=bt_memalign(boundary,__size); else rb=memalign(boundary,__size); @@ -492,15 +493,18 @@ void mp_free(any_t*__ptr) { - if(!priv) mp_init_malloc(NULL,1000,10,MPA_FLG_RANDOMIZER); - if(__ptr) { - if(priv->flags&(MPA_FLG_BOUNDS_CHECK|MPA_FLG_BEFORE_CHECK)) - prot_free(__ptr); - else if(priv->flags&MPA_FLG_BACKTRACE) - bt_free(__ptr); - else - ::free(__ptr); - } + // we really may have some number of pointers malloced before mp_init_malloc() + // example: global constructors with using of overloaded operator new() + if(priv) { + if(__ptr) { + if(priv->flags&(MPA_FLG_BOUNDS_CHECK|MPA_FLG_BEFORE_CHECK)) + prot_free(__ptr); + else if(priv->flags&MPA_FLG_BACKTRACE) + bt_free(__ptr); + else + ::free(__ptr); + } + } else ::free(__ptr); } /* ================ APPENDIX ==================== */ Modified: mplayerxp/osdep/mplib.h =================================================================== --- mplayerxp/osdep/mplib.h 2012-12-26 17:16:39 UTC (rev 603) +++ mplayerxp/osdep/mplib.h 2012-12-27 08:38:19 UTC (rev 604) @@ -46,7 +46,7 @@ MPA_FLG_BEFORE_CHECK = 0x00000002, MPA_FLG_BACKTRACE = 0x00000004 }; - void __FASTCALL__ mp_init_malloc(const char *argv0,unsigned rnd_limit,unsigned every_nth_call,enum mp_malloc_e flags); + void __FASTCALL__ mp_init_malloc(const std::string& argv0,unsigned rnd_limit,unsigned every_nth_call,enum mp_malloc_e flags); void __FASTCALL__ mp_uninit_malloc(int verbose); any_t* __FASTCALL__ mp_malloc(size_t __size); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |