EXIF library (libexif) Internals  0.6.24
test-fuzzer-persistent.c
Go to the documentation of this file.
1 
26 #include <string.h>
27 #include <unistd.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <sys/stat.h>
31 
32 #include "libexif/exif-data.h"
33 #include "libexif/exif-loader.h"
34 #include "libexif/exif-system.h"
35 
37 
38 #undef USE_LOG
39 
40 #ifdef USE_LOG
41 static void
42 logfunc(ExifLog *log, ExifLogCode code, const char *domain, const char *format, va_list args, void *data)
43 {
44  fprintf( stderr, "test-fuzzer: code=%d domain=%s ", code, domain);
45  vfprintf (stderr, format, args);
46  fprintf (stderr, "\n");
47 }
48 #endif
49 
51 void content_foreach_func(ExifEntry *entry, void *callback_data);
52 void content_foreach_func(ExifEntry *entry, void *UNUSED(callback_data))
53 {
54  char buf[2001];
55 
56  /* ensure \0 */
57  buf[sizeof(buf)-1] = 0;
58  buf[sizeof(buf)-2] = 0;
59  exif_tag_get_name(entry->tag);
61  exif_entry_get_value(entry, buf, sizeof(buf)-1);
62  if (buf[sizeof(buf)-2] != 0) abort();
63 }
64 
65 
67 void data_foreach_func(ExifContent *content, void *callback_data);
68 void data_foreach_func(ExifContent *content, void *callback_data)
69 {
70  printf(" Content %p: ifd=%d\n", (void *)content, exif_content_get_ifd(content));
71  exif_content_foreach_entry(content, content_foreach_func, callback_data);
72 }
73 static int
75 {
76  unsigned int i, c;
77  char v[1024];
78  ExifMnoteData *md;
79 
80  fprintf (stdout, "Byte order: %s\n",
82 
83  md = exif_data_get_mnote_data (d);
84  if (!md) {
85  fprintf (stderr, "Could not parse maker note!\n");
86  return 1;
87  }
88 
91 
92  c = exif_mnote_data_count (md);
93  for (i = 0; i < c; i++) {
94  const char *name = exif_mnote_data_get_name (md, i);
95  if (!name) continue;
99  exif_mnote_data_get_value (md, i, v, sizeof (v));
100  }
101 
102  return 0;
103 }
104 
106 int main(const int argc, const char *argv[])
107 {
108  int i;
109  ExifData *d;
110  ExifLoader *loader = exif_loader_new();
111  unsigned int xbuf_size;
112  unsigned char *xbuf;
113  FILE *f;
114  struct stat stbuf;
115 #ifdef USE_LOG
116  ExifLog *log = exif_log_new ();
117 
118  exif_log_set_func(log, logfunc, NULL);
119 #endif
120 
121 #ifdef __AFL_HAVE_MANUAL_CONTROL
122  __AFL_INIT();
123 #endif
124 
125  unsigned char *buf = __AFL_FUZZ_TESTCASE_BUF; // must be after __AFL_INIT
126  // and before __AFL_LOOP!
127 
128  while (__AFL_LOOP(10000)) {
129 
130  int len = __AFL_FUZZ_TESTCASE_LEN; // don't use the macro directly in a call!
131 
132  d = exif_data_new_from_data(buf, len);
133 
134  /* try the exif loader */
135  #ifdef USE_LOG
136  exif_data_log (d, log);
137  #endif
139  test_exif_data (d);
140 
141  xbuf = NULL;
142  exif_data_save_data (d, &xbuf, &xbuf_size);
143  free (xbuf);
144 
146 
147  xbuf = NULL;
148  exif_data_save_data (d, &xbuf, &xbuf_size);
149  free (xbuf);
150 
151  exif_data_unref(d);
152 
153 #if 0
154  /* try the exif data writer ... different than the loader */
155 
156  exif_loader_write(loader, buf, len);
157 
158  d = exif_loader_get_data(loader);
160  test_exif_data (d);
161  exif_loader_unref(loader);
162  exif_data_unref(d);
163 #endif
164  }
165  return 0;
166 }
const char * exif_byte_order_get_name(ExifByteOrder order)
Return a short, localized, textual name for the given byte order.
@ EXIF_BYTE_ORDER_INTEL
Little-endian byte order.
ExifIfd exif_content_get_ifd(ExifContent *c)
Return the IFD number in which the given ExifContent is found.
Definition: exif-content.c:240
void exif_content_foreach_entry(ExifContent *content, ExifContentForeachEntryFunc func, void *data)
Executes function on each EXIF tag in this IFD in turn.
Definition: exif-content.c:216
void exif_data_set_byte_order(ExifData *data, ExifByteOrder order)
Set the byte order to use for this EXIF data.
Definition: exif-data.c:1217
void exif_data_unref(ExifData *data)
Definition: exif-data.c:1098
ExifByteOrder exif_data_get_byte_order(ExifData *data)
Return the byte order in use by this EXIF structure.
Definition: exif-data.c:1173
ExifData * exif_data_new_from_data(const unsigned char *data, unsigned int size)
Allocate a new ExifData and load EXIF data from a memory buffer.
Definition: exif-data.c:154
ExifMnoteData * exif_data_get_mnote_data(ExifData *d)
Return the MakerNote data out of the EXIF data.
Definition: exif-data.c:90
void exif_data_save_data(ExifData *data, unsigned char **d, unsigned int *ds)
Store raw EXIF data representing the ExifData structure into a memory buffer.
Definition: exif-data.c:1030
void exif_data_foreach_content(ExifData *data, ExifDataForeachContentFunc func, void *user_data)
Execute a function on each IFD in turn.
Definition: exif-data.c:1182
void exif_data_log(ExifData *data, ExifLog *log)
Set the log message object for all IFDs.
Definition: exif-data.c:1233
Defines the ExifData type and the associated functions.
const char * exif_entry_get_value(ExifEntry *e, char *val, unsigned int maxlen)
Return a localized textual representation of the value of the EXIF entry.
Definition: exif-entry.c:846
const char * exif_format_get_name(ExifFormat format)
Return a textual representation of the given EXIF data type.
Definition: exif-format.c:53
ExifFormat format
Definition: exif-format.c:33
ExifLoader * exif_loader_new(void)
Allocate a new ExifLoader.
Definition: exif-loader.c:352
void exif_loader_unref(ExifLoader *loader)
Decrease the refcount of the ExifLoader.
Definition: exif-loader.c:404
ExifData * exif_loader_get_data(ExifLoader *loader)
Create an ExifData from the data in the loader.
Definition: exif-loader.c:426
unsigned char exif_loader_write(ExifLoader *eld, unsigned char *buf, unsigned int len)
Load a buffer into the ExifLoader from a memory buffer.
Definition: exif-loader.c:163
Defines the ExifLoader type.
ExifLogCode code
Definition: exif-log.c:39
void exif_log_set_func(ExifLog *log, ExifLogFunc func, void *data)
Register log callback function.
Definition: exif-log.c:123
ExifLog * exif_log_new(void)
Create a new logging instance.
Definition: exif-log.c:86
ExifLogCode
Definition: exif-log.h:54
void exif_mnote_data_ref(ExifMnoteData *d)
char * exif_mnote_data_get_value(ExifMnoteData *d, unsigned int n, char *val, unsigned int maxlen)
Return a textual representation of the value of the MakerNote entry.
const char * exif_mnote_data_get_name(ExifMnoteData *d, unsigned int n)
Returns textual name of the given MakerNote tag.
const char * exif_mnote_data_get_description(ExifMnoteData *d, unsigned int n)
Returns verbose textual description of the given MakerNote tag.
const char * exif_mnote_data_get_title(ExifMnoteData *d, unsigned int n)
Returns textual title of the given MakerNote tag.
unsigned int exif_mnote_data_count(ExifMnoteData *d)
Return the number of tags in the MakerNote.
void exif_mnote_data_unref(ExifMnoteData *d)
System specific definitions, not for installation!
#define UNUSED(param)
Definition: exif-system.h:29
const char * exif_tag_get_name(ExifTag tag)
Definition: exif-tag.c:1147
const char * name
Represents the entire EXIF data found in an image.
Definition: exif-data.h:47
Data found in one EXIF tag.
Definition: exif-entry.h:43
ExifFormat format
Type of data in this entry.
Definition: exif-entry.h:48
ExifTag tag
EXIF tag for this entry.
Definition: exif-entry.h:45
void data_foreach_func(ExifContent *content, void *callback_data)
static int test_exif_data(ExifData *d)
int main(const int argc, const char *argv[])
void content_foreach_func(ExifEntry *entry, void *callback_data)
__AFL_FUZZ_INIT()
Persistent AFL fuzzing binary (reaches 4 digits execs / second)

libexif Generated by doxygen