Ticket #5825: userClientSentBadPathV2.diff

File userClientSentBadPathV2.diff, 7.5 KB (added by cfpp2p, 8 years ago)
  • J:/T1/5802-transmission-remote_--w--BUG-101514/trunk-284+/reset-to-defaults-102214/torrent.c

    old new  
    847847  return disappeared;
    848848}
    849849
     850static bool
     851path_is_bad (const char * path)
     852{
     853    if ((path == NULL) || (*path == '\0')) return true;
     854       
     855    //do NOT allow backward traverse
     856    if (!strncmp(path, "../", 3)) return true;
     857    if ((strstr( path, "/../" ) != NULL )) return true;
     858
     859    // check for path end that allows backward traverse
     860    if (strlen (path) > 2 ) {
     861        const char * endOfString = strrchr (path, '\0');
     862        --endOfString;
     863        --endOfString;
     864        if ((!strcmp (--endOfString, "/.." ))) return true;
     865        return false;
     866    }
     867
     868    if ((strlen( path) == 2)
     869        && (!strcmp (path, ".."))) return true;
     870
     871    return false;
     872}
     873
    850874static void
    851875torrentInit (tr_torrent * tor, const tr_ctor * ctor)
    852876{
     
    903927  tr_ctorInitTorrentPriorities (ctor, tor);
    904928  tr_ctorInitTorrentWanted (ctor, tor);
    905929
    906   refreshCurrentDir (tor);
     930  tor->currentDir = NULL;
     931  if ((tor->downloadDir != NULL) || (tor->incompleteDir != NULL))
     932    refreshCurrentDir (tor);
    907933
     934    if (path_is_bad (tor->currentDir))
     935    {
     936        if ((path_is_bad (tor->incompleteDir)) && (tor->incompleteDir != NULL))
     937        {
     938            tr_torrentSetLocalError (tor, "Illegal incomplete directory: \"%s\ Please restart torrent. IGNORING incomplete directory", tor->incompleteDir);
     939            tor->incompleteDir = NULL;  // try the download directory
     940            refreshCurrentDir (tor);
     941
     942            if (path_is_bad (tor->currentDir));
     943              {
     944                tr_torrentSetLocalError (tor, "IGNORED incomplete directory, resulting download directory: \"%s\ Illegal. Please restart torrent. Changed download directory to default", tor->currentDir);
     945                tor->downloadDir = tr_getDefaultDownloadDir ();  // set to default downloadDir
     946                refreshCurrentDir (tor);
     947                assert (!path_is_bad (tor->currentDir));
     948              }
     949
     950            tor->isRunning = false;
     951        }
     952        else
     953        {
     954// should always be redundant with tor downloadDir
     955            tr_torrentSetLocalError (tor, "Download directory: \"%s\ Illegal. Please restart torrent. Changed download directory to default", tor->currentDir);
     956            tor->downloadDir = tr_getDefaultDownloadDir ();  // set to default downloadDir
     957            refreshCurrentDir (tor);
     958            assert (!path_is_bad (tor->currentDir));
     959            tor->isRunning = false;
     960        }
     961    }
     962
     963    if (path_is_bad (tor->downloadDir))
     964    {
     965        tr_torrentSetLocalError (tor, "Illegal download directory: \"%s\ Try using torrent set location. Changed to default download directory. Please restart torrent.", tor->downloadDir);
     966
     967        // set to default downloadDir
     968        tor->downloadDir = tr_getDefaultDownloadDir ();
     969        refreshCurrentDir (tor);
     970        assert (!path_is_bad (tor->currentDir));
     971
     972        tor->isRunning = false;
     973    }
     974
    908975  doStart = tor->isRunning;
    909976  tor->isRunning = false;
    910977
     
    16881755static void
    16891756torrentStart (tr_torrent * tor, bool bypass_queue)
    16901757{
     1758    if (path_is_bad (tor->downloadDir))
     1759    {
     1760        tr_torrentSetLocalError (tor, "Illegal download directory: \"%s\ Try using torrent set location. Changed to default download directory. Please restart torrent.", tor->downloadDir);
     1761
     1762        // set to default downloadDir
     1763        tor->downloadDir = tr_getDefaultDownloadDir ();
     1764        refreshCurrentDir (tor);
     1765        assert (!path_is_bad (tor->currentDir));
     1766
     1767        return;
     1768    }
     1769
     1770    if (path_is_bad (tor->currentDir))
     1771    {
     1772        if ((path_is_bad (tor->incompleteDir)) && (tor->incompleteDir != NULL))
     1773        {
     1774            tr_torrentSetLocalError (tor, "Illegal incomplete directory: \"%s\ Please restart torrent. IGNORING incomplete directory", tor->incompleteDir);
     1775            tor->incompleteDir = NULL;  // try the download directory
     1776            refreshCurrentDir (tor);
     1777
     1778            if (path_is_bad (tor->currentDir));
     1779              {
     1780                tr_torrentSetLocalError (tor, "IGNORED incomplete directory, resulting download directory: \"%s\ Illegal. Please restart torrent. Changed download directory to default", tor->currentDir);
     1781                tor->downloadDir = tr_getDefaultDownloadDir ();  // set to default downloadDir
     1782                refreshCurrentDir (tor);
     1783                assert (!path_is_bad (tor->currentDir));
     1784              }
     1785
     1786            return;
     1787        }
     1788        else
     1789        {
     1790// this should never happen
     1791            tr_torrentSetLocalError (tor, "Download directory: \"%s\ Illegal. Please restart torrent. Changed download directory to default", tor->currentDir);
     1792            tor->downloadDir = tr_getDefaultDownloadDir ();  // set to default downloadDir
     1793            refreshCurrentDir (tor);
     1794            assert (!path_is_bad (tor->currentDir));
     1795            return;
     1796        }
     1797    }
     1798
    16911799  switch (tr_torrentGetActivity (tor))
    16921800    {
    16931801      case TR_STATUS_SEED:
     
    18251933tr_torrentVerify (tr_torrent           * tor,
    18261934                  tr_verify_done_func    callback_func,
    18271935                  void                 * callback_data)
    1828 {
    1829   struct verify_data * data;
     1936  if ((tr_isTorrent (tor)) && (!path_is_bad (tor->currentDir)))
     1937    {
     1938      struct verify_data * data;
    18301939
    1831   data = tr_new (struct verify_data, 1);
    1832   data->tor = tor;
    1833   data->aborted = false;
    1834   data->callback_func = callback_func;
    1835   data->callback_data = callback_data;
    1836   tr_runInEventThread (tor->session, verifyTorrent, data);
    1837 }
     1940      data = tr_new (struct verify_data, 1);
     1941      data->tor = tor;
     1942      data->aborted = false;
     1943      data->callback_func = callback_func;
     1944      data->callback_data = callback_data;
     1945      tr_runInEventThread (tor->session, verifyTorrent, data);
     1946    }
    18381947
    18391948void
    18401949tr_torrentSave (tr_torrent * tor)
     
    28913000  if (!tr_torrentHasMetadata (tor))
    28923001    return;
    28933002
     3003    if (path_is_bad (tor->currentDir))
     3004    {
     3005        tr_logAddTorErr (tor, " bad path error deleting  \"%s\" ", tor->currentDir);
     3006        return;
     3007    }
     3008
    28943009  /***
    28953010  ****  Move the local data to a new tmpdir
    28963011  ***/
     
    31463261                       volatile double  * setme_progress,
    31473262                       volatile int     * setme_state)
    31483263{
     3264
     3265    if (path_is_bad (tor->currentDir)) tr_logAddTorErr (tor, "bad path error set location source \"%s\" ", tor->currentDir);
     3266
     3267    if ((path_is_bad (tor->currentDir)) && (!path_is_bad (location)))
     3268    {
     3269        tr_logAddTorErr (tor, "bad path set location source IGNORING \"%s\" ", tor->currentDir);
     3270        move_from_old_location = false;
     3271    }
     3272
     3273    if (path_is_bad (location))
     3274    {
     3275        tr_logAddTorErr (tor, "bad path error set location destination \"%s\" ", location);
     3276        return;
     3277    }
     3278
    31493279  struct LocationData * data;
    31503280
    31513281  assert (tr_isTorrent (tor));
     
    32953425  file = &tor->info.files[fileNum];
    32963426
    32973427  /* look in the download dir... */
    3298   if (b == NULL)
     3428  if ((b == NULL) && (tor->downloadDir != NULL))
    32993429    {
    33003430      char * filename = tr_buildPath (tor->downloadDir, file->name, NULL);
    33013431      if (tr_sys_path_get_info (filename, 0, &file_info, NULL))
     
    33343464    }
    33353465
    33363466  /* look for a .part file in the download dir... */
    3337   if (b == NULL)
     3467  if ((b == NULL) && (tor->downloadDir != NULL))
    33383468    {
    33393469      char * filename = tr_buildPath (tor->downloadDir, part, NULL);
    33403470      if (tr_sys_path_get_info (filename, 0, &file_info, NULL))