--- parser3/src/classes/file.C 2002/09/16 15:21:36 1.98 +++ parser3/src/classes/file.C 2002/09/18 09:44:51 1.100 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_FILE_C="$Date: 2002/09/16 15:21:36 $"; +static const char* IDENT_FILE_C="$Date: 2002/09/18 09:44:51 $"; #include "pa_config_includes.h" @@ -95,7 +95,7 @@ static void _save(Request& r, const Stri Value& vfile_name=params->as_no_junction(1, "file name must not be code"); // save - static_cast(r.self)->save(r.absolute(vfile_name.as_string()), + static_cast(r.get_self())->save(r.absolute(vfile_name.as_string()), vmode_name.as_string()==TEXT_MODE_NAME); } @@ -129,7 +129,7 @@ static void _load(Request& r, const Stri params->as_string(2, "filename must be string").cstr(String::UL_FILE_SPEC) :lfile_name.cstr(String::UL_FILE_SPEC); - static_cast(r.self)->set(true/*tainted*/, data, size, + static_cast(r.get_self())->set(true/*tainted*/, data, size, user_file_name, new(pool) VString(r.mime_type_of(user_file_name))); } @@ -145,7 +145,7 @@ static void _stat(Request& r, const Stri size, atime, mtime, ctime); - VFile& vfile=*static_cast(r.self); + VFile& vfile=*static_cast(r.get_self()); vfile.set(true/*tainted*/, 0/*no bytes*/, size); Hash& ff=vfile.fields(); ff.put(*new(pool) String(pool, "adate"), new(pool) VDate(pool, atime)); @@ -168,21 +168,21 @@ static bool is_safe_env_key(const char * #ifndef DOXYGEN struct Append_env_pair_info { Hash* hash; - const String* sstdin; + Value* vstdin; }; #endif -static void append_env_pair(const Hash::Key& key, Hash::Val *value, void *info) { +static void append_env_pair(const Hash::Key& key, Hash::Val *avalue, void *info) { Append_env_pair_info& pi=*static_cast(info); - const String& svalue=static_cast(value)->as_string(); + Value& value=*static_cast(avalue); if(key==STDIN_EXEC_PARAM_NAME) { - pi.sstdin=&svalue; + pi.vstdin=&value; } else { if(!is_safe_env_key(key.cstr())) throw Exception("parser.runtime", &key, "not safe environment variable"); - pi.hash->put(key, &svalue); + pi.hash->put(key, &value.as_string()); } } #ifndef DOXYGEN @@ -255,8 +255,17 @@ static void _exec_cgi(Request& r, const if(Hash *user_env=venv.get_hash(&method_name)) { Append_env_pair_info info={&env}; user_env->for_each(append_env_pair, &info); - if(info.sstdin) - in.append(*info.sstdin, String::UL_CLEAN, true); + if(info.vstdin) + if(info.vstdin->is_string()) + in.append(*info.vstdin->get_string(), String::UL_CLEAN, true); + else + if(VFile *vfile=static_cast(info.vstdin->as("file", false))) + in.APPEND_TAINTED((const char *)vfile->value_ptr(), vfile->value_size(), + "$.stdin[assigned]", 0); + else + throw Exception("parser.runtime", + &method_name, + STDIN_EXEC_PARAM_NAME " parameter must be string or file"); } } @@ -277,7 +286,7 @@ static void _exec_cgi(Request& r, const String& err=*new(pool) String(pool); int status=pa_exec(false/*forced_allow*/, script_name, &env, argv, in, out, err); - VFile& self=*static_cast(r.self); + VFile& self=*static_cast(r.get_self()); const String *body=&out; // ^file:exec Value *content_type=0;