Develop and Download Open Source Software

Browse Subversion Repository

Diff of /hamigaki/trunk/libs/archivers/example/wuntar.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  // untar.cpp: a simple tar extracting program (Unicode version)  // untar.cpp: a simple tar extracting 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  int main(int argc, char* argv[])  int main(int argc, char* argv[])
58  {  {
59      try      try
# Line 58  int main(int argc, char* argv[]) Line 73  int main(int argc, char* argv[])
73              const ar::tar::wheader& head = tar.header();              const ar::tar::wheader& head = tar.header();
74    
75              std::wcout << head.path << std::endl;              std::wcout << head.path << std::endl;
76                if (!is_valid_path(head.path))
77                {
78                    std::cerr << "Warning: invalid path" << '\n';
79                    continue;
80                }
81    
82              if (head.type_flag == ar::tar::type_flag::link)              if (head.type_flag == ar::tar::type_flag::link)
83              {              {

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