handle non-0 terminated value returns as failure
[platform/upstream/libexif.git] / test / test-fuzzer.c
index 101fa27..2af7288 100644 (file)
 void content_foreach_func(ExifEntry *entry, void *callback_data);
 void content_foreach_func(ExifEntry *entry, void *UNUSED(callback_data))
 {
-       char buf[2000];
+       char buf[2001];
 
-       exif_entry_get_value(entry, buf, sizeof(buf));
+       /* ensure \0 */
+       buf[sizeof(buf)-1] = 0;
+       buf[sizeof(buf)-2] = 0;
+       exif_entry_get_value(entry, buf, sizeof(buf)-1);
        printf("    Entry %p: %s (%s)\n"
                 "      Size, Comps: %d, %d\n"
                 "      Value: %s\n", 
@@ -45,7 +48,8 @@ void content_foreach_func(ExifEntry *entry, void *UNUSED(callback_data))
                 exif_format_get_name(entry->format),
                 entry->size,
                 (int)(entry->components),
-                exif_entry_get_value(entry, buf, sizeof(buf)));
+                exif_entry_get_value(entry, buf, sizeof(buf)-1));
+       if (buf[sizeof(buf)-2] != 0) abort();
 }
 
 
@@ -77,6 +81,8 @@ test_exif_data (ExifData *d)
 
        c = exif_mnote_data_count (md);
        for (i = 0; i < c; i++) {
+               char *name = exif_mnote_data_get_name (md, i);
+               if (!name) break;
                fprintf (stdout, "Dumping entry number %i...\n", i);
                fprintf (stdout, "  Name: '%s'\n",
                                exif_mnote_data_get_name (md, i));