summaryrefslogtreecommitdiff
path: root/src/or/consdiff.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/or/consdiff.c')
-rw-r--r--src/or/consdiff.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/or/consdiff.c b/src/or/consdiff.c
index d2a2af1b5f..c0fe979b60 100644
--- a/src/or/consdiff.c
+++ b/src/or/consdiff.c
@@ -671,7 +671,7 @@ gen_ed_diff(const smartlist_t *cons1, const smartlist_t *cons2,
*/
i1=len1-1, i2=len2-1;
char buf[128];
- while (i1 > 0 || i2 > 0) {
+ while (i1 >= 0 || i2 >= 0) {
int start1x, start2x, end1, end2, added, deleted;
@@ -757,6 +757,9 @@ get_linenum(const char **s, int *num_out)
{
int ok;
char *next;
+ if (!TOR_ISDIGIT(**s)) {
+ return -1;
+ }
*num_out = (int) tor_parse_long(*s, 10, 0, INT32_MAX, &ok, &next);
if (ok && next) {
*s = next;
@@ -795,6 +798,7 @@ apply_ed_diff(const smartlist_t *cons1, const smartlist_t *diff,
diff_line[diff_cdline->len] = 0;
const char *ptr = diff_line;
int start = 0, end = 0;
+ int had_range = 0;
if (get_linenum(&ptr, &start) < 0) {
log_warn(LD_CONSDIFF, "Could not apply consensus diff because "
"an ed command was missing a line number.");
@@ -802,6 +806,7 @@ apply_ed_diff(const smartlist_t *cons1, const smartlist_t *diff,
}
if (*ptr == ',') {
/* Two-item range */
+ had_range = 1;
++ptr;
if (get_linenum(&ptr, &end) < 0) {
log_warn(LD_CONSDIFF, "Could not apply consensus diff because "
@@ -850,6 +855,13 @@ apply_ed_diff(const smartlist_t *cons1, const smartlist_t *diff,
goto error_cleanup;
}
+ /* 'a' commands are not allowed to have ranges. */
+ if (had_range && action == 'a') {
+ log_warn(LD_CONSDIFF, "Could not apply consensus diff because "
+ "it wanted to add lines after a range.");
+ goto error_cleanup;
+ }
+
/* Add unchanged lines. */
for (; j && j > end; --j) {
cdline_t *cons_line = smartlist_get(cons1, j-1);