-
Notifications
You must be signed in to change notification settings - Fork 1.2k
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ato* family of functions does not allow for robust error handling #1358
Comments
Just to note that same applies also for So the only option to check for conversion errors is to use |
It's unnecessary to use atoi in this case. Addresses: #1358 Signed-off-by: Karel Zak <kzak@redhat.com>
old version: # blockdev --setfra 4x096 /dev/sdc new version: # blockdev --setfra 4x096 /dev/sdc blockdev: failed to parse command argument: '4x096' Addresses: #1358 Signed-off-by: Karel Zak <kzak@redhat.com>
* add ul_strtos64() and ul_strtou64() * add simple test Addresses: #1358 Signed-off-by: Karel Zak <kzak@redhat.com>
Addresses: #1358 Signed-off-by: Karel Zak <kzak@redhat.com>
* remove unnecessary strtok() use * remove atoi use() Addresses: #1358 Signed-off-by: Karel Zak <kzak@redhat.com>
Addresses: #1358 Signed-off-by: Karel Zak <kzak@redhat.com>
Addresses: #1358 Signed-off-by: Karel Zak <kzak@redhat.com>
Addresses: #1358 Signed-off-by: Karel Zak <kzak@redhat.com>
Addresses: #1358 Signed-off-by: Karel Zak <kzak@redhat.com>
Addresses: #1358 Signed-off-by: Karel Zak <kzak@redhat.com>
Addresses: #1358 Signed-off-by: Karel Zak <kzak@redhat.com>
Addresses: #1358 Signed-off-by: Karel Zak <kzak@redhat.com>
All the issues should be fixed now. |
There is still one small issue. Parsing number with leading space pass but with trailing fails. I guess that string with leading space should me marked as invalid number too, like string with trailing space. Or is there some specific reason why leading space in number string is accepted?
|
man strtol:
|
IMHO is better to keep the current behavior as it's how we parse user input for years, but not sure why strto* behaves in this way... |
Yes! This is source of that behavior. I know about it. I should have rather asked if it is expected behavior that modules in util-linux also accept these leading spaces when parsing numbers. |
Ok! So this is a good argument... |
It's unnecessary to use atoi in this case. Addresses: #1358 Signed-off-by: Karel Zak <kzak@redhat.com>
old version: # blockdev --setfra 4x096 /dev/sdc new version: # blockdev --setfra 4x096 /dev/sdc blockdev: failed to parse command argument: '4x096' Addresses: #1358 Signed-off-by: Karel Zak <kzak@redhat.com>
* add ul_strtos64() and ul_strtou64() * add simple test Addresses: #1358 Signed-off-by: Karel Zak <kzak@redhat.com>
Addresses: #1358 Signed-off-by: Karel Zak <kzak@redhat.com>
* remove unnecessary strtok() use * remove atoi use() Addresses: #1358 Signed-off-by: Karel Zak <kzak@redhat.com>
Addresses: #1358 Signed-off-by: Karel Zak <kzak@redhat.com>
Addresses: #1358 Signed-off-by: Karel Zak <kzak@redhat.com>
Addresses: #1358 Signed-off-by: Karel Zak <kzak@redhat.com>
Addresses: #1358 Signed-off-by: Karel Zak <kzak@redhat.com>
Addresses: #1358 Signed-off-by: Karel Zak <kzak@redhat.com>
Addresses: #1358 Signed-off-by: Karel Zak <kzak@redhat.com>
Addresses: #1358 Signed-off-by: Karel Zak <kzak@redhat.com>
There are
atoi
andatol
functions used in the util-linux codebase. Unlikestrto*
functions, they do not allow for catching errors properly, distinguishing true zero from error, or values too big.It is possible that some of the uses are in fact fine as the goal is only to see if the value is a number (specifically the first one in cfdisk.c):
https://github.com/karelzak/util-linux/blob/master/disk-utils/cfdisk.c#L1352-L1368
https://github.com/karelzak/util-linux/blob/master/disk-utils/blockdev.c#L354
https://github.com/karelzak/util-linux/blob/master/disk-utils/fsck.c#L1607
https://github.com/karelzak/util-linux/blob/master/login-utils/utmpdump.c#L78
https://github.com/karelzak/util-linux/blob/master/sys-utils/lscpu-topology.c#L193
https://github.com/karelzak/util-linux/blob/master/sys-utils/eject.c#L538
https://github.com/karelzak/util-linux/blob/master/sys-utils/ipcs.c#L123
https://github.com/karelzak/util-linux/blob/master/sys-utils/swapon.c#L731
https://github.com/karelzak/util-linux/blob/master/sys-utils/lscpu-cputype.c#L303
https://github.com/karelzak/util-linux/blob/master/sys-utils/lscpu-cputype.c#L489
https://github.com/karelzak/util-linux/blob/master/text-utils/pg.c#L323-L327
https://github.com/karelzak/util-linux/blob/master/text-utils/pg.c#L602-L605
https://github.com/karelzak/util-linux/blob/master/text-utils/hexdump-parse.c#L136
https://github.com/karelzak/util-linux/blob/master/text-utils/hexdump-parse.c#L153
https://github.com/karelzak/util-linux/blob/master/text-utils/hexdump-parse.c#L203
https://github.com/karelzak/util-linux/blob/master/text-utils/hexdump-parse.c#L272
https://github.com/karelzak/util-linux/blob/master/term-utils/agetty.c#L2427
But if #1356 gets addressed, reviewing the
ato*
usage might also be useful.The text was updated successfully, but these errors were encountered: