mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-30 23:53:32 +01:00
prop250: Pass the dst length to sr_srv_encode()
Signed-off-by: David Goulet <dgoulet@torproject.org>
This commit is contained in:
parent
d43646e191
commit
5fe9a50c31
@ -437,7 +437,7 @@ generate_srv(const char *hashed_reveals, uint8_t reveal_num,
|
|||||||
{
|
{
|
||||||
/* Debugging. */
|
/* Debugging. */
|
||||||
char srv_hash_encoded[SR_SRV_VALUE_BASE64_LEN + 1];
|
char srv_hash_encoded[SR_SRV_VALUE_BASE64_LEN + 1];
|
||||||
sr_srv_encode(srv_hash_encoded, srv);
|
sr_srv_encode(srv_hash_encoded, sizeof(srv_hash_encoded), srv);
|
||||||
log_debug(LD_DIR, "SR: Generated SRV: %s", srv_hash_encoded);
|
log_debug(LD_DIR, "SR: Generated SRV: %s", srv_hash_encoded);
|
||||||
}
|
}
|
||||||
return srv;
|
return srv;
|
||||||
@ -504,7 +504,7 @@ srv_to_ns_string(const sr_srv_t *srv, const char *key)
|
|||||||
tor_assert(srv);
|
tor_assert(srv);
|
||||||
tor_assert(key);
|
tor_assert(key);
|
||||||
|
|
||||||
sr_srv_encode(srv_hash_encoded, srv);
|
sr_srv_encode(srv_hash_encoded, sizeof(srv_hash_encoded), srv);
|
||||||
tor_asprintf(&srv_str, "%s %d %s\n", key,
|
tor_asprintf(&srv_str, "%s %d %s\n", key,
|
||||||
srv->num_reveals, srv_hash_encoded);
|
srv->num_reveals, srv_hash_encoded);
|
||||||
log_debug(LD_DIR, "SR: Consensus SRV line: %s", srv_str);
|
log_debug(LD_DIR, "SR: Consensus SRV line: %s", srv_str);
|
||||||
@ -839,7 +839,7 @@ get_majority_srv_from_votes(const smartlist_t *votes, int current)
|
|||||||
{
|
{
|
||||||
/* Debugging */
|
/* Debugging */
|
||||||
char encoded[SR_SRV_VALUE_BASE64_LEN + 1];
|
char encoded[SR_SRV_VALUE_BASE64_LEN + 1];
|
||||||
sr_srv_encode(encoded, the_srv);
|
sr_srv_encode(encoded, sizeof(encoded), the_srv);
|
||||||
log_debug(LD_DIR, "SR: Chosen SRV by majority: %s (%d votes)", encoded,
|
log_debug(LD_DIR, "SR: Chosen SRV by majority: %s (%d votes)", encoded,
|
||||||
count);
|
count);
|
||||||
}
|
}
|
||||||
@ -853,7 +853,7 @@ get_majority_srv_from_votes(const smartlist_t *votes, int current)
|
|||||||
/* Encode the given shared random value and put it in dst. Destination
|
/* Encode the given shared random value and put it in dst. Destination
|
||||||
* buffer must be at least SR_SRV_VALUE_BASE64_LEN plus the NULL byte. */
|
* buffer must be at least SR_SRV_VALUE_BASE64_LEN plus the NULL byte. */
|
||||||
void
|
void
|
||||||
sr_srv_encode(char *dst, const sr_srv_t *srv)
|
sr_srv_encode(char *dst, size_t dst_len, const sr_srv_t *srv)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
/* Extra byte for the NULL terminated char. */
|
/* Extra byte for the NULL terminated char. */
|
||||||
@ -861,12 +861,14 @@ sr_srv_encode(char *dst, const sr_srv_t *srv)
|
|||||||
|
|
||||||
tor_assert(dst);
|
tor_assert(dst);
|
||||||
tor_assert(srv);
|
tor_assert(srv);
|
||||||
|
tor_assert(dst_len >= sizeof(buf));
|
||||||
|
|
||||||
ret = base64_encode(buf, sizeof(buf), (const char *) srv->value,
|
ret = base64_encode(buf, sizeof(buf), (const char *) srv->value,
|
||||||
sizeof(srv->value), 0);
|
sizeof(srv->value), 0);
|
||||||
/* Always expect the full length without the NULL byte. */
|
/* Always expect the full length without the NULL byte. */
|
||||||
tor_assert(ret == (sizeof(buf) - 1));
|
tor_assert(ret == (sizeof(buf) - 1));
|
||||||
strlcpy(dst, buf, sizeof(buf));
|
tor_assert(ret <= (int) dst_len);
|
||||||
|
strlcpy(dst, buf, dst_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Free a commit object. */
|
/* Free a commit object. */
|
||||||
|
@ -114,7 +114,7 @@ sr_srv_t *sr_parse_srv(const smartlist_t *args);
|
|||||||
char *sr_get_string_for_vote(void);
|
char *sr_get_string_for_vote(void);
|
||||||
char *sr_get_string_for_consensus(const smartlist_t *votes);
|
char *sr_get_string_for_consensus(const smartlist_t *votes);
|
||||||
void sr_commit_free(sr_commit_t *commit);
|
void sr_commit_free(sr_commit_t *commit);
|
||||||
void sr_srv_encode(char *dst, const sr_srv_t *srv);
|
void sr_srv_encode(char *dst, size_t dst_len, const sr_srv_t *srv);
|
||||||
|
|
||||||
/* Private methods (only used by shared_random_state.c): */
|
/* Private methods (only used by shared_random_state.c): */
|
||||||
static inline
|
static inline
|
||||||
|
@ -589,7 +589,7 @@ disk_state_put_srv_line(const sr_srv_t *srv, config_line_t *line)
|
|||||||
if (srv == NULL) {
|
if (srv == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sr_srv_encode(encoded, srv);
|
sr_srv_encode(encoded, sizeof(encoded), srv);
|
||||||
tor_asprintf(&line->value, "%d %s", srv->num_reveals, encoded);
|
tor_asprintf(&line->value, "%d %s", srv->num_reveals, encoded);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user