]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
config,state: check magic in all callbacks.
authorNick Mathewson <nickm@torproject.org>
Fri, 25 Oct 2019 12:09:05 +0000 (08:09 -0400)
committerNick Mathewson <nickm@torproject.org>
Fri, 25 Oct 2019 12:09:05 +0000 (08:09 -0400)
src/app/config/config.c
src/app/config/statefile.c

index b6927b8b771457c0a0914e4102777b873d3a1613..f2db0e5250c379aa00a89186ba684c0b93ac6e6c 100644 (file)
@@ -921,6 +921,10 @@ get_options_mgr(void)
   return options_mgr;
 }
 
+#define CHECK_OPTIONS_MAGIC(opt) STMT_BEGIN                      \
+    config_check_toplevel_magic(get_options_mgr(), (opt));       \
+  STMT_END
+
 /** Return the contents of our frontpage string, or NULL if not configured. */
 MOCK_IMPL(const char*,
 get_dirportfrontpage, (void))
@@ -1027,6 +1031,7 @@ static void
 options_clear_cb(const config_mgr_t *mgr, void *opts)
 {
   (void)mgr;
+  CHECK_OPTIONS_MAGIC(opts);
   or_options_t *options = opts;
 
   routerset_free(options->ExcludeExitNodesUnion_);
@@ -3467,6 +3472,9 @@ options_validate_single_onion(or_options_t *options, char **msg)
 static int
 options_validate_cb(const void *old_options_, void *options_, char **msg)
 {
+  if (old_options_)
+    CHECK_OPTIONS_MAGIC(old_options_);
+  CHECK_OPTIONS_MAGIC(options_);
   const or_options_t *old_options = old_options_;
   or_options_t *options = options_;
 
@@ -4821,6 +4829,9 @@ options_check_transition_cb(const void *old_,
                             const void *new_val_,
                             char **msg)
 {
+  CHECK_OPTIONS_MAGIC(old_);
+  CHECK_OPTIONS_MAGIC(new_val_);
+
   const or_options_t *old = old_;
   const or_options_t *new_val = new_val_;
 
index d3a0ec1790415d46e5c8dfa460f09dad0707bb63..834ad93ed7cd67029175f8a293b5f3943144b00d 100644 (file)
@@ -184,6 +184,10 @@ get_state_mgr(void)
   return state_mgr;
 }
 
+#define CHECK_STATE_MAGIC(s) STMT_BEGIN                        \
+    config_check_toplevel_magic(get_state_mgr(), (s));         \
+  STMT_END
+
 /** Persistent serialized state. */
 static or_state_t *global_state = NULL;
 
@@ -286,6 +290,7 @@ or_state_validate_cb(const void *old_state, void *state_, char **msg)
   /* There is not a meaningful concept of a state-to-state transition,
    * since we do not reload the state after we start. */
   (void) old_state;
+  CHECK_STATE_MAGIC(state_);
 
   or_state_t *state = state_;