[Pkg-privacy-commits] [irssi-plugin-otr] 162/267: Fix: otr auth command secret extraction

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 12:41:38 UTC 2015


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch debian
in repository irssi-plugin-otr.

commit 5909f2a188a2303c08e80e42b973c8dc91cf2a6c
Author: David Goulet <dgoulet at ev0ke.net>
Date:   Sat Dec 1 20:41:57 2012 -0500

    Fix: otr auth command secret extraction
    
    Signed-off-by: David Goulet <dgoulet at ev0ke.net>
---
 src/cmd.c   | 13 ++++++-------
 src/utils.c | 38 ++++++++++++++++++++++++++++++++++++++
 src/utils.h |  1 +
 3 files changed, 45 insertions(+), 7 deletions(-)

diff --git a/src/cmd.c b/src/cmd.c
index 1702b75..cffd1d0 100644
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -188,8 +188,8 @@ end:
 static void _cmd_auth(struct otr_user_state *ustate, SERVER_REC *irssi,
 		const char *target, const void *data)
 {
-	int argc;
-	char **argv;
+	int ret;
+	char *secret = NULL;
 
 	if (!irssi || !target) {
 		IRSSI_WARN(irssi, target,
@@ -198,17 +198,16 @@ static void _cmd_auth(struct otr_user_state *ustate, SERVER_REC *irssi,
 		goto error;
 	}
 
-	utils_explode_args(data, &argv, &argc);
-
-	if (argc == 0) {
+	ret = utils_auth_extract_secret(data, &secret);
+	if (ret < 0) {
 		IRSSI_NOTICE(irssi, target, "Huh... I need a secret here James.");
 		goto end;
 	}
 
-	otr_auth(irssi, target, NULL, argv[0]);
+	otr_auth(irssi, target, NULL, secret);
+	free(secret);
 
 end:
-	utils_free_args(&argv, argc);
 error:
 	return;
 }
diff --git a/src/utils.c b/src/utils.c
index 43b331d..35b221b 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -139,6 +139,44 @@ error:
 	return -1;
 }
 
+/*
+ * Extract the secret from an auth otr command. The secret can have more than
+ * one words so this is more efficient than exploding all args and
+ * concatenating them.
+ *
+ * Return 0 and set secret on success or else return negative value an secret
+ * is untouched.
+ */
+int utils_auth_extract_secret(const char *_data, char **secret)
+{
+	char *s, *data = NULL, *cmd_offset = NULL;
+
+	if (!_data || !secret) {
+		goto error;
+	}
+
+	data = strndup(_data, strlen(_data));
+	if (!data) {
+		goto error;
+	}
+
+	s = utils_trim_string(data);
+
+	cmd_offset = strchr(s, ' ');
+	if (!cmd_offset) {
+		goto error;
+	}
+
+	s = utils_trim_string(cmd_offset);
+	*secret = s;
+
+	return 0;
+
+error:
+	free(data);
+	return -1;
+}
+
 void utils_explode_args(const char *_data, char ***_argv, int *_argc)
 {
 	int argc = 0, i = 0, have_arg = 0;
diff --git a/src/utils.h b/src/utils.h
index ef48e24..019e399 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -26,6 +26,7 @@ void utils_extract_command(const char *data, char **_cmd);
 void utils_explode_args(const char *_data, char ***_argv, int *_argc);
 int utils_io_extract_smp(const char *data, char **question, char **secret);
 void utils_string_to_upper(char *string);
+int utils_auth_extract_secret(const char *_data, char **secret);
 void utils_hash_parts_to_readable_hash(const char **parts, char *dst);
 
 #endif /* IRSSI_OTR_UTILS_H */

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/irssi-plugin-otr.git



More information about the Pkg-privacy-commits mailing list