Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Tor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
The Tor Project
Core
Tor
Commits
209229f1
Commit
209229f1
authored
13 years ago
by
Nick Mathewson
Browse files
Options
Downloads
Plain Diff
Merge branch 'bug3407' into maint-0.2.2
parents
64bfbcb9
227896e4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
changes/fix-connection_printf_to_buf
+15
-0
15 additions, 0 deletions
changes/fix-connection_printf_to_buf
src/or/control.c
+21
-43
21 additions, 43 deletions
src/or/control.c
with
36 additions
and
43 deletions
changes/fix-connection_printf_to_buf
0 → 100644
+
15
−
0
View file @
209229f1
* Code simplifications and refactoring:
- Make connection_printf_to_buf's behaviour sane. Its callers
expect it to emit a CRLF iff the format string ends with CRLF;
it actually emits a CRLF iff (a) the format string ends with
CRLF or (b) the resulting string is over 1023 characters long or
(c) the format string does not end with CRLF ''and'' the
resulting string is 1021 characters long or longer. Bugfix on
0.1.1.9-alpha; fixes part of bug 3407.
- Make send_control_event_impl's behaviour sane. Its callers
expect it to always emit a CRLF at the end of the string; it
might emit extra control characters as well. Bugfix on
0.1.1.9-alpha; fixes another part of bug 3407.
This diff is collapsed.
Click to expand it.
src/or/control.c
+
21
−
43
View file @
209229f1
...
...
@@ -98,7 +98,7 @@ static int disable_log_messages = 0;
static
int
authentication_cookie_is_set
=
0
;
/** If authentication_cookie_is_set, a secret cookie that we've stored to disk
* and which we're using to authenticate controllers. (If the controller can
* read it off disk, it has permission to connect. */
* read it off disk, it has permission to connect.
)
*/
static
char
authentication_cookie
[
AUTHENTICATION_COOKIE_LEN
];
/** A sufficiently large size to record the last bootstrap phase string. */
...
...
@@ -481,33 +481,26 @@ decode_escaped_string(const char *start, size_t in_len_max,
}
/** Acts like sprintf, but writes its formatted string to the end of
* <b>conn</b>-\>outbuf. The message may be truncated if it is too long,
* but it will always end with a CRLF sequence.
*
* Currently the length of the message is limited to 1024 (including the
* ending CR LF NUL ("\\r\\n\\0"). */
* <b>conn</b>-\>outbuf. */
static
void
connection_printf_to_buf
(
control_connection_t
*
conn
,
const
char
*
format
,
...)
{
#define CONNECTION_PRINTF_TO_BUF_BUFFERSIZE 1024
va_list
ap
;
char
buf
[
CONNECTION_PRINTF_TO_BUF_BUFFERSIZE
]
;
int
r
;
size_t
len
;
char
*
buf
=
NULL
;
int
len
;
va_start
(
ap
,
format
);
r
=
tor_vs
n
printf
(
buf
,
sizeof
(
buf
)
,
format
,
ap
);
len
=
tor_v
a
sprintf
(
&
buf
,
format
,
ap
);
va_end
(
ap
);
if
(
r
<
0
)
{
if
(
len
<
0
)
{
log_warn
(
LD_BUG
,
"Unable to format string for controller."
);
return
;
}
len
=
strlen
(
buf
);
if
(
fast_memcmp
(
"
\r\n\0
"
,
buf
+
len
-
2
,
3
))
{
buf
[
CONNECTION_PRINTF_TO_BUF_BUFFERSIZE
-
1
]
=
'\0'
;
buf
[
CONNECTION_PRINTF_TO_BUF_BUFFERSIZE
-
2
]
=
'\n'
;
buf
[
CONNECTION_PRINTF_TO_BUF_BUFFERSIZE
-
3
]
=
'\r'
;
}
connection_write_to_buf
(
buf
,
len
,
TO_CONN
(
conn
));
connection_write_to_buf
(
buf
,
(
size_t
)
len
,
TO_CONN
(
conn
));
tor_free
(
buf
);
}
/** Write all of the open control ports to ControlPortWriteToFile */
...
...
@@ -606,46 +599,31 @@ send_control_event_string(uint16_t event, event_format_t which,
}
SMARTLIST_FOREACH_END
(
conn
);
}
/** Helper for send_control
1
_event and
send_
control
1
_event_
extended
:
/** Helper for send_control_event and control_event_
status
:
* Send an event to all v1 controllers that are listening for code
* <b>event</b>. The event's body is created by the printf-style format in
* <b>format</b>, and other arguments as provided.
*
* Currently the length of the message is limited to 1024 (including the
* ending \\r\\n\\0). */
* <b>format</b>, and other arguments as provided. */
static
void
send_control_event_impl
(
uint16_t
event
,
event_format_t
which
,
const
char
*
format
,
va_list
ap
)
{
/* This is just a little longer than the longest allowed log message */
#define SEND_CONTROL1_EVENT_BUFFERSIZE 10064
int
r
;
char
buf
[
SEND_CONTROL1_EVENT_BUFFERSIZE
];
size_t
len
;
char
*
buf
=
NULL
;
int
len
;
r
=
tor_vs
n
printf
(
buf
,
sizeof
(
buf
)
,
format
,
ap
);
if
(
r
<
0
)
{
len
=
tor_v
a
sprintf
(
&
buf
,
format
,
ap
);
if
(
len
<
0
)
{
log_warn
(
LD_BUG
,
"Unable to format event for controller."
);
return
;
}
len
=
strlen
(
buf
);
if
(
fast_memcmp
(
"
\r\n\0
"
,
buf
+
len
-
2
,
3
))
{
/* if it is not properly terminated, do it now */
buf
[
SEND_CONTROL1_EVENT_BUFFERSIZE
-
1
]
=
'\0'
;
buf
[
SEND_CONTROL1_EVENT_BUFFERSIZE
-
2
]
=
'\n'
;
buf
[
SEND_CONTROL1_EVENT_BUFFERSIZE
-
3
]
=
'\r'
;
}
send_control_event_string
(
event
,
which
|
ALL_FORMATS
,
buf
);
tor_free
(
buf
);
}
/** Send an event to all v1 controllers that are listening for code
* <b>event</b>. The event's body is created by the printf-style format in
* <b>format</b>, and other arguments as provided.
*
* Currently the length of the message is limited to 1024 (including the
* ending \\n\\r\\0. */
* <b>format</b>, and other arguments as provided. */
static
void
send_control_event
(
uint16_t
event
,
event_format_t
which
,
const
char
*
format
,
...)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment