Ticket #23098: 0001-Remove-usage-of-the-PATH_MAX-variable.patch

File 0001-Remove-usage-of-the-PATH_MAX-variable.patch, 11.4 KB (added by cypherpunks, 2 years ago)
  • new file changes/bug23098

    From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
    From: cypherpunks <cypherpunks@torproject.org>
    Date: Thu, 3 Aug 2017 15:06:26 +0000
    Subject: [PATCH] Remove usage of the PATH_MAX variable
    
    GNU Hurd does not define the PATH_MAX variable. Using the variable on
    this platform results in compilation errors.
    
    Closes #23098.
    ---
     changes/bug23098       |  4 +++
     src/test/test_config.c | 91 ++++++++++++++++++++++++++++----------------------
     2 files changed, 56 insertions(+), 39 deletions(-)
     create mode 100644 changes/bug23098
    
    diff --git a/changes/bug23098 b/changes/bug23098
    new file mode 100644
    index 000000000..7c8448a29
    - +  
     1  o Minor bugfixes (portability):
     2    - Stop using the PATH_MAX variable. The variable is not defined in
     3      GNU Hurd which prevents Tor from being built. Fixes bug 23098,
     4      bugfix on 0.3.1.1-alpha.
  • src/test/test_config.c

    diff --git a/src/test/test_config.c b/src/test/test_config.c
    index 40d562a6f..24cb65271 100644
    a b test_config_include_limit(void *data) 
    48164816  (void)data;
    48174817
    48184818  config_line_t *result = NULL;
     4819  char *torrc_path = NULL;
    48194820  char *dir = tor_strdup(get_fname("test_include_limit"));
    48204821  tt_ptr_op(dir, OP_NE, NULL);
    48214822
    test_config_include_limit(void *data) 
    48254826  tt_int_op(mkdir(dir, 0700), OP_EQ, 0);
    48264827#endif
    48274828
    4828   char torrc_path[PATH_MAX+1];
    4829   tor_snprintf(torrc_path, sizeof(torrc_path), "%s"PATH_SEPARATOR"torrc", dir);
     4829  tor_asprintf(&torrc_path, "%s"PATH_SEPARATOR"torrc", dir);
    48304830  char torrc_contents[1000];
    48314831  tor_snprintf(torrc_contents, sizeof(torrc_contents), "%%include %s",
    48324832               torrc_path);
    test_config_include_limit(void *data) 
    48374837
    48384838 done:
    48394839  config_free_lines(result);
     4840  tor_free(torrc_path);
    48404841  tor_free(dir);
    48414842}
    48424843
    test_config_include_does_not_exist(void *data) 
    48474848
    48484849  config_line_t *result = NULL;
    48494850  char *dir = tor_strdup(get_fname("test_include_does_not_exist"));
     4851  char *missing_path = NULL;
    48504852  tt_ptr_op(dir, OP_NE, NULL);
    48514853
    48524854#ifdef _WIN32
    test_config_include_does_not_exist(void *data) 
    48554857  tt_int_op(mkdir(dir, 0700), OP_EQ, 0);
    48564858#endif
    48574859
    4858   char missing_path[PATH_MAX+1];
    4859   tor_snprintf(missing_path, sizeof(missing_path), "%s"PATH_SEPARATOR"missing",
    4860                dir);
     4860  tor_asprintf(&missing_path, "%s"PATH_SEPARATOR"missing", dir);
    48614861  char torrc_contents[1000];
    48624862  tor_snprintf(torrc_contents, sizeof(torrc_contents), "%%include %s",
    48634863               missing_path);
    test_config_include_does_not_exist(void *data) 
    48684868 done:
    48694869  config_free_lines(result);
    48704870  tor_free(dir);
     4871  tor_free(missing_path);
    48714872}
    48724873
    48734874static void
    test_config_include_error_in_included_file(void *data) 
    48774878  config_line_t *result = NULL;
    48784879
    48794880  char *dir = tor_strdup(get_fname("test_error_in_included_file"));
     4881  char *invalid_path = NULL;
    48804882  tt_ptr_op(dir, OP_NE, NULL);
    48814883
    48824884#ifdef _WIN32
    test_config_include_error_in_included_file(void *data) 
    48854887  tt_int_op(mkdir(dir, 0700), OP_EQ, 0);
    48864888#endif
    48874889
    4888   char invalid_path[PATH_MAX+1];
    4889   tor_snprintf(invalid_path, sizeof(invalid_path), "%s"PATH_SEPARATOR"invalid",
    4890                dir);
     4890  tor_asprintf(&invalid_path, "%s"PATH_SEPARATOR"invalid", dir);
    48914891  tt_int_op(write_str_to_file(invalid_path, "unclosed \"", 0), OP_EQ, 0);
    48924892
    48934893  char torrc_contents[1000];
    test_config_include_error_in_included_file(void *data) 
    49004900 done:
    49014901  config_free_lines(result);
    49024902  tor_free(dir);
     4903  tor_free(invalid_path);
    49034904}
    49044905
    49054906static void
    test_config_include_empty_file_folder(void *data) 
    49084909  (void)data;
    49094910  config_line_t *result = NULL;
    49104911
     4912  char *folder_path = NULL;
     4913  char *file_path = NULL;
    49114914  char *dir = tor_strdup(get_fname("test_include_empty_file_folder"));
    49124915  tt_ptr_op(dir, OP_NE, NULL);
    49134916
    test_config_include_empty_file_folder(void *data) 
    49174920  tt_int_op(mkdir(dir, 0700), OP_EQ, 0);
    49184921#endif
    49194922
    4920   char folder_path[PATH_MAX+1];
    4921   tor_snprintf(folder_path, sizeof(folder_path), "%s"PATH_SEPARATOR"empty_dir",
    4922                dir);
     4923  tor_asprintf(&folder_path, "%s"PATH_SEPARATOR"empty_dir", dir);
    49234924#ifdef _WIN32
    49244925  tt_int_op(mkdir(folder_path), OP_EQ, 0);
    49254926#else
    49264927  tt_int_op(mkdir(folder_path, 0700), OP_EQ, 0);
    49274928#endif
    4928   char file_path[PATH_MAX+1];
    4929   tor_snprintf(file_path, sizeof(file_path), "%s"PATH_SEPARATOR"empty_file",
    4930                dir);
     4929  tor_asprintf(&file_path, "%s"PATH_SEPARATOR"empty_file", dir);
    49314930  tt_int_op(write_str_to_file(file_path, "", 0), OP_EQ, 0);
    49324931
    49334932  char torrc_contents[1000];
    test_config_include_empty_file_folder(void *data) 
    49444943
    49454944 done:
    49464945  config_free_lines(result);
     4946  tor_free(folder_path);
     4947  tor_free(file_path);
    49474948  tor_free(dir);
    49484949}
    49494950
    test_config_include_recursion_before_after(void *data) 
    49534954  (void)data;
    49544955
    49554956  config_line_t *result = NULL;
     4957  char *torrc_path = NULL;
    49564958  char *dir = tor_strdup(get_fname("test_include_recursion_before_after"));
    49574959  tt_ptr_op(dir, OP_NE, NULL);
    49584960
    test_config_include_recursion_before_after(void *data) 
    49624964  tt_int_op(mkdir(dir, 0700), OP_EQ, 0);
    49634965#endif
    49644966
    4965   char torrc_path[PATH_MAX+1];
    4966   tor_snprintf(torrc_path, sizeof(torrc_path), "%s"PATH_SEPARATOR"torrc", dir);
     4967  tor_asprintf(&torrc_path, "%s"PATH_SEPARATOR"torrc", dir);
    49674968
    49684969  char file_contents[1000];
    49694970  const int limit = MAX_INCLUDE_RECURSION_LEVEL;
    test_config_include_recursion_before_after(void *data) 
    49824983    }
    49834984
    49844985    if (i > 1) {
    4985       char file_path[PATH_MAX+1];
    4986       tor_snprintf(file_path, sizeof(file_path), "%s%d", torrc_path, i);
     4986      char *file_path = NULL;
     4987      tor_asprintf(&file_path, "%s%d", torrc_path, i);
    49874988      tt_int_op(write_str_to_file(file_path, file_contents, 0), OP_EQ, 0);
     4989      tor_free(file_path);
    49884990    }
    49894991  }
    49904992
    test_config_include_recursion_before_after(void *data) 
    50085010 done:
    50095011  config_free_lines(result);
    50105012  tor_free(dir);
     5013  tor_free(torrc_path);
    50115014}
    50125015
    50135016static void
    test_config_include_recursion_after_only(void *data) 
    50165019  (void)data;
    50175020
    50185021  config_line_t *result = NULL;
     5022  char *torrc_path = NULL;
    50195023  char *dir = tor_strdup(get_fname("test_include_recursion_after_only"));
    50205024  tt_ptr_op(dir, OP_NE, NULL);
    50215025
    test_config_include_recursion_after_only(void *data) 
    50255029  tt_int_op(mkdir(dir, 0700), OP_EQ, 0);
    50265030#endif
    50275031
    5028   char torrc_path[PATH_MAX+1];
    5029   tor_snprintf(torrc_path, sizeof(torrc_path), "%s"PATH_SEPARATOR"torrc", dir);
     5032  tor_asprintf(&torrc_path, "%s"PATH_SEPARATOR"torrc", dir);
    50305033
    50315034  char file_contents[1000];
    50325035  const int limit = MAX_INCLUDE_RECURSION_LEVEL;
    test_config_include_recursion_after_only(void *data) 
    50455048    }
    50465049
    50475050    if (i > 1) {
    5048       char file_path[PATH_MAX+1];
    5049       tor_snprintf(file_path, sizeof(file_path), "%s%d", torrc_path, i);
     5051      char *file_path = NULL;
     5052      tor_asprintf(&file_path, "%s%d", torrc_path, i);
    50505053      tt_int_op(write_str_to_file(file_path, file_contents, 0), OP_EQ, 0);
     5054      tor_free(file_path);
    50515055    }
    50525056  }
    50535057
    test_config_include_recursion_after_only(void *data) 
    50715075 done:
    50725076  config_free_lines(result);
    50735077  tor_free(dir);
     5078  tor_free(torrc_path);
    50745079}
    50755080
    50765081static void
    test_config_include_folder_order(void *data) 
    50795084  (void)data;
    50805085
    50815086  config_line_t *result = NULL;
     5087  char *torrcd = NULL;
     5088  char *path = NULL;
     5089  char *path2 = NULL;
    50825090  char *dir = tor_strdup(get_fname("test_include_folder_order"));
    50835091  tt_ptr_op(dir, OP_NE, NULL);
    50845092
    test_config_include_folder_order(void *data) 
    50885096  tt_int_op(mkdir(dir, 0700), OP_EQ, 0);
    50895097#endif
    50905098
    5091   char torrcd[PATH_MAX+1];
    5092   tor_snprintf(torrcd, sizeof(torrcd), "%s"PATH_SEPARATOR"%s", dir, "torrc.d");
     5099  tor_asprintf(&torrcd, "%s"PATH_SEPARATOR"%s", dir, "torrc.d");
    50935100
    50945101#ifdef _WIN32
    50955102  tt_int_op(mkdir(torrcd), OP_EQ, 0);
    test_config_include_folder_order(void *data) 
    50985105#endif
    50995106
    51005107  // test that files in subfolders are ignored
    5101   char path[PATH_MAX+1];
    5102   tor_snprintf(path, sizeof(path), "%s"PATH_SEPARATOR"%s", torrcd,
    5103                "subfolder");
     5108  tor_asprintf(&path, "%s"PATH_SEPARATOR"%s", torrcd, "subfolder");
    51045109
    51055110#ifdef _WIN32
    51065111  tt_int_op(mkdir(path), OP_EQ, 0);
    test_config_include_folder_order(void *data) 
    51085113  tt_int_op(mkdir(path, 0700), OP_EQ, 0);
    51095114#endif
    51105115
    5111   char path2[PATH_MAX+1];
    5112   tor_snprintf(path2, sizeof(path2), "%s"PATH_SEPARATOR"%s", path,
    5113                "01_ignore");
     5116  tor_asprintf(&path2, "%s"PATH_SEPARATOR"%s", path, "01_ignore");
    51145117  tt_int_op(write_str_to_file(path2, "ShouldNotSee 1\n", 0), OP_EQ, 0);
     5118  tor_free(path);
    51155119
    51165120  // test that files starting with . are ignored
    5117   tor_snprintf(path, sizeof(path), "%s"PATH_SEPARATOR"%s", torrcd, ".dot");
     5121  tor_asprintf(&path, "%s"PATH_SEPARATOR"%s", torrcd, ".dot");
    51185122  tt_int_op(write_str_to_file(path, "ShouldNotSee 2\n", 0), OP_EQ, 0);
     5123  tor_free(path);
    51195124
    51205125  // test file order
    5121   tor_snprintf(path, sizeof(path), "%s"PATH_SEPARATOR"%s", torrcd, "01_1st");
     5126  tor_asprintf(&path, "%s"PATH_SEPARATOR"%s", torrcd, "01_1st");
    51225127  tt_int_op(write_str_to_file(path, "Test 1\n", 0), OP_EQ, 0);
     5128  tor_free(path);
    51235129
    5124   tor_snprintf(path, sizeof(path), "%s"PATH_SEPARATOR"%s", torrcd, "02_2nd");
     5130  tor_asprintf(&path, "%s"PATH_SEPARATOR"%s", torrcd, "02_2nd");
    51255131  tt_int_op(write_str_to_file(path, "Test 2\n", 0), OP_EQ, 0);
     5132  tor_free(path);
    51265133
    5127   tor_snprintf(path, sizeof(path), "%s"PATH_SEPARATOR"%s", torrcd, "aa_3rd");
     5134  tor_asprintf(&path, "%s"PATH_SEPARATOR"%s", torrcd, "aa_3rd");
    51285135  tt_int_op(write_str_to_file(path, "Test 3\n", 0), OP_EQ, 0);
     5136  tor_free(path);
    51295137
    5130   tor_snprintf(path, sizeof(path), "%s"PATH_SEPARATOR"%s", torrcd, "ab_4th");
     5138  tor_asprintf(&path, "%s"PATH_SEPARATOR"%s", torrcd, "ab_4th");
    51315139  tt_int_op(write_str_to_file(path, "Test 4\n", 0), OP_EQ, 0);
     5140  tor_free(path);
    51325141
    51335142  char torrc_contents[1000];
    51345143  tor_snprintf(torrc_contents, sizeof(torrc_contents),
    test_config_include_folder_order(void *data) 
    51545163
    51555164 done:
    51565165  config_free_lines(result);
     5166  tor_free(path);
     5167  tor_free(path2);
    51575168  tor_free(dir);
    51585169}
    51595170
    test_config_include_flag_torrc_only(void *data) 
    52855296  (void)data;
    52865297
    52875298  char *errmsg = NULL;
     5299  char *path = NULL;
    52885300  char *dir = tor_strdup(get_fname("test_include_flag_torrc_only"));
    52895301  tt_ptr_op(dir, OP_NE, NULL);
    52905302
    test_config_include_flag_torrc_only(void *data) 
    52945306  tt_int_op(mkdir(dir, 0700), OP_EQ, 0);
    52955307#endif
    52965308
    5297   char path[PATH_MAX+1];
    5298   tor_snprintf(path, sizeof(path), "%s"PATH_SEPARATOR"%s", dir, "dummy");
     5309  tor_asprintf(&path, "%s"PATH_SEPARATOR"%s", dir, "dummy");
    52995310  tt_int_op(write_str_to_file(path, "\n", 0), OP_EQ, 0);
    53005311
    53015312  char conf_empty[1000];
    test_config_include_flag_torrc_only(void *data) 
    53155326
    53165327 done:
    53175328  tor_free(errmsg);
     5329  tor_free(path);
    53185330  tor_free(dir);
    53195331}
    53205332
    test_config_include_flag_defaults_only(void *data) 
    53245336  (void)data;
    53255337
    53265338  char *errmsg = NULL;
     5339  char *path = NULL;
    53275340  char *dir = tor_strdup(get_fname("test_include_flag_defaults_only"));
    53285341  tt_ptr_op(dir, OP_NE, NULL);
    53295342
    test_config_include_flag_defaults_only(void *data) 
    53335346  tt_int_op(mkdir(dir, 0700), OP_EQ, 0);
    53345347#endif
    53355348
    5336   char path[PATH_MAX+1];
    5337   tor_snprintf(path, sizeof(path), "%s"PATH_SEPARATOR"%s", dir, "dummy");
     5349  tor_asprintf(&path, "%s"PATH_SEPARATOR"%s", dir, "dummy");
    53385350  tt_int_op(write_str_to_file(path, "\n", 0), OP_EQ, 0);
    53395351
    53405352  char conf_empty[1000];
    test_config_include_flag_defaults_only(void *data) 
    53545366
    53555367 done:
    53565368  tor_free(errmsg);
     5369  tor_free(path);
    53575370  tor_free(dir);
    53585371}
    53595372