[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[PATCH] Fix send_control_event()



Hi!

According to the new control spec document, the "EVENT" message sent to a UI client contains the 2-byte event code followed by event-dependent information.

However, according to the source code, that is not the case :D.

Attached (hopefully) is a patch against TOR 0.0.9pre5 which fixes this. Briefly tested with my PHP test client.

This is my first patch submission for TOR, so please let me know if this is ok.

Cheers,
Andre Eisenbach <andre@eisenbach.com>
--- control.c.orig	2004-11-10 18:07:24.000000000 -0600
+++ control.c	2004-11-10 18:25:13.000000000 -0600
@@ -184,15 +184,24 @@ send_control_event(uint16_t event, uint1
 {
   connection_t **conns;
   int n_conns, i;
+  size_t buflen;
+  char *buf;
+
+  buflen = len + 2;
+  buf = tor_malloc_zero(buflen);
+  set_uint16(buf, htons(event));
+  memcpy(buf+2, body, len);
 
   get_connection_array(&conns, &n_conns);
   for (i = 0; i < n_conns; ++i) {
     if (conns[i]->type == CONN_TYPE_CONTROL &&
         conns[i]->state == CONTROL_CONN_STATE_OPEN &&
         conns[i]->event_mask & (1<<event)) {
-      send_control_message(conns[i], CONTROL_CMD_EVENT, len, body);
+      send_control_message(conns[i], CONTROL_CMD_EVENT, (uint16_t)(buflen), buf);
     }
   }
+
+  tor_free(buf); 
 }
 
 /** Called when we receive a SETCONF message: parse the body and try