Changeset 14717


Ignore:
Timestamp:
Mar 13, 2016, 10:41:52 AM (5 years ago)
Author:
mikedld
Message:

Handle potential dirname/basename errors where needed

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/fdlimit.c

    r14548 r14717  
    166166  if (writable)
    167167    {
    168       char * dir = tr_sys_path_dirname (filename, NULL);
     168      char * dir = tr_sys_path_dirname (filename, &error);
     169      if (dir == NULL)
     170        {
     171          tr_logAddError (_("Couldn't get directory for \"%1$s\": %2$s"), filename, error->message);
     172          goto fail;
     173        }
    169174      if (!tr_sys_dir_create (dir, TR_SYS_DIR_CREATE_PARENTS, 0777, &error))
    170175        {
  • trunk/libtransmission/file-test.c

    r14658 r14717  
    670670test_path_basename_dirname (void)
    671671{
     672  const struct xname_test_data common_xname_tests[] =
     673  {
     674    { "/", "/" },
     675    { "", "." },
     676#ifdef _WIN32
     677    { "\\", "/" },
     678    /* Invalid paths */
     679    { "\\\\\\", NULL },
     680    { "123:" , NULL },
     681    /* Reserved characters */
     682    { "<", NULL },
     683    { ">", NULL },
     684    { ":", NULL },
     685    { "\"", NULL },
     686    { "|", NULL },
     687    { "?", NULL },
     688    { "*", NULL },
     689    { "a\\<", NULL },
     690    { "a\\>", NULL },
     691    { "a\\:", NULL },
     692    { "a\\\"", NULL },
     693    { "a\\|", NULL },
     694    { "a\\?", NULL },
     695    { "a\\*", NULL },
     696    { "c:\\a\\b<c\\d", NULL },
     697    { "c:\\a\\b>c\\d", NULL },
     698    { "c:\\a\\b:c\\d", NULL },
     699    { "c:\\a\\b\"c\\d", NULL },
     700    { "c:\\a\\b|c\\d", NULL },
     701    { "c:\\a\\b?c\\d", NULL },
     702    { "c:\\a\\b*c\\d", NULL }
     703#else
     704    { "////", "/" }
     705#endif
     706  };
     707
     708  if (test_path_xname (common_xname_tests, sizeof (common_xname_tests) / sizeof (*common_xname_tests), tr_sys_path_basename) != 0)
     709    return 1;
     710  if (test_path_xname (common_xname_tests, sizeof (common_xname_tests) / sizeof (*common_xname_tests), tr_sys_path_dirname) != 0)
     711    return 1;
     712
    672713  const struct xname_test_data basename_tests[] =
    673714  {
     
    677718    { "/a/b/c", "c" },
    678719    { "/a/b/c/", "c" },
    679     { "/", "/" },
    680     { "", "." },
    681720#ifdef _WIN32
    682721    { "c:\\a\\b\\c", "c" },
     
    691730    { "\\\\a", "a" },
    692731    { "\\\\1.2.3.4", "1.2.3.4" },
    693     { "\\\\", "/" },
    694732    { "\\", "/" },
    695     { "\\a", "a" },
    696     { "\\\\\\", NULL },
    697     { "123:" , NULL }
    698 #else
    699     { "////", "/" }
     733    { "\\a", "a" }
    700734#endif
    701735  };
     
    711745    { "a", "." },
    712746    { "a/", "." },
    713     { "/", "/" },
    714     { "", "." },
    715747#ifdef _WIN32
    716748    { "C:\\a/b\\c", "C:\\a/b" },
     
    731763    { "\\\\1.2.3.4", "\\\\" },
    732764    { "\\\\", "\\\\" },
    733     { "\\", "/" },
    734     { "a/b\\c", "a/b" },
    735     { "\\\\\\" , NULL },
    736     { "123:" , NULL }
    737 #else
    738     { "////", "/" }
     765    { "a/b\\c", "a/b" }
    739766#endif
    740767  };
  • trunk/libtransmission/makemeta.c

    r14355 r14717  
    4343          struct FileList * list)
    4444{
     45  if (dir == NULL || base == NULL)
     46    return NULL;
     47
    4548  tr_sys_dir_t odir;
    4649  char * buf;
     
    374377
    375378  base = tr_sys_path_basename (builder->top, NULL);
    376   tr_variantDictAddStr (dict, TR_KEY_name, base);
    377   tr_free (base);
     379  if (base != NULL)
     380    {
     381      tr_variantDictAddStr (dict, TR_KEY_name, base);
     382      tr_free (base);
     383    }
    378384
    379385  tr_variantDictAddInt (dict, TR_KEY_piece_length, builder->pieceSize);
  • trunk/libtransmission/torrent-ctor.c

    r14634 r14717  
    160160            {
    161161                char * base = tr_sys_path_basename (filename, NULL);
    162                 tr_variantDictAddStr (info, TR_KEY_name, base);
    163                 tr_free (base);
     162                if (base != NULL)
     163                  {
     164                    tr_variantDictAddStr (info, TR_KEY_name, base);
     165                    tr_free (base);
     166                  }
    164167            }
    165168        }
  • trunk/libtransmission/torrent.c

    r14644 r14717  
    30493049      tr_free (filename);
    30503050
     3051      if (dir == NULL)
     3052        continue;
     3053
    30513054      /* walk up the directory tree until we reach 'top' */
    30523055      if (!tr_sys_path_is_same (top, dir, NULL) && strcmp (top, dir) != 0)
     
    37553758      char * tmp = tr_sys_path_dirname (oldpath, NULL);
    37563759
     3760      if (tmp == NULL)
     3761        return;
     3762
    37573763      if (oldpath_len >= strlen(file->name))
    37583764        name = tr_buildPath (tmp, newname, NULL);
  • trunk/libtransmission/utils.c

    r14682 r14717  
    14791479  /* make sure the target directory exists */
    14801480  {
    1481     char * newdir = tr_sys_path_dirname (newpath, NULL);
    1482     const bool i = tr_sys_dir_create (newdir, TR_SYS_DIR_CREATE_PARENTS, 0777, error);
     1481    char * newdir = tr_sys_path_dirname (newpath, error);
     1482    const bool i = newdir != NULL && tr_sys_dir_create (newdir, TR_SYS_DIR_CREATE_PARENTS, 0777, error);
    14831483    tr_free (newdir);
    14841484    if (!i)
  • trunk/utils/create.c

    r14615 r14717  
    157157  if (outfile == NULL)
    158158    {
    159       char * base = tr_sys_path_basename (infile, NULL);
     159      tr_error * error = NULL;
     160      char * base = tr_sys_path_basename (infile, &error);
     161      if (base == NULL)
     162        {
     163          fprintf (stderr, "ERROR: Cannot deduce output path from input path: %s\n", error->message);
     164          return EXIT_FAILURE;
     165        }
     166
    160167      char * end = tr_strdup_printf ("%s.torrent", base);
    161168      char * cwd = tr_getcwd ();
Note: See TracChangeset for help on using the changeset viewer.