From 0ce8e1b704b22d218d98524addcb59f466544fda Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Wed, 24 Jul 2013 20:10:09 +0200 Subject: [PATCH] block: use dynamically sized probe buffer in libblkid-tiny This fixes label extraction on vfat partitions with large cluster sizes, the previous statically sized buffer of 4096 bytes was too small. --- libblkid-tiny/libblkid-tiny.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/libblkid-tiny/libblkid-tiny.c b/libblkid-tiny/libblkid-tiny.c index bd86c41..623ef69 100644 --- a/libblkid-tiny/libblkid-tiny.c +++ b/libblkid-tiny/libblkid-tiny.c @@ -13,6 +13,7 @@ int blkid_debug_mask = 0; static unsigned char *probe_buffer; +static unsigned int probe_buffer_size = 0; int get_linux_version (void) { @@ -80,17 +81,24 @@ unsigned char *blkid_probe_get_buffer(blkid_probe pr, blkid_loff_t off, blkid_loff_t len) { int ret; + unsigned char *buf; - if (len > 4096) { - fprintf(stderr, "probe buffer too small %d\n", (int) len); - return NULL; - } + if (len > probe_buffer_size) { + buf = realloc(probe_buffer, len); + + if (!buf) { + fprintf(stderr, "failed to allocate %d byte buffer\n", + (int)len); - if (!probe_buffer) { - probe_buffer = malloc(4096); - memset(probe_buffer, 0, 4096); + return NULL; + } + + probe_buffer = buf; + probe_buffer_size = len; } + memset(probe_buffer, 0, probe_buffer_size); + lseek(pr->fd, off, SEEK_SET); ret = read(pr->fd, probe_buffer, len); -- 2.25.1