mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-20 18:22:09 +01:00
Merge remote-tracking branch 'origin/maint-0.2.3'
This commit is contained in:
commit
05dd0a9cd9
3
changes/clang_strcspn
Normal file
3
changes/clang_strcspn
Normal file
@ -0,0 +1,3 @@
|
||||
o Minor bugfixes:
|
||||
- Avoid a warning caused by using strcspn from glibc with clang 3.0.
|
||||
Bugfix on 0.2.3.13-alpha.
|
2
changes/envvar_test
Normal file
2
changes/envvar_test
Normal file
@ -0,0 +1,2 @@
|
||||
o New unit tests:
|
||||
- Add a unit test for the environment_variable_names_equal function.
|
@ -3357,7 +3357,7 @@ format_helper_exit_status(unsigned char child_state, int saved_errno,
|
||||
*cur++ = '\n';
|
||||
*cur++ = '\0';
|
||||
|
||||
res = cur - hex_errno - 1;
|
||||
res = (int)(cur - hex_errno - 1);
|
||||
|
||||
goto done;
|
||||
|
||||
@ -3897,13 +3897,26 @@ tor_get_exit_code(const process_handle_t *process_handle,
|
||||
return PROCESS_EXIT_EXITED;
|
||||
}
|
||||
|
||||
/** Helper: return the number of characters in <b>s</b> preceding the first
|
||||
* occurence of <b>ch</b>. If <b>ch</b> does not occur in <b>s</b>, return
|
||||
* the length of <b>s</b>. Should be equivalent to strspn(s, "ch"). */
|
||||
static INLINE size_t
|
||||
str_num_before(const char *s, char ch)
|
||||
{
|
||||
const char *cp = strchr(s, ch);
|
||||
if (cp)
|
||||
return cp - s;
|
||||
else
|
||||
return strlen(s);
|
||||
}
|
||||
|
||||
/** Return non-zero iff getenv would consider <b>s1</b> and <b>s2</b>
|
||||
* to have the same name as strings in a process's environment. */
|
||||
int
|
||||
environment_variable_names_equal(const char *s1, const char *s2)
|
||||
{
|
||||
size_t s1_name_len = strcspn(s1, "=");
|
||||
size_t s2_name_len = strcspn(s2, "=");
|
||||
size_t s1_name_len = str_num_before(s1, '=');
|
||||
size_t s2_name_len = str_num_before(s2, '=');
|
||||
|
||||
return (s1_name_len == s2_name_len &&
|
||||
tor_memeq(s1, s2, s1_name_len));
|
||||
@ -3978,7 +3991,7 @@ process_environment_make(struct smartlist_t *env_vars)
|
||||
for (i = 0; i < n_env_vars; ++i) {
|
||||
const char *s = smartlist_get(env_vars_sorted, i);
|
||||
size_t slen = strlen(s);
|
||||
size_t s_name_len = strcspn(s, "=");
|
||||
size_t s_name_len = str_num_before(s, '=');
|
||||
|
||||
if (s_name_len == slen) {
|
||||
log_warn(LD_GENERAL,
|
||||
|
@ -2869,6 +2869,39 @@ test_util_sl_new_from_text_lines(void *ptr)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_util_envnames(void *ptr)
|
||||
{
|
||||
(void) ptr;
|
||||
|
||||
tt_assert(environment_variable_names_equal("abc", "abc"));
|
||||
tt_assert(environment_variable_names_equal("abc", "abc="));
|
||||
tt_assert(environment_variable_names_equal("abc", "abc=def"));
|
||||
tt_assert(environment_variable_names_equal("abc=def", "abc"));
|
||||
tt_assert(environment_variable_names_equal("abc=def", "abc=ghi"));
|
||||
|
||||
tt_assert(environment_variable_names_equal("abc", "abc"));
|
||||
tt_assert(environment_variable_names_equal("abc", "abc="));
|
||||
tt_assert(environment_variable_names_equal("abc", "abc=def"));
|
||||
tt_assert(environment_variable_names_equal("abc=def", "abc"));
|
||||
tt_assert(environment_variable_names_equal("abc=def", "abc=ghi"));
|
||||
|
||||
tt_assert(!environment_variable_names_equal("abc", "abcd"));
|
||||
tt_assert(!environment_variable_names_equal("abc=", "abcd"));
|
||||
tt_assert(!environment_variable_names_equal("abc=", "abcd"));
|
||||
tt_assert(!environment_variable_names_equal("abc=", "def"));
|
||||
tt_assert(!environment_variable_names_equal("abc=", "def="));
|
||||
tt_assert(!environment_variable_names_equal("abc=x", "def=x"));
|
||||
|
||||
tt_assert(!environment_variable_names_equal("", "a=def"));
|
||||
/* A bit surprising. */
|
||||
tt_assert(environment_variable_names_equal("", "=def"));
|
||||
tt_assert(environment_variable_names_equal("=y", "=x"));
|
||||
|
||||
done:
|
||||
;
|
||||
}
|
||||
|
||||
/** Test process_environment_make */
|
||||
static void
|
||||
test_util_make_environment(void *ptr)
|
||||
@ -3081,6 +3114,7 @@ struct testcase_t util_tests[] = {
|
||||
UTIL_TEST(n_bits_set, 0),
|
||||
UTIL_TEST(eat_whitespace, 0),
|
||||
UTIL_TEST(sl_new_from_text_lines, 0),
|
||||
UTIL_TEST(envnames, 0),
|
||||
UTIL_TEST(make_environment, 0),
|
||||
UTIL_TEST(set_env_var_in_sl, 0),
|
||||
END_OF_TESTCASES
|
||||
|
Loading…
Reference in New Issue
Block a user