EXIF library (libexif) Internals 0.6.26
test-fuzzer-persistent.c
Go to the documentation of this file.
1
27#include <string.h>
28#include <unistd.h>
29#include <stdio.h>
30#include <stdlib.h>
31#include <sys/stat.h>
32
33#include "libexif/exif-data.h"
34#include "libexif/exif-loader.h"
35#include "libexif/exif-system.h"
36
38
39#undef USE_LOG
40
41#ifdef USE_LOG
42static void
43logfunc(ExifLog *log, ExifLogCode code, const char *domain, const char *format, va_list args, void *data)
44{
45 fprintf( stderr, "test-fuzzer: code=%d domain=%s ", code, domain);
46 vfprintf (stderr, format, args);
47 fprintf (stderr, "\n");
48}
49#endif
50
52void content_foreach_func(ExifEntry *entry, void *callback_data);
53void content_foreach_func(ExifEntry *entry, void *UNUSED(callback_data))
54{
55 char buf[2001];
56
57 /* ensure \0 */
58 buf[sizeof(buf)-1] = 0;
59 buf[sizeof(buf)-2] = 0;
60 exif_tag_get_name(entry->tag);
62 exif_entry_get_value(entry, buf, sizeof(buf)-1);
63 if (buf[sizeof(buf)-2] != 0) abort();
64}
65
66
68void data_foreach_func(ExifContent *content, void *callback_data);
69void data_foreach_func(ExifContent *content, void *callback_data)
70{
71 printf(" Content %p: ifd=%d\n", (void *)content, exif_content_get_ifd(content));
72 exif_content_foreach_entry(content, content_foreach_func, callback_data);
73}
74static int
76{
77 unsigned int i, c;
78 char v[1024];
79 ExifMnoteData *md;
80
81 fprintf (stdout, "Byte order: %s\n",
83
85 if (!md) {
86 fprintf (stderr, "Could not parse maker note!\n");
87 return 1;
88 }
89
92
93 c = exif_mnote_data_count (md);
94 for (i = 0; i < c; i++) {
95 const char *name = exif_mnote_data_get_name (md, i);
96 if (!name) continue;
100 exif_mnote_data_get_value (md, i, v, sizeof (v));
101 }
102
103 return 0;
104}
105
107int main(const int argc, const char *argv[])
108{
109 int i;
110 ExifData *d;
111 ExifLoader *loader = exif_loader_new();
112 unsigned int xbuf_size;
113 unsigned char *xbuf;
114 FILE *f;
115 struct stat stbuf;
116#ifdef USE_LOG
117 ExifLog *log = exif_log_new ();
118
119 exif_log_set_func(log, logfunc, NULL);
120#endif
121
122#ifdef __AFL_HAVE_MANUAL_CONTROL
123 __AFL_INIT();
124#endif
125
126 unsigned char *buf = __AFL_FUZZ_TESTCASE_BUF; // must be after __AFL_INIT
127 // and before __AFL_LOOP!
128
129 while (__AFL_LOOP(10000)) {
130
131 int len = __AFL_FUZZ_TESTCASE_LEN; // don't use the macro directly in a call!
132
133 d = exif_data_new_from_data(buf, len);
134
135 /* try the exif loader */
136 #ifdef USE_LOG
137 exif_data_log (d, log);
138 #endif
140 test_exif_data (d);
141
142 xbuf = NULL;
143 exif_data_save_data (d, &xbuf, &xbuf_size);
144 free (xbuf);
145
147
148 xbuf = NULL;
149 exif_data_save_data (d, &xbuf, &xbuf_size);
150 free (xbuf);
151
153
154#if 0
155 /* try the exif data writer ... different than the loader */
156
157 exif_loader_write(loader, buf, len);
158
159 d = exif_loader_get_data(loader);
161 test_exif_data (d);
162 exif_loader_unref(loader);
164#endif
165 }
166 return 0;
167}
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.
void exif_content_foreach_entry(ExifContent *content, ExifContentForeachEntryFunc func, void *data)
Executes function on each EXIF tag in this IFD in turn.
void exif_data_set_byte_order(ExifData *data, ExifByteOrder order)
Set the byte order to use for this EXIF data.
Definition exif-data.c:1229
void exif_data_unref(ExifData *data)
Definition exif-data.c:1110
ExifByteOrder exif_data_get_byte_order(ExifData *data)
Return the byte order in use by this EXIF structure.
Definition exif-data.c:1185
ExifMnoteData * exif_data_get_mnote_data(ExifData *d)
Return the MakerNote data out of the EXIF data.
Definition exif-data.c:92
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:156
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:1042
void exif_data_foreach_content(ExifData *data, ExifDataForeachContentFunc func, void *user_data)
Execute a function on each IFD in turn.
Definition exif-data.c:1194
void exif_data_log(ExifData *data, ExifLog *log)
Set the log message object for all IFDs.
Definition exif-data.c:1245
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:854
const char * exif_format_get_name(ExifFormat format)
Return a textual representation of the given EXIF data type.
Definition exif-format.c:55
ExifFormat format
Definition exif-format.c:35
ExifLoader * exif_loader_new(void)
Allocate a new ExifLoader.
ExifData * exif_loader_get_data(ExifLoader *loader)
Create an ExifData from the data in the loader.
void exif_loader_unref(ExifLoader *loader)
Decrease the refcount of the ExifLoader.
unsigned char exif_loader_write(ExifLoader *eld, unsigned char *buf, unsigned int len)
Load a buffer into the ExifLoader from a memory buffer.
Defines the ExifLoader type.
ExifLog * exif_log_new(void)
Create a new logging instance.
Definition exif-log.c:88
ExifLogCode code
Definition exif-log.c:41
void exif_log_set_func(ExifLog *log, ExifLogFunc func, void *data)
Register log callback function.
Definition exif-log.c:125
ExifLogCode
Definition exif-log.h:56
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.
void exif_mnote_data_ref(ExifMnoteData *d)
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.
const char * exif_mnote_data_get_name(ExifMnoteData *d, unsigned int n)
Returns textual name 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:31
const char * exif_tag_get_name(ExifTag tag)
Definition exif-tag.c:1151
const char * name
int main(void)
Represents the entire EXIF data found in an image.
Definition exif-data.h:48
Data found in one EXIF tag.
Definition exif-entry.h:45
ExifFormat format
Type of data in this entry.
Definition exif-entry.h:50
ExifTag tag
EXIF tag for this entry.
Definition exif-entry.h:47
void data_foreach_func(ExifContent *content, void *callback_data)
static int test_exif_data(ExifData *d)
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