Signed-off-by: Paul B. Henson <[email protected]>
---
 miscutils/ubi_tools.c |   17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/miscutils/ubi_tools.c b/miscutils/ubi_tools.c
index dd99a44..9e3db1e 100644
--- a/miscutils/ubi_tools.c
+++ b/miscutils/ubi_tools.c
@@ -234,16 +234,23 @@ int ubi_tools_main(int argc UNUSED_PARAM, char **argv)
                        ssize_t len;
                        char *input_data;
 
-                       // Make assumption that device not is in normal format.
-                       // Removes need for scanning sysfs tree as full libubi 
does
-                       if (sscanf(ubi_ctrl, "/dev/ubi%u_%u", &ubinum, &volnum) 
!= 2)
+                       // Make assumption that device node is in normal format
+                       // (/dev/ubi%d_%d), removes need for scanning sysfs
+                       // tree as full libubi does
+                       if (strncmp(ubi_ctrl, "/dev/ubi", 8) != 0 ||
+                           (input_data = strchr(ubi_ctrl+8, '_')) == NULL)
                                bb_error_msg_and_die("%s volume node not in 
correct format", "UBI");
+                       // temporarily tokenize for parsing
+                       *input_data = '\0';
+                       ubinum = xstrtou(ubi_ctrl+8, 10);
+                       volnum = xstrtou(input_data+1, 10);
+                       // restore original string
+                       *input_data = '_';
 
                        sprintf(buf, "/sys/class/ubi/ubi%u_%u/usable_eb_size", 
ubinum, volnum);
                        if (open_read_close(buf, buf, sizeof(buf)) <= 0)
                                bb_error_msg_and_die("%s could not get LEB 
size", "UBI");
-                       if (sscanf(buf, "%u", &leb_size) != 1)
-                               bb_error_msg_and_die("%s could not get LEB 
size", "UBI");
+                       leb_size = xstrtou(buf, 10);
 
                        if (opts & OPTION_s) {
                                input_fd = 0;
-- 
1.7.8.6

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to