[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] Separate is-recognized-option from get-option-value, since ...
- To: or-cvs@freehaven.net
- Subject: [or-cvs] Separate is-recognized-option from get-option-value, since ...
- From: nickm@seul.org (Nick Mathewson)
- Date: Tue, 9 Nov 2004 01:40:34 -0500 (EST)
- Delivered-to: archiver@seul.org
- Delivered-to: or-cvs-outgoing@seul.org
- Delivered-to: or-cvs@seul.org
- Delivery-date: Tue, 09 Nov 2004 01:40:53 -0500
- Reply-to: or-dev@freehaven.net
- Sender: owner-or-cvs@freehaven.net
Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv13753/src/or
Modified Files:
config.c control.c or.h
Log Message:
Separate is-recognized-option from get-option-value, since NULL is ambiguous and returning "" misrepresents.
Index: config.c
===================================================================
RCS file: /home/or/cvsroot/src/or/config.c,v
retrieving revision 1.226
retrieving revision 1.227
diff -u -d -r1.226 -r1.227
--- config.c 9 Nov 2004 06:18:17 -0000 1.226
+++ config.c 9 Nov 2004 06:40:32 -0000 1.227
@@ -255,7 +255,7 @@
if (options->command != CMD_RUN_TOR)
return 0;
- if (set_max_file_descriptors(get_options()->MaxConn) < 0)
+ if (set_max_file_descriptors(options->MaxConn) < 0)
return -1;
/* Configure the log(s) */
@@ -542,6 +542,14 @@
option_reset(options, var);
}
+/** Return true iff key is a valid configuration option. */
+int
+config_option_is_recognized(const char *key)
+{
+ config_var_t *var = config_find_option(key);
+ return (var != NULL);
+}
+
/** Return a canonicalized list of the options assigned for key.
*/
struct config_line_t *
@@ -551,6 +559,7 @@
const void *value;
char buf[32];
struct config_line_t *result;
+ tor_assert(options && key);
var = config_find_option(key);
if (!var) {
@@ -583,7 +592,13 @@
switch(var->type)
{
case CONFIG_TYPE_STRING:
- result->value = tor_strdup(*(char**)value ? *(char**)value : "");
+ if (*(char**)value) {
+ result->value = tor_strdup(*(char**)value);
+ } else {
+ tor_free(result->key);
+ tor_free(result);
+ return NULL;
+ }
break;
case CONFIG_TYPE_UINT:
/* XXX This means every or_options_t uint or bool element
@@ -633,6 +648,7 @@
config_assign(or_options_t *options, struct config_line_t *list, int reset)
{
struct config_line_t *p;
+ tor_assert(options);
/* pass 1: normalize keys */
for (p = list; p; p = p->next) {
Index: control.c
===================================================================
RCS file: /home/or/cvsroot/src/or/control.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- control.c 9 Nov 2004 04:28:17 -0000 1.15
+++ control.c 9 Nov 2004 06:40:32 -0000 1.16
@@ -146,7 +146,7 @@
{
char buf[4];
tor_assert(conn);
- tor_assert(len || !body);
+ tor_assert(len || !body || !strlen(body));
tor_assert(type <= _CONTROL_CMD_MAX_RECOGNIZED);
set_uint32(buf, htons(len));
set_uint32(buf+2, htons(type));
@@ -249,11 +249,13 @@
answers = smartlist_create();
SMARTLIST_FOREACH(questions, const char *, q,
{
- struct config_line_t *answer = config_get_assigned_option(options,q);
- if (!answer) {
+ int recognized = config_option_is_recognized(q);
+ if (!recognized) {
send_control_error(conn, ERR_UNRECOGNIZED_CONFIG_KEY, body);
goto done;
} else {
+ struct config_line_t *answer = config_get_assigned_option(options,q);
+
while (answer) {
struct config_line_t *next;
size_t alen = strlen(answer->key)+strlen(answer->value)+2;
Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.467
retrieving revision 1.468
diff -u -d -r1.467 -r1.468
--- or.h 9 Nov 2004 04:28:18 -0000 1.467
+++ or.h 9 Nov 2004 06:40:32 -0000 1.468
@@ -1106,6 +1106,7 @@
struct exit_policy_t **dest);
void exit_policy_free(struct exit_policy_t *p);
const char *get_data_directory(void);
+int config_option_is_recognized(const char *key);
struct config_line_t *config_get_assigned_option(or_options_t *options,
const char *key);
struct config_line_t *config_line_prepend(struct config_line_t *front,