@@ -103,7 +103,8 @@ static void t_read_file(void)
103
103
static int write_test_ref (struct reftable_writer * wr , void * arg )
104
104
{
105
105
struct reftable_ref_record * ref = arg ;
106
- reftable_writer_set_limits (wr , ref -> update_index , ref -> update_index );
106
+ check (!reftable_writer_set_limits (wr , ref -> update_index ,
107
+ ref -> update_index ));
107
108
return reftable_writer_add_ref (wr , ref );
108
109
}
109
110
@@ -143,7 +144,8 @@ static int write_test_log(struct reftable_writer *wr, void *arg)
143
144
{
144
145
struct write_log_arg * wla = arg ;
145
146
146
- reftable_writer_set_limits (wr , wla -> update_index , wla -> update_index );
147
+ check (!reftable_writer_set_limits (wr , wla -> update_index ,
148
+ wla -> update_index ));
147
149
return reftable_writer_add_log (wr , wla -> log );
148
150
}
149
151
@@ -961,7 +963,7 @@ static void t_reflog_expire(void)
961
963
962
964
static int write_nothing (struct reftable_writer * wr , void * arg UNUSED )
963
965
{
964
- reftable_writer_set_limits (wr , 1 , 1 );
966
+ check (! reftable_writer_set_limits (wr , 1 , 1 ) );
965
967
return 0 ;
966
968
}
967
969
@@ -1369,11 +1371,57 @@ static void t_reftable_stack_reload_with_missing_table(void)
1369
1371
clear_dir (dir );
1370
1372
}
1371
1373
1374
+ static int write_limits_after_ref (struct reftable_writer * wr , void * arg )
1375
+ {
1376
+ struct reftable_ref_record * ref = arg ;
1377
+ check (!reftable_writer_set_limits (wr , ref -> update_index , ref -> update_index ));
1378
+ check (!reftable_writer_add_ref (wr , ref ));
1379
+ return reftable_writer_set_limits (wr , ref -> update_index , ref -> update_index );
1380
+ }
1381
+
1382
+ static void t_reftable_invalid_limit_updates (void )
1383
+ {
1384
+ struct reftable_ref_record ref = {
1385
+ .refname = (char * ) "HEAD" ,
1386
+ .update_index = 1 ,
1387
+ .value_type = REFTABLE_REF_SYMREF ,
1388
+ .value .symref = (char * ) "master" ,
1389
+ };
1390
+ struct reftable_write_options opts = {
1391
+ .default_permissions = 0660 ,
1392
+ };
1393
+ struct reftable_addition * add = NULL ;
1394
+ char * dir = get_tmp_dir (__LINE__ );
1395
+ struct reftable_stack * st = NULL ;
1396
+ int err ;
1397
+
1398
+ err = reftable_new_stack (& st , dir , & opts );
1399
+ check (!err );
1400
+
1401
+ reftable_addition_destroy (add );
1402
+
1403
+ err = reftable_stack_new_addition (& add , st , 0 );
1404
+ check (!err );
1405
+
1406
+ /*
1407
+ * write_limits_after_ref also updates the update indexes after adding
1408
+ * the record. This should cause an err to be returned, since the limits
1409
+ * must be set at the start.
1410
+ */
1411
+ err = reftable_addition_add (add , write_limits_after_ref , & ref );
1412
+ check_int (err , = = , REFTABLE_API_ERROR );
1413
+
1414
+ reftable_addition_destroy (add );
1415
+ reftable_stack_destroy (st );
1416
+ clear_dir (dir );
1417
+ }
1418
+
1372
1419
int cmd_main (int argc UNUSED , const char * argv [] UNUSED )
1373
1420
{
1374
1421
TEST (t_empty_add (), "empty addition to stack" );
1375
1422
TEST (t_read_file (), "read_lines works" );
1376
1423
TEST (t_reflog_expire (), "expire reflog entries" );
1424
+ TEST (t_reftable_invalid_limit_updates (), "prevent limit updates after adding records" );
1377
1425
TEST (t_reftable_stack_add (), "add multiple refs and logs to stack" );
1378
1426
TEST (t_reftable_stack_add_one (), "add a single ref record to stack" );
1379
1427
TEST (t_reftable_stack_add_performs_auto_compaction (), "addition to stack triggers auto-compaction" );
0 commit comments