Develop and Download Open Source Software

Browse Subversion Repository

Diff of /hamigaki/trunk/libs/archivers/example/wunzip.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1781 by hamigaki, Sun Sep 7 03:09:56 2008 UTC revision 1782 by hamigaki, Sun Jun 10 06:01:53 2018 UTC
# Line 1  Line 1 
1  // wunzip.cpp: a simple ZIP decompressing program (Unicode version)  // wunzip.cpp: a simple ZIP decompressing program (Unicode version)
2    
3  // Copyright Takeshi Mouri 2008.  // Copyright Takeshi Mouri 2008-2018.
4  // Distributed under the Boost Software License, Version 1.0.  // Distributed under the Boost Software License, Version 1.0.
5  // (See accompanying file LICENSE_1_0.txt or copy at  // (See accompanying file LICENSE_1_0.txt or copy at
6  // http://www.boost.org/LICENSE_1_0.txt)  // http://www.boost.org/LICENSE_1_0.txt)
# Line 39  inline bool has_parent_path(const Path& Line 39  inline bool has_parent_path(const Path&
39  #endif  #endif
40  }  }
41    
42    template<class Path>
43    bool is_valid_path(const Path& ph)
44    {
45    #if !defined(HAMIGAKI_ALLOW_DIRECTORY_TRAVERSAL)
46        if (ph.has_root_name() || ph.has_root_directory())
47            return false;
48        for (typename Path::iterator it = ph.begin(); it != ph.end(); ++it)
49        {
50            if (*it == L"..")
51                return false;
52        }
53    #endif
54        return true;
55    }
56    
57  inline fs_ex::timestamp make_timestamp(std::time_t t)  inline fs_ex::timestamp make_timestamp(std::time_t t)
58  {  {
59      return fs_ex::timestamp::from_time_t(t);      return fs_ex::timestamp::from_time_t(t);
# Line 63  int main(int argc, char* argv[]) Line 78  int main(int argc, char* argv[])
78              const ar::zip::wheader& head = zip.header();              const ar::zip::wheader& head = zip.header();
79    
80              std::wcout << head.path << '\n';              std::wcout << head.path << '\n';
81                if (!is_valid_path(head.path))
82                {
83                    std::cerr << "Warning: invalid path" << '\n';
84                    continue;
85                }
86    
87              if (!head.link_path.empty())              if (!head.link_path.empty())
88              {              {

Legend:
Removed from v.1781  
changed lines
  Added in v.1782

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26