[Spice-devel] [PATCH 03/12] Add error checking to vcard_emul_options

marcandre.lureau at redhat.com marcandre.lureau at redhat.com
Thu Oct 8 08:40:32 PDT 2015


From: Jeremy White <jwhite at codeweavers.com>

Also add an alias of 'nssemul' for the default card
of hw=yes hw_type=cac, and an alias of 'passthru' for
the new card type of hw=yes hw_type=passthru.

This allows the spice-gtk client to take a more human
friendly set of arguments and relay them through to this code.

Signed-off-by: Jeremy White <jwhite at codeweavers.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau at redhat.com>
---
 src/vcard_emul_nss.c | 39 ++++++++++++++++++++++++++++-----------
 1 file changed, 28 insertions(+), 11 deletions(-)

diff --git a/src/vcard_emul_nss.c b/src/vcard_emul_nss.c
index 2f95f03..7ffa0b4 100644
--- a/src/vcard_emul_nss.c
+++ b/src/vcard_emul_nss.c
@@ -1116,17 +1116,13 @@ static VCardEmulOptions options;
  * and its length in "token_length". "token" will not be nul-terminated.
  * After calling the macro, "args" will be advanced to the beginning of
  * the next token.
- * This macro may call continue or break.
  */
 #define NEXT_TOKEN(token) \
             (token) = args; \
             args = strpbrk(args, ",)"); \
-            if (*args == 0) { \
-                break; \
-            } \
-            if (*args == ')') { \
-                args++; \
-                continue; \
+            if (*args == 0 || *args == ')') { \
+                fprintf(stderr, "Error: invalid soft specification.\n"); \
+                return NULL; \
             } \
             (token##_length) = args - (token); \
             args = strip(args+1);
@@ -1144,6 +1140,7 @@ vcard_emul_options(const char *args)
     do {
         args = strip(args); /* strip off the leading spaces */
         if (*args == ',') {
+            args++;
             continue;
         }
         /* soft=(slot_name,virt_name,emul_type,emul_flags,cert_1, (no eol)
@@ -1162,7 +1159,8 @@ vcard_emul_options(const char *args)
 
             args = strip(args + 5);
             if (*args != '(') {
-                continue;
+                fprintf(stderr, "Error: invalid soft specification.\n");
+                return NULL;
             }
             args = strip(args+1);
 
@@ -1173,11 +1171,17 @@ vcard_emul_options(const char *args)
             memcpy(type_str, type_params, type_params_length);
             type_str[type_params_length] = '\0';
             type = vcard_emul_type_from_string(type_str);
+            if (type == VCARD_EMUL_NONE) {
+                fprintf(stderr, "Error: invalid smartcard type '%s'.\n",
+                        type_str);
+                return NULL;
+            }
 
             NEXT_TOKEN(type_params)
 
             if (*args == 0) {
-                break;
+                fprintf(stderr, "Error: missing cert specification.\n");
+                return NULL;
             }
 
             if (opts->vreader_count >= reader_count) {
@@ -1217,6 +1221,11 @@ vcard_emul_options(const char *args)
         } else if (strncmp(args, "hw_type=", 8) == 0) {
             args = strip(args+8);
             opts->hw_card_type = vcard_emul_type_from_string(args);
+            if (opts->hw_card_type == VCARD_EMUL_NONE) {
+                fprintf(stderr, "Error: invalid smartcard type '%s'.\n",
+                        args);
+                return NULL;
+            }
             args = find_blank(args);
         /* hw_params= */
         } else if (strncmp(args, "hw_params=", 10) == 0) {
@@ -1230,7 +1239,8 @@ vcard_emul_options(const char *args)
             const char *db;
             args = strip(args+3);
             if (*args != '"') {
-                continue;
+                fprintf(stderr, "Error: you must quote the file path.\n");
+                return NULL;
             }
             args++;
             db = args;
@@ -1239,8 +1249,14 @@ vcard_emul_options(const char *args)
             if (*args != 0) {
                 args++;
             }
+        } else if (strncmp(args, "nssemul", 7) == 0) {
+            opts->hw_card_type = VCARD_EMUL_CAC;
+            opts->use_hw = PR_TRUE;
+            args = find_blank(args + 7);
+        /* nssemul */
         } else {
-            args = find_blank(args);
+            fprintf(stderr, "Error: Unknown smartcard specification.\n");
+            return NULL;
         }
     } while (*args != 0);
 
@@ -1256,6 +1272,7 @@ vcard_emul_usage(void)
 " use_hw=[yes|no]                 (default yes)\n"
 " hw_type={card_type_to_emulate}  (default CAC)\n"
 " hw_param={param_for_card}       (default \"\")\n"
+" nssemul                         (alias for use_hw=yes, hw_type=CAC)\n"
 " soft=({slot_name},{vreader_name},{card_type_to_emulate},{params_for_card},\n"
 "       {cert1},{cert2},{cert3}    (default none)\n"
 "\n"
-- 
2.4.3



More information about the Spice-devel mailing list