zoukankan      html  css  js  c++  java
  • Never use absolute path when you create tar

    In unix, especially Solaris, the tar file is dangerous if you create a tar file with absolute path.

    For example:

    We have an very important config files here, if you change the content may cause some problem

    1 bash-2.03$ ls -ltr /home/limingwei/config.txt
    2 -rw-r--r--   1 limingwei mqm            3 Apr  4 15:46 /home/limingwei/config.txt
    3 bash-2.03$ cat /home/limingwei/config.txt
    4 hi

    Someday, you need to tar the file for some reason, and you tar the file with absolute path.

    1 bash-2.03$ tar -cvf config.tar /home/limingwei/config.txt
    2 a /home/limingwei/config.txt 1K
    3 bash-2.03$ ls config.tar
    4 config.tar

    Then a few days later, the content of the config is changed due to some reason. Now the correct content is not "hi". It is "hello world"

    bash-2.03$ cat /home/limingwei/config.txt
    hello world

    So in this situation, if someone who is not clear about this tar file. He may untar this file for some reason.

    bash-2.03$ ls -l config.tar
    -rw-r--r--   1 limingwei mqm         2048 Apr  4 15:47 config.tar
    bash-2.03$ tar -xvf config.tar
    tar: blocksize = 4
    x /home/limingwei/config.txt, 3 bytes, 1 tape blocks
    bash-2.03$ cat /home/limingwei/config.txt
    hi
    bash-2.03$

    Now you can see. The someone`s untar option have overwrite our correct config file.

    So the point is never use absolute path when you create tar. And more importantly, you need to check the tar file before you untar it. Check it with -t option.

    bash-2.03$ tar tvf config.tar
    tar: blocksize = 4
    -rw-r--r-- 100009/105      3 Apr  4 15:46 2013 /home/limingwei/config.txt

    If the someone did this before untar the file, config file will not be overwrite.

  • 相关阅读:
    python及pandas,numpy等知识点技巧点学习笔记
    人工智能,大数据,云计算大杂烩
    python开发环境
    机器学习vs深度学习及其知识点
    深入理解SVG坐标体系和transformations- viewport, viewBox,preserveAspectRatio
    军队改革看管理
    d3js path generator vs layouts
    d3js layout 深入理解
    RedisTemplate 事务处理方法 watch multi exec 的使用
    阻止联网
  • 原文地址:https://www.cnblogs.com/kramer/p/2995537.html
Copyright © 2011-2022 走看看