Merge branch 'kn/reftable-writer-log-write-verify'
Reftable backend adds check for upper limit of log's update_index. * kn/reftable-writer-log-write-verify: reftable/writer: ensure valid range for log's update_indexmaint
commit
f7c607fac3
|
@ -425,6 +425,18 @@ int reftable_writer_add_log(struct reftable_writer *w,
|
||||||
if (log->value_type == REFTABLE_LOG_DELETION)
|
if (log->value_type == REFTABLE_LOG_DELETION)
|
||||||
return reftable_writer_add_log_verbatim(w, log);
|
return reftable_writer_add_log_verbatim(w, log);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Verify only the upper limit of the update_index. Each reflog entry
|
||||||
|
* is tied to a specific update_index. Entries in the reflog can be
|
||||||
|
* replaced by adding a new entry with the same update_index,
|
||||||
|
* effectively canceling the old one.
|
||||||
|
*
|
||||||
|
* Consequently, reflog updates may include update_index values lower
|
||||||
|
* than the writer's min_update_index.
|
||||||
|
*/
|
||||||
|
if (log->update_index > w->max_update_index)
|
||||||
|
return REFTABLE_API_ERROR;
|
||||||
|
|
||||||
if (!log->refname)
|
if (!log->refname)
|
||||||
return REFTABLE_API_ERROR;
|
return REFTABLE_API_ERROR;
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,7 @@ static void t_log_buffer_size(void)
|
||||||
int i;
|
int i;
|
||||||
struct reftable_log_record
|
struct reftable_log_record
|
||||||
log = { .refname = (char *) "refs/heads/master",
|
log = { .refname = (char *) "refs/heads/master",
|
||||||
.update_index = 0xa,
|
.update_index = update_index,
|
||||||
.value_type = REFTABLE_LOG_UPDATE,
|
.value_type = REFTABLE_LOG_UPDATE,
|
||||||
.value = { .update = {
|
.value = { .update = {
|
||||||
.name = (char *) "Han-Wen Nienhuys",
|
.name = (char *) "Han-Wen Nienhuys",
|
||||||
|
@ -128,7 +128,7 @@ static void t_log_overflow(void)
|
||||||
int err;
|
int err;
|
||||||
struct reftable_log_record log = {
|
struct reftable_log_record log = {
|
||||||
.refname = (char *) "refs/heads/master",
|
.refname = (char *) "refs/heads/master",
|
||||||
.update_index = 0xa,
|
.update_index = update_index,
|
||||||
.value_type = REFTABLE_LOG_UPDATE,
|
.value_type = REFTABLE_LOG_UPDATE,
|
||||||
.value = {
|
.value = {
|
||||||
.update = {
|
.update = {
|
||||||
|
@ -152,6 +152,48 @@ static void t_log_overflow(void)
|
||||||
reftable_buf_release(&buf);
|
reftable_buf_release(&buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void t_log_write_limits(void)
|
||||||
|
{
|
||||||
|
struct reftable_write_options opts = { 0 };
|
||||||
|
struct reftable_buf buf = REFTABLE_BUF_INIT;
|
||||||
|
struct reftable_writer *w = t_reftable_strbuf_writer(&buf, &opts);
|
||||||
|
struct reftable_log_record log = {
|
||||||
|
.refname = (char *)"refs/head/master",
|
||||||
|
.update_index = 0,
|
||||||
|
.value_type = REFTABLE_LOG_UPDATE,
|
||||||
|
.value = {
|
||||||
|
.update = {
|
||||||
|
.old_hash = { 1 },
|
||||||
|
.new_hash = { 2 },
|
||||||
|
.name = (char *)"Han-Wen Nienhuys",
|
||||||
|
.email = (char *)"hanwen@google.com",
|
||||||
|
.tz_offset = 100,
|
||||||
|
.time = 0x5e430672,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
int err;
|
||||||
|
|
||||||
|
reftable_writer_set_limits(w, 1, 1);
|
||||||
|
|
||||||
|
/* write with update_index (0) below set limits (1, 1) */
|
||||||
|
err = reftable_writer_add_log(w, &log);
|
||||||
|
check_int(err, ==, 0);
|
||||||
|
|
||||||
|
/* write with update_index (1) in the set limits (1, 1) */
|
||||||
|
log.update_index = 1;
|
||||||
|
err = reftable_writer_add_log(w, &log);
|
||||||
|
check_int(err, ==, 0);
|
||||||
|
|
||||||
|
/* write with update_index (3) above set limits (1, 1) */
|
||||||
|
log.update_index = 3;
|
||||||
|
err = reftable_writer_add_log(w, &log);
|
||||||
|
check_int(err, ==, REFTABLE_API_ERROR);
|
||||||
|
|
||||||
|
reftable_writer_free(w);
|
||||||
|
reftable_buf_release(&buf);
|
||||||
|
}
|
||||||
|
|
||||||
static void t_log_write_read(void)
|
static void t_log_write_read(void)
|
||||||
{
|
{
|
||||||
struct reftable_write_options opts = {
|
struct reftable_write_options opts = {
|
||||||
|
@ -918,6 +960,7 @@ int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
|
||||||
TEST(t_corrupt_table_empty(), "read-write on an empty table");
|
TEST(t_corrupt_table_empty(), "read-write on an empty table");
|
||||||
TEST(t_log_buffer_size(), "buffer extension for log compression");
|
TEST(t_log_buffer_size(), "buffer extension for log compression");
|
||||||
TEST(t_log_overflow(), "log overflow returns expected error");
|
TEST(t_log_overflow(), "log overflow returns expected error");
|
||||||
|
TEST(t_log_write_limits(), "writer limits for writing log records");
|
||||||
TEST(t_log_write_read(), "read-write on log records");
|
TEST(t_log_write_read(), "read-write on log records");
|
||||||
TEST(t_log_zlib_corruption(), "reading corrupted log record returns expected error");
|
TEST(t_log_zlib_corruption(), "reading corrupted log record returns expected error");
|
||||||
TEST(t_table_read_api(), "read on a table");
|
TEST(t_table_read_api(), "read on a table");
|
||||||
|
|
|
@ -773,8 +773,12 @@ static void t_reftable_stack_tombstone(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
logs[i].refname = xstrdup(buf);
|
logs[i].refname = xstrdup(buf);
|
||||||
/* update_index is part of the key. */
|
/*
|
||||||
logs[i].update_index = 42;
|
* update_index is part of the key so should be constant.
|
||||||
|
* The value itself should be less than the writer's upper
|
||||||
|
* limit.
|
||||||
|
*/
|
||||||
|
logs[i].update_index = 1;
|
||||||
if (i % 2 == 0) {
|
if (i % 2 == 0) {
|
||||||
logs[i].value_type = REFTABLE_LOG_UPDATE;
|
logs[i].value_type = REFTABLE_LOG_UPDATE;
|
||||||
t_reftable_set_hash(logs[i].value.update.new_hash, i,
|
t_reftable_set_hash(logs[i].value.update.new_hash, i,
|
||||||
|
|
Loading…
Reference in New Issue