Commit f0b10066650b99a4d79b96a7174ea1311361c467

Patrick Steinhardt 2019-07-24T18:37:14

config_file: fix cast of readonly backend In `backend_readonly_free`, the passed in config backend is being cast to a `diskfile_backend` instead of to a `diskfile_readonly_backend`. While this works out just fine because we only access its header values, which were shared between both backends, it is undefined behaviour. Use the correct type to fix this.

1
2
3
4
5
6
7
8
9
10
11
12
13
diff --git a/src/config_file.c b/src/config_file.c
index 31b311f..448d7bf 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -625,7 +625,7 @@ static int config_unlock_readonly(git_config_backend *_cfg, int success)
 
 static void backend_readonly_free(git_config_backend *_backend)
 {
-	diskfile_backend *backend = GIT_CONTAINER_OF(_backend, diskfile_backend, parent);
+	diskfile_readonly_backend *backend = GIT_CONTAINER_OF(_backend, diskfile_readonly_backend, parent);
 
 	if (backend == NULL)
 		return;