summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Crispin <blogic@openwrt.org>2014-08-24 21:13:38 +0200
committerJohn Crispin <blogic@openwrt.org>2014-08-24 21:13:38 +0200
commit7f620b45fedfa4bde2f75f9bb9ced49272d1a5d1 (patch)
treef0452c72e48eca14685b2e3940605883950126ed
parentd16d0d2a487687ff38c3b7b5fc530d660b1d85cc (diff)
sanitize pincode properly
Signed-off-by: John Crispin <blogic@openwrt.org>
-rw-r--r--cli.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/cli.c b/cli.c
index 1f043d5..86fe726 100644
--- a/cli.c
+++ b/cli.c
@@ -24,6 +24,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <ctype.h>
#include <libubox/utils.h>
#include <libubox/uloop.h>
@@ -335,6 +336,24 @@ mbim_disconnect_request(void)
return mbim_send_command_msg();
}
+static char*
+mbim_pin_sanitize(char *pin)
+{
+ char *p;
+
+ while (*pin && !isdigit(*pin))
+ pin++;
+ p = pin;
+ if (!*p)
+ return NULL;
+ while (*pin && isdigit(*pin))
+ pin++;
+ if (*pin)
+ *pin = '\0';
+
+ return p;
+}
+
static int
mbim_pin_unlock_request(void)
{
@@ -342,6 +361,12 @@ mbim_pin_unlock_request(void)
(struct mbim_basic_connect_pin_s *) mbim_setup_command_msg(basic_connect,
MBIM_MESSAGE_COMMAND_TYPE_SET, MBIM_CMD_BASIC_CONNECT_PIN,
sizeof(struct mbim_basic_connect_pin_s));
+ char *pin = mbim_pin_sanitize(_argv[0]);
+
+ if (!pin || !strlen(pin)) {
+ fprintf(stderr, "failed to sanitize the pincode\n");
+ return -1;
+ }
p->pintype = htole32(MBIM_PIN_TYPE_PIN1);
p->pinoperation = htole32(MBIM_PIN_OPERATION_ENTER);