vsscanf do not convert hex numbers starting with a non-digit

vsscanf do not convert hex numbers starting with a non-digit

Post by Torsten Foertsc » Wed, 12 Mar 2003 13:10:08



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

I found the following little bug in 2.4.19. I did not try newer kernels.

vsscanf refuses to convert a hex number starting with a nondecimal digit like:

char *buf="ff";
unsigned ff=0;
sscanf( buf, "%x", &ff );      /* fails: nothing is converted */

Here is a patch that corrects that behaviour:

- --- linux/lib/vsprintf.c        2001-10-11 20:17:22.000000000 +0200

                while (isspace(*str))
                        str++;

- -               if (!*str || !isdigit(*str))
+               if (!*str || !(isdigit(*str) || (base==16 && isxdigit(*str))))
                        break;

                switch(qualifier) {

Torsten
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE+bcI7wicyCTir8T4RAgsPAKCZtX+R9tljalegoC4z7xbTo3p38ACfUIYv
5xgo+tQqj8TZmQOM4W0MqqY=
=D9hc
-----END PGP SIGNATURE-----
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

vsscanf do not convert hex numbers starting with a non-digit

Post by Marc-Christian Peterse » Wed, 12 Mar 2003 13:40:08



Hi Torsten,

> I found the following little bug in 2.4.19. I did not try newer kernels.
> vsscanf refuses to convert a hex number starting with a nondecimal digit
> like:
> char *buf="ff";
> unsigned ff=0;
> sscanf( buf, "%x", &ff );      /* fails: nothing is converted */

> Here is a patch that corrects that behaviour:

> --- linux/lib/vsprintf.c        2001-10-11 20:17:22.000000000 +0200
> +++ linux.patched/lib/vsprintf.c        2003-03-11 11:52:08.000000000 +0100

>                 while (isspace(*str))
>                         str++;

> -               if (!*str || !isdigit(*str))
> +               if (!*str || !(isdigit(*str) || (base==16 &&
> isxdigit(*str)))) break;

>                 switch(qualifier) {

http://marc.theaimsgroup.com/?l=linux-kernel&m=104687957102846&w=2

This fix was first posted since early 2.4.18-pre stage.

ciao, Marc

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

1. sscanf()/vsscanf() isn't able to handle Hex digits

Hi,

I'm using kernel 2.4.18-pre9.

I want to parse a mac adress within a kernel module. I want to
use int sscanf(const char *buf, const char *fmt, ...) .

This function is located in /usr/src/linux/lib/vsprintf.c .

Mac addresses like 6f:6f:7f:9a:10:11 are parsed correctly,
fd:23:22:fd:df:77 fails.

The reason is located in vsprintf.c line 640:

if (!*str || !isdigit(*str))
        break;

I think isxdigit(*str) might be better here.

bye
--
May the source be with you!
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

2. How do i Question - Root Password Forgotten

3. 2.4.20: lib/vsprintf.c: Fix vsscanf of hex digits

4. relay sendmail

5. Help with X windows

6. How to find the what number is missing in Sequence of 19 or 20 digit number.

7. Root: console vs. su

8. validating delimiter in 6 pairs of hex digits

9. Random 2 digit hex output

10. convert week number to week starting date

11. changing one-digit month/day strings to two digits

12. PPP WITH A 10 DIGIT NUMBER!