2 * \brief Pass NULL values into libexif APIs and ensure it doesn't crash.
4 * Copyright (C) 2019 Dan Fandrich <dan@coneharvesters.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301 USA.
23 #include "libexif/exif-data.h"
24 #include "libexif/exif-entry.h"
25 #include "libexif/exif-loader.h"
26 #include "libexif/exif-mnote-data.h"
31 static void loader_null_test(void)
36 const unsigned char *ccp;
39 l = exif_loader_new_mem(NULL);
41 fprintf(stderr, "Unexpected success in %s\n", "exif_loader_new_mem");
45 exif_loader_ref(NULL);
47 exif_loader_unref(NULL);
49 exif_loader_write_file(NULL, "test");
51 exif_loader_write_file(NULL, NULL);
53 ret = exif_loader_write(NULL, (unsigned char *)"x", 1);
55 fprintf(stderr, "Unexpected success in %s\n", "exif_loader_write");
59 exif_loader_write(NULL, NULL, 123);
61 exif_loader_reset(NULL);
63 d = exif_loader_get_data(NULL);
65 fprintf(stderr, "Unexpected success in %s\n", "exif_loader_get_data");
69 exif_loader_get_buf(NULL, NULL, NULL);
71 exif_loader_log(NULL, NULL);
73 l = exif_loader_new();
75 fprintf(stderr, "Out of memory\n");
79 exif_loader_write_file(l, NULL);
81 exif_loader_write(l, NULL, 0);
82 exif_loader_write(l, NULL, 1);
84 exif_loader_get_buf(l, NULL, NULL);
85 exif_loader_get_buf(l, &ccp, NULL);
86 exif_loader_get_buf(l, NULL, &i);
88 exif_loader_log(l, NULL);
93 static void data_null_test(void)
95 /* exif_data_new_from_file() is untested since it doesn't check path */
104 d = exif_data_new_mem(NULL);
106 fprintf(stderr, "Unexpected success in %s\n", "exif_data_new_mem");
110 d = exif_data_new_from_data(NULL, 123);
115 bo = exif_data_get_byte_order(NULL);
118 exif_data_set_byte_order(NULL, EXIF_BYTE_ORDER_MOTOROLA);
120 m = exif_data_get_mnote_data(NULL);
122 fprintf(stderr, "Unexpected success in %s\n", "exif_data_get_mnote_data");
128 exif_data_foreach_content(NULL, NULL, NULL);
130 exif_data_set_option(NULL, EXIF_DATA_OPTION_FOLLOW_SPECIFICATION);
132 exif_data_unset_option(NULL, EXIF_DATA_OPTION_FOLLOW_SPECIFICATION);
134 exif_data_set_data_type(NULL, EXIF_DATA_TYPE_UNCOMPRESSED_CHUNKY);
136 dt = exif_data_get_data_type(NULL);
139 exif_data_load_data(NULL, NULL, 123);
141 exif_data_save_data(NULL, NULL, NULL);
143 exif_data_log(NULL, NULL);
145 exif_data_dump(NULL);
149 exif_data_unref(NULL);
153 fprintf(stderr, "Out of memory\n");
157 exif_data_load_data(d, NULL, 123);
159 exif_data_save_data(d, NULL, &len);
160 exif_data_save_data(d, &buf, NULL);
161 exif_data_save_data(d, NULL, NULL);
163 exif_data_foreach_content(d, NULL, NULL);
165 exif_data_log(d, NULL);
170 static void content_null_test(void)
175 c = exif_content_new_mem(NULL);
177 fprintf(stderr, "Unexpected success in %s\n", "exif_content_new_mem");
181 exif_content_ref(NULL);
183 exif_content_unref(NULL);
185 exif_content_free(NULL);
187 exif_content_get_entry(NULL, EXIF_TAG_COMPRESSION);
189 exif_content_fix(NULL);
191 exif_content_foreach_entry(NULL, NULL, NULL);
193 i = exif_content_get_ifd(NULL);
196 exif_content_dump(NULL, 0);
198 exif_content_add_entry(NULL, NULL);
200 exif_content_remove_entry(NULL, NULL);
202 exif_content_log(NULL, NULL);
204 c = exif_content_new();
206 fprintf(stderr, "Out of memory\n");
210 exif_content_add_entry(c, NULL);
212 exif_content_remove_entry(c, NULL);
214 exif_content_log(c, NULL);
216 exif_content_foreach_entry(c, NULL, NULL);
218 exif_content_unref(c);
221 static void entry_null_test(void)
224 const char *v = NULL;
228 e = exif_entry_new_mem(NULL);
230 fprintf(stderr, "Unexpected success in %s\n", "exif_entry_new_mem");
234 exif_entry_ref(NULL);
236 exif_entry_unref(NULL);
238 exif_entry_free(NULL);
240 exif_entry_initialize(NULL, EXIF_TAG_COMPRESSION);
242 exif_entry_fix(NULL);
244 v = exif_entry_get_value(NULL, NULL, 123);
246 fprintf(stderr, "Unexpected success in %s\n", "exif_entry_get_value");
250 v = exif_entry_get_value(NULL, buf, 1);
252 fprintf(stderr, "Unexpected value in %s\n", "exif_entry_get_value");
256 exif_entry_dump(NULL, 0);
258 /* Creating a plain ExifEntry isn't enough, since some functions require
259 * that it exists in an IFD.
263 fprintf(stderr, "Out of memory\n");
266 /* Create the mandatory EXIF fields so we have something to work with */
268 e = exif_content_get_entry (d->ifd[EXIF_IFD_0], EXIF_TAG_X_RESOLUTION);
270 (void) exif_entry_get_value(e, NULL, 0);
271 (void) exif_entry_get_value(e, NULL, 123);
276 static void mnote_null_test(void)
278 /* Note that these APIs aren't tested with a real ExifMnoteData pointer
279 * because it's impossible to create one without real data.
281 exif_mnote_data_ref(NULL);
283 exif_mnote_data_unref(NULL);
285 exif_mnote_data_load(NULL, NULL, 123);
287 exif_mnote_data_load(NULL, (const unsigned char *)"x", 1);
289 exif_mnote_data_save(NULL, NULL, NULL);
291 exif_mnote_data_count(NULL);
293 exif_mnote_data_get_id(NULL, 0);
295 exif_mnote_data_get_name(NULL, 0);
297 exif_mnote_data_get_title(NULL, 0);
299 exif_mnote_data_get_description(NULL, 0);
301 exif_mnote_data_get_value(NULL, 0, NULL, 123);
303 exif_mnote_data_log(NULL, NULL);
306 static void log_null_test(void)
311 l = exif_log_new_mem(NULL);
313 fprintf(stderr, "Unexpected success in %s\n", "exif_log_new_mem");
319 exif_log_unref(NULL);
323 exif_log_set_func(NULL, NULL, NULL);
325 exif_log(NULL, EXIF_LOG_CODE_CORRUPT_DATA, "XXX", "YYY");
327 exif_logv(NULL, EXIF_LOG_CODE_CORRUPT_DATA, "XXX", "YYY", va);
331 fprintf(stderr, "Out of memory\n");
335 exif_log_set_func(l, NULL, NULL);
349 /* If it gets here, we didn't get a SIGSEGV, so success! */