88 */
99
1010#include <git2.h>
11+ #include "config_backend.h"
1112
1213#include <stdlib.h>
1314#include <stdio.h>
@@ -25,51 +26,43 @@ int foreach_cb(const git_config_entry *entry, void *payload)
2526 return 0 ;
2627}
2728
28- static char path [] = "/tmp/git.XXXXXX" ;
29- static int fd = -1 ;
30-
3129int LLVMFuzzerInitialize (int * argc , char * * * argv )
3230{
3331 UNUSED (argc );
3432 UNUSED (argv );
3533
3634 if (git_libgit2_init () < 0 )
3735 abort ();
38- fd = mkstemp (path );
39- if (fd < 0 ) {
40- abort ();
41- }
4236
4337 return 0 ;
4438}
4539
4640int LLVMFuzzerTestOneInput (const uint8_t * data , size_t size )
4741{
4842 git_config * cfg = NULL ;
43+ git_config_backend * backend = NULL ;
4944 int err = 0 ;
50- size_t total = 0 ;
5145
52- if (ftruncate (fd , 0 ) != 0 ) {
53- abort ();
54- }
55- if (lseek (fd , 0 , SEEK_SET ) != 0 ) {
56- abort ();
46+ err = git_config_new (& cfg );
47+ if (err != 0 ) {
48+ goto out ;
5749 }
5850
59- while (total < size ) {
60- ssize_t written = write (fd , data , size );
61- if (written < 0 && errno != EINTR )
62- abort ();
63- if (written < 0 )
64- continue ;
65- total += written ;
51+ err = git_config_backend_from_string (& backend , (const char * )data , size );
52+ if (err != 0 ) {
53+ goto out ;
6654 }
67-
68- err = git_config_open_ondisk (& cfg , path );
69- if (err == 0 ) {
70- git_config_foreach (cfg , foreach_cb , NULL );
71- git_config_free (cfg );
55+ err = git_config_add_backend (cfg , backend , 0 , NULL , 0 );
56+ if (err != 0 ) {
57+ goto out ;
7258 }
59+ // Now owned by the config
60+ backend = NULL ;
61+
62+ git_config_foreach (cfg , foreach_cb , NULL );
63+ out :
64+ git_config_backend_free (backend );
65+ git_config_free (cfg );
7366
7467 return 0 ;
7568}
0 commit comments