File tree Expand file tree Collapse file tree 2 files changed +86
-0
lines changed
Expand file tree Collapse file tree 2 files changed +86
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ * libgit2 config file parser fuzz target.
3+ *
4+ * Copyright (C) the libgit2 contributors. All rights reserved.
5+ *
6+ * This file is part of libgit2, distributed under the GNU GPL v2 with
7+ * a Linking Exception. For full terms see the included COPYING file.
8+ */
9+
10+ #include <git2.h>
11+
12+ #include <stdlib.h>
13+ #include <stdio.h>
14+ #include <unistd.h>
15+ #include <limits.h>
16+ #include <errno.h>
17+
18+ #define UNUSED (x ) (void)(x)
19+
20+ int foreach_cb (const git_config_entry * entry , void * payload )
21+ {
22+ UNUSED (entry );
23+ UNUSED (payload );
24+
25+ return 0 ;
26+ }
27+
28+ static char path [] = "/tmp/git.XXXXXX" ;
29+ static int fd = -1 ;
30+
31+ int LLVMFuzzerInitialize (int * argc , char * * * argv )
32+ {
33+ UNUSED (argc );
34+ UNUSED (argv );
35+
36+ if (git_libgit2_init () < 0 )
37+ abort ();
38+ fd = mkstemp (path );
39+ if (fd < 0 ) {
40+ abort ();
41+ }
42+
43+ return 0 ;
44+ }
45+
46+ int LLVMFuzzerTestOneInput (const uint8_t * data , size_t size )
47+ {
48+ git_config * cfg = NULL ;
49+ int err = 0 ;
50+ size_t total = 0 ;
51+
52+ if (ftruncate (fd , 0 ) != 0 ) {
53+ abort ();
54+ }
55+ if (lseek (fd , 0 , SEEK_SET ) != 0 ) {
56+ abort ();
57+ }
58+
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 ;
66+ }
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 );
72+ }
73+
74+ return 0 ;
75+ }
Original file line number Diff line number Diff line change 1+ [core]
2+ repositoryformatversion = 0
3+ filemode = true
4+ bare = false
5+ logallrefupdates = true
6+ [remote "origin"]
7+ url = git@github.com:libgit2/libgit2
8+ fetch = +refs/heads/*:refs/remotes/origin/*
9+ [branch "master"]
10+ remote = origin
11+ merge = refs/heads/master
You can’t perform that action at this time.
0 commit comments