Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2424e64

Browse files
committed
config: harden our use of the backend objects a bit
When we create an iterator we don't actually know that we have a live config object and we must instead only rely on the header. We fixed it to use this in a previous commit, but this makes it harder to misuse by converting to use the header object in the typecast. We also guard inside the `config_refresh` function against being given a snapshot (although callers right now do check).
1 parent 1785de4 commit 2424e64

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/config_file.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,9 @@ static int config_refresh(git_config_backend *cfg)
326326
int error, modified;
327327
uint32_t i;
328328

329+
if (b->header.parent.readonly)
330+
return 0;
331+
329332
error = config_is_modified(&modified, &b->file);
330333
if (error < 0 && error != GIT_ENOTFOUND)
331334
goto out;
@@ -416,13 +419,13 @@ static int config_iterator_new(
416419
diskfile_header *h;
417420
git_config_file_iter *it;
418421
git_config_backend *snapshot;
419-
diskfile_backend *b = (diskfile_backend *) backend;
422+
diskfile_header *bh = (diskfile_header *) backend;
420423
int error;
421424

422425
if ((error = config_snapshot(&snapshot, backend)) < 0)
423426
return error;
424427

425-
if ((error = snapshot->open(snapshot, b->header.level, b->header.repo)) < 0)
428+
if ((error = snapshot->open(snapshot, bh->level, bh->repo)) < 0)
426429
return error;
427430

428431
it = git__calloc(1, sizeof(git_config_file_iter));

0 commit comments

Comments
 (0)