[libgepub/wip/hadess/tests-fix-invalid-read: 2/2] tests: Fix "Invalid read of size 1"




commit 9d0137b09779dfbebc229627daec82d76d72316e
Author: Bastien Nocera <hadess hadess net>
Date:   Tue Aug 6 14:43:10 2019 +0200

    tests: Fix "Invalid read of size 1"
    
    The data might not be NULL-terminated, so don't read past the size:
    ==8841== Invalid read of size 1
    ==8841==    at 0x483BBF4: strlen (vg_replace_strmem.c:461)
    ==8841==    by 0x7F5552D: __vfprintf_internal (in /usr/lib64/libc-2.29.so)
    ==8841==    by 0x7F66BC4: __vasprintf_internal (in /usr/lib64/libc-2.29.so)
    ==8841==    by 0x7E5E5AD: g_vasprintf (gprintf.c:330)
    ==8841==    by 0x7E378FF: g_strdup_vprintf (gstrfuncs.c:514)
    ==8841==    by 0x7E3799B: g_strdup_printf (gstrfuncs.c:540)
    ==8841==    by 0x403651: test_doc_resources (test-gepub.c:257)
    ==8841==    by 0x403651: main (test-gepub.c:452)
    ==8841==  Address 0x1d5931ff is 0 bytes after a block of size 3,247 alloc'd
    ==8841==    at 0x483AB1A: calloc (vg_replace_malloc.c:762)
    ==8841==    by 0x7E1E580: g_malloc0 (gmem.c:129)
    ==8841==    by 0x484BDAE: gepub_archive_read_entry (gepub-archive.c:149)
    ==8841==    by 0x484BDAE: gepub_archive_read_entry (gepub-archive.c:132)
    ==8841==    by 0x484C441: gepub_doc_get_resource_by_id (gepub-doc.c:537)
    ==8841==    by 0x403632: test_doc_resources (test-gepub.c:255)
    ==8841==    by 0x403632: main (test-gepub.c:452)

 tests/test-gepub.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
---
diff --git a/tests/test-gepub.c b/tests/test-gepub.c
index 55ab1a2..8949d39 100644
--- a/tests/test-gepub.c
+++ b/tests/test-gepub.c
@@ -254,7 +254,7 @@ test_doc_resources (const char *path)
 
     ncx = gepub_doc_get_resource_by_id (doc, "ncx");
     data = g_bytes_get_data (ncx, &size);
-    PTEST ("ncx:\n%s\n", data);
+    PTEST ("ncx:\n%.*s\n", size, data);
     g_bytes_unref (ncx);
 
     g_object_unref (G_OBJECT (doc));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]