dmsetup: fix sscanf return check
PATCH 1/1 dmsetup: fix sscanf return check
--- tools/dmsetup.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
tools/dmsetup.c +1 -2
@@ -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 ; }
Signature · 1 line
1.7.11.4
Quoted 9 lines · On Thu, 23 Aug 2012 14:31:02 +0100 Matthew Booth <[email protected]> wrote:
--- tools/dmsetup.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)tools/dmsetup.c +0
-0
tools/dmsetup.c static int _parse_line(struct dm_task *dmt, char · line 234
Quoted 9 lines
tools/dmsetup.c +1
-2@@ -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...
Signature · 4 lines
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
tools/dmsetup.c static int _parse_line(struct dm_task *dmt, char *buffer, const char *file, · line 231
Quoted 3 lines · Matthew Booth
tools/dmsetup.c +1
-2-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
Quoted 6 lines · Alasdair G Kergon
tools/dmsetup.c static int _parse_line(struct dm_task *dmt, char *buffer, const char *file, · line 231
Quoted 3 lines · Matthew Booth
tools/dmsetup.c +1
-2-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.
Quoted 11 lines
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
Signature · 5 lines
Matthew Booth, RHCA, RHCSS Red Hat Engineering, Virtualisation Team GPG ID: D33C3490 GPG FPR: 3733 612D 2D05 5458 8A8A 1600 3441 EA19 D33C 3490