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)
37 l = exif_loader_new_mem(NULL);
39 fprintf(stderr, "Unexpected success in %s\n", "exif_loader_new_mem");
43 exif_loader_ref(NULL);
45 exif_loader_unref(NULL);
47 exif_loader_write_file(NULL, "test");
49 exif_loader_write_file(NULL, NULL);
51 ret = exif_loader_write(NULL, (unsigned char *)"x", 1);
53 fprintf(stderr, "Unexpected success in %s\n", "exif_loader_write");
57 exif_loader_write(NULL, NULL, 123);
59 exif_loader_reset(NULL);
61 d = exif_loader_get_data(NULL);
63 fprintf(stderr, "Unexpected success in %s\n", "exif_loader_get_data");
67 exif_loader_get_buf(NULL, NULL, NULL);
69 exif_loader_log(NULL, NULL);
72 static void data_null_test(void)
74 /* exif_data_new_from_file() is untested since it doesn't check path */
83 d = exif_data_new_mem(NULL);
85 fprintf(stderr, "Unexpected success in %s\n", "exif_data_new_mem");
89 d = exif_data_new_from_data(NULL, 123);
94 bo = exif_data_get_byte_order(NULL);
97 exif_data_set_byte_order(NULL, EXIF_BYTE_ORDER_MOTOROLA);
99 m = exif_data_get_mnote_data(NULL);
101 fprintf(stderr, "Unexpected success in %s\n", "exif_data_get_mnote_data");
107 exif_data_foreach_content(NULL, NULL, NULL);
109 exif_data_set_option(NULL, EXIF_DATA_OPTION_FOLLOW_SPECIFICATION);
111 exif_data_unset_option(NULL, EXIF_DATA_OPTION_FOLLOW_SPECIFICATION);
113 exif_data_set_data_type(NULL, EXIF_DATA_TYPE_UNCOMPRESSED_CHUNKY);
115 dt = exif_data_get_data_type(NULL);
118 exif_data_dump(NULL);
122 exif_data_unref(NULL);
126 fprintf(stderr, "Out of memory\n");
130 exif_data_load_data(NULL, NULL, 123);
131 exif_data_load_data(d, NULL, 123);
133 exif_data_save_data(NULL, NULL, NULL);
134 exif_data_save_data(d, NULL, &len);
135 exif_data_save_data(d, &buf, NULL);
136 exif_data_save_data(d, NULL, NULL);
138 exif_data_log(NULL, NULL);
139 exif_data_log(d, NULL);
144 static void content_null_test(void)
149 c = exif_content_new_mem(NULL);
151 fprintf(stderr, "Unexpected success in %s\n", "exif_content_new_mem");
155 exif_content_ref(NULL);
157 exif_content_unref(NULL);
159 exif_content_free(NULL);
161 exif_content_get_entry(NULL, EXIF_TAG_COMPRESSION);
163 exif_content_fix(NULL);
165 exif_content_foreach_entry(NULL, NULL, NULL);
167 i = exif_content_get_ifd(NULL);
170 exif_content_dump(NULL, 0);
172 c = exif_content_new();
174 fprintf(stderr, "Out of memory\n");
178 exif_content_add_entry(c, NULL);
180 exif_content_add_entry(NULL, NULL);
182 exif_content_remove_entry(c, NULL);
183 exif_content_remove_entry(NULL, NULL);
185 exif_content_log(c, NULL);
187 exif_content_log(NULL, NULL);
189 exif_content_unref(c);
192 static void entry_null_test(void)
195 const char *v = NULL;
198 e = exif_entry_new_mem(NULL);
200 fprintf(stderr, "Unexpected success in %s\n", "exif_entry_new_mem");
204 exif_entry_ref(NULL);
206 exif_entry_unref(NULL);
208 exif_entry_free(NULL);
210 exif_entry_initialize(NULL, EXIF_TAG_COMPRESSION);
212 exif_entry_fix(NULL);
214 v = exif_entry_get_value(NULL, NULL, 123);
216 fprintf(stderr, "Unexpected success in %s\n", "exif_entry_get_value");
220 v = exif_entry_get_value(NULL, buf, 1);
222 fprintf(stderr, "Unexpected value in %s\n", "exif_entry_get_value");
226 exif_entry_dump(NULL, 0);
229 static void mnote_null_test(void)
231 /* Note that these APIs aren't tested with a real ExifMnoteData pointer
232 * because it's impossible to create one without real data.
234 exif_mnote_data_ref(NULL);
236 exif_mnote_data_unref(NULL);
238 exif_mnote_data_load(NULL, NULL, 123);
240 exif_mnote_data_load(NULL, (const unsigned char *)"x", 1);
242 exif_mnote_data_save(NULL, NULL, NULL);
244 exif_mnote_data_count(NULL);
246 exif_mnote_data_get_id(NULL, 0);
248 exif_mnote_data_get_name(NULL, 0);
250 exif_mnote_data_get_title(NULL, 0);
252 exif_mnote_data_get_description(NULL, 0);
254 exif_mnote_data_get_value(NULL, 0, NULL, 123);
256 exif_mnote_data_log(NULL, NULL);
259 static void log_null_test(void)
264 l = exif_log_new_mem(NULL);
266 fprintf(stderr, "Unexpected success in %s\n", "exif_log_new_mem");
272 exif_log_unref(NULL);
276 exif_log_set_func(NULL, NULL, NULL);
278 exif_log(NULL, EXIF_LOG_CODE_CORRUPT_DATA, "XXX", "YYY");
280 exif_logv(NULL, EXIF_LOG_CODE_CORRUPT_DATA, "XXX", "YYY", va);
292 /* If it gets here, we didn't get a SIGSEGV, so success! */