Karel Zak wrote:
> On Wed, Feb 25, 2009 at 11:59:33PM +0100, Joel Granados Moreno wrote:
>> +static unsigned int
>> +_device_get_partition_range(PedDevice* dev)
>> +{
>> + int range, r;
>> + char path[128];
>> + FILE* fp;
>> + bool ok;
>> +
>> + r = snprintf(path, sizeof(path), "/sys/block/%s/range",
>> + basename(dev->path));
>
> always _GNU_SOURCE, right? :-)
Good portability catch.
There are actually two uses of basename.
I'll convert them to base_name or last_component
(provided by gnulib's basename module).
>> + if(r < 0 || r > sizeof(path))
>> + return MAX_NUM_PARTS;
>
> if(r < 0 || r >= sizeof(path))
>
> the return value does not including the trailing '\0', see man page:
>
> Thus, a return value of size or more means that the
> output was truncated.
Thanks, Karel.
I've just pushed this:
>From 855941570a4f0f173822e98d8437943c43643b5a Mon Sep 17 00:00:00 2001
From: Karel Zak <[email protected]>
Date: Thu, 5 Mar 2009 18:34:47 +0100
Subject: [PATCH] test correctly for snprintf failure
* libparted/arch/linux.c (_device_get_partition_range): Correct
test for failed snprintf.
---
libparted/arch/linux.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index 724df46..047ed50 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -2279,7 +2279,7 @@ _device_get_partition_range(PedDevice* dev)
r = snprintf(path, sizeof(path), "/sys/block/%s/range",
basename(dev->path));
- if(r < 0 || r > sizeof(path))
+ if(r < 0 || r >= sizeof(path))
return MAX_NUM_PARTS;
fp = fopen(path, "r");
--
1.6.2.rc1.285.gc5f54
_______________________________________________
parted-devel mailing list
[email protected]
http://lists.alioth.debian.org/mailman/listinfo/parted-devel