* [linux-lvm] [PATCH] dmsetup: fix sscanf return check
@ 2012-08-23 13:31 Matthew Booth
2012-08-23 20:01 ` Mark van Dijk
2012-08-23 20:27 ` Alasdair G Kergon
0 siblings, 2 replies; 4+ messages in thread
From: Matthew Booth @ 2012-08-23 13:31 UTC (permalink / raw)
To: linux-lvm
---
tools/dmsetup.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/tools/dmsetup.c b/tools/dmsetup.c
index 0ac970f..65d17f8 100644
--- a/tools/dmsetup.c
+++ b/tools/dmsetup.c
@@ -228,8 +228,7 @@ static int _parse_line(struct dm_task *dmt, char *buffer, const char *file,
if (!*ptr || *ptr == '#')
return 1;
- if (sscanf(ptr, "%llu %llu %s %n",
- &start, &size, ttype, &n) < 3) {
+ if (sscanf(ptr, "%llu %llu %s %n", &start, &size, ttype, &n) != 4) {
err("Invalid format on line %d of table %s", line, file);
return 0;
}
--
1.7.11.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [linux-lvm] [PATCH] dmsetup: fix sscanf return check
2012-08-23 13:31 [linux-lvm] [PATCH] dmsetup: fix sscanf return check Matthew Booth
@ 2012-08-23 20:01 ` Mark van Dijk
2012-08-23 20:27 ` Alasdair G Kergon
1 sibling, 0 replies; 4+ messages in thread
From: Mark van Dijk @ 2012-08-23 20:01 UTC (permalink / raw)
To: LVM general discussion and development; +Cc: mbooth
On Thu, 23 Aug 2012 14:31:02 +0100
Matthew Booth <mbooth@redhat.com> wrote:
> ---
> tools/dmsetup.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/tools/dmsetup.c b/tools/dmsetup.c
> index 0ac970f..65d17f8 100644
> --- a/tools/dmsetup.c
> +++ b/tools/dmsetup.c
> @@ -228,8 +228,7 @@ static int _parse_line(struct dm_task *dmt, char
> *buffer, const char *file, if (!*ptr || *ptr == '#')
> return 1;
>
> - if (sscanf(ptr, "%llu %llu %s %n",
> - &start, &size, ttype, &n) < 3) {
> + if (sscanf(ptr, "%llu %llu %s %n", &start, &size, ttype,
> &n) != 4) { err("Invalid format on line %d of table %s", line, file);
> return 0;
> }
Ah. For non-coders like myself the purpose of this patch seems to be
clouded in mystery...
--
Stay in touch,
Mark van Dijk. ,------------------------------------
-------------------------------' Thu Aug 23 20:00 UTC 2012
Today is Setting Orange, the 16th day of Bureaucracy in the YOLD 3178
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [linux-lvm] [PATCH] dmsetup: fix sscanf return check
2012-08-23 13:31 [linux-lvm] [PATCH] dmsetup: fix sscanf return check Matthew Booth
2012-08-23 20:01 ` Mark van Dijk
@ 2012-08-23 20:27 ` Alasdair G Kergon
2012-08-24 8:46 ` Matthew Booth
1 sibling, 1 reply; 4+ messages in thread
From: Alasdair G Kergon @ 2012-08-23 20:27 UTC (permalink / raw)
To: Matthew Booth; +Cc: linux-lvm
On Thu, Aug 23, 2012 at 02:31:02PM +0100, Matthew Booth wrote:
> - if (sscanf(ptr, "%llu %llu %s %n",
> - &start, &size, ttype, &n) < 3) {
> + if (sscanf(ptr, "%llu %llu %s %n", &start, &size, ttype, &n) != 4) {
Did you test this?
According to the sscanf man page:
n Nothing is expected; instead, the number of characters consumed
thus far from the input is stored through the next pointer,
which must be a pointer to int. This is not a conversion,
although it can be suppressed with the * assignment-suppression
character. The C standard says: "Execution of a %n directive
does not increment the assignment count returned at the comple-
tion of execution" but the Corrigendum seems to contradict this.
Probably it is wise not to make any assumptions on the effect of
%n conversions on the return value.
Alasdair
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [linux-lvm] [PATCH] dmsetup: fix sscanf return check
2012-08-23 20:27 ` Alasdair G Kergon
@ 2012-08-24 8:46 ` Matthew Booth
0 siblings, 0 replies; 4+ messages in thread
From: Matthew Booth @ 2012-08-24 8:46 UTC (permalink / raw)
To: linux-lvm
On 23/08/12 21:27, Alasdair G Kergon wrote:
> On Thu, Aug 23, 2012 at 02:31:02PM +0100, Matthew Booth wrote:
>> - if (sscanf(ptr, "%llu %llu %s %n",
>> - &start, &size, ttype, &n) < 3) {
>> + if (sscanf(ptr, "%llu %llu %s %n", &start, &size, ttype, &n) != 4) {
>
> Did you test this?
No. My git-fu isn't good enough to point that out in the email without
cluttering the commit message with it, but I pointed it out on IRC.
> According to the sscanf man page:
>
> n Nothing is expected; instead, the number of characters consumed
> thus far from the input is stored through the next pointer,
> which must be a pointer to int. This is not a conversion,
> although it can be suppressed with the * assignment-suppression
> character. The C standard says: "Execution of a %n directive
> does not increment the assignment count returned at the comple-
> tion of execution" but the Corrigendum seems to contradict this.
> Probably it is wise not to make any assumptions on the effect of
> %n conversions on the return value.
Thanks for being thorough. I've now made another entry in my mental list
of surprising interfaces :)
Matt
--
Matthew Booth, RHCA, RHCSS
Red Hat Engineering, Virtualisation Team
GPG ID: D33C3490
GPG FPR: 3733 612D 2D05 5458 8A8A 1600 3441 EA19 D33C 3490
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-08-24 8:46 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-23 13:31 [linux-lvm] [PATCH] dmsetup: fix sscanf return check Matthew Booth
2012-08-23 20:01 ` Mark van Dijk
2012-08-23 20:27 ` Alasdair G Kergon
2012-08-24 8:46 ` Matthew Booth
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).