fix error code
[oweals/openssl.git] / crypto / engine / eng_ctrl.c
index d9104d3b0a1e07e4b9a315bb230861a36125d0ed..5ce25d92ec9518508b9e7c3734bf1b59ae8fcc63 100644 (file)
  *
  */
 
-#include <openssl/crypto.h>
-#include "cryptlib.h"
 #include "eng_int.h"
-#include <openssl/engine.h>
 
 /* When querying a ENGINE-specific control command's 'description', this string
  * is used if the ENGINE_CMD_DEFN has cmd_desc set to NULL. */
@@ -103,7 +100,8 @@ static int int_ctrl_cmd_by_num(const ENGINE_CMD_DEFN *defn, unsigned int num)
        return -1;
        }
 
-static int int_ctrl_helper(ENGINE *e, int cmd, long i, void *p, void (*f)())
+static int int_ctrl_helper(ENGINE *e, int cmd, long i, void *p,
+                          void (*f)(void))
        {
        int idx;
        char *s = (char *)p;
@@ -160,15 +158,19 @@ static int int_ctrl_helper(ENGINE *e, int cmd, long i, void *p, void (*f)())
        case ENGINE_CTRL_GET_NAME_LEN_FROM_CMD:
                return strlen(e->cmd_defns[idx].cmd_name);
        case ENGINE_CTRL_GET_NAME_FROM_CMD:
-               return sprintf(s, "%s", e->cmd_defns[idx].cmd_name);
+               return BIO_snprintf(s,strlen(e->cmd_defns[idx].cmd_name) + 1,
+                                   "%s", e->cmd_defns[idx].cmd_name);
        case ENGINE_CTRL_GET_DESC_LEN_FROM_CMD:
                if(e->cmd_defns[idx].cmd_desc)
                        return strlen(e->cmd_defns[idx].cmd_desc);
                return strlen(int_no_description);
        case ENGINE_CTRL_GET_DESC_FROM_CMD:
                if(e->cmd_defns[idx].cmd_desc)
-                       return sprintf(s, "%s", e->cmd_defns[idx].cmd_desc);
-               return sprintf(s, "%s", int_no_description);
+                       return BIO_snprintf(s,
+                                           strlen(e->cmd_defns[idx].cmd_desc) + 1,
+                                           "%s", e->cmd_defns[idx].cmd_desc);
+               return BIO_snprintf(s, strlen(int_no_description) + 1,"%s",
+                                   int_no_description);
        case ENGINE_CTRL_GET_CMD_FLAGS:
                return e->cmd_defns[idx].cmd_flags;
                }
@@ -253,7 +255,7 @@ int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name,
 
        if((e == NULL) || (cmd_name == NULL))
                {
-               ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
+               ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD,
                        ERR_R_PASSED_NULL_PARAMETER);
                return 0;
                }
@@ -278,7 +280,7 @@ int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name,
                }
        /* Force the result of the control command to 0 or 1, for the reasons
         * mentioned before. */
-        if (ENGINE_ctrl(e, num, i, p, f))
+        if (ENGINE_ctrl(e, num, i, p, f) > 0)
                 return 1;
         return 0;
         }
@@ -343,7 +345,7 @@ int ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg,
                 * usage of these commands is consistent across applications and
                 * that certain applications don't understand it one way, and
                 * others another. */
-               if(ENGINE_ctrl(e, num, 0, (void *)arg, NULL))
+               if(ENGINE_ctrl(e, num, 0, (void *)arg, NULL) > 0)
                        return 1;
                return 0;
                }
@@ -358,7 +360,7 @@ int ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg,
        if(flags & ENGINE_CMD_FLAG_STRING)
                {
                /* Same explanation as above */
-               if(ENGINE_ctrl(e, num, 0, (void *)arg, NULL))
+               if(ENGINE_ctrl(e, num, 0, (void *)arg, NULL) > 0)
                        return 1;
                return 0;
                }
@@ -381,7 +383,7 @@ int ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg,
                }
        /* Force the result of the control command to 0 or 1, for the reasons
         * mentioned before. */
-       if(ENGINE_ctrl(e, num, l, NULL, NULL))
+       if(ENGINE_ctrl(e, num, l, NULL, NULL) > 0)
                return 1;
        return 0;
        }