[Pkg-privacy-commits] [irssi-plugin-otr] 148/267: Add fingerprint encrypted msgstate check function
Ximin Luo
infinity0 at moszumanska.debian.org
Sat Aug 22 12:41:37 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 fc048b5f442d05d6315ff20bbf97a825ae506a4f
Author: David Goulet <dgoulet at ev0ke.net>
Date: Mon Nov 26 15:53:21 2012 -0500
Add fingerprint encrypted msgstate check function
This new function checks if one of the fingerprint's context(es) is in
the encrypted state.
Also fix a bad assignment when allocating the peer otr context.
This commit fixes an issue with the otr forget command that was using
the master context thus always having a plaintext state.
There is also a NULL check added to the otr contexts command so we don't
deref. a NULL pointer.
Signed-off-by: David Goulet <dgoulet at ev0ke.net>
---
src/cmd.c | 5 +++++
src/otr.c | 42 +++++++++++++++++++++++++++++++++++-------
2 files changed, 40 insertions(+), 7 deletions(-)
diff --git a/src/cmd.c b/src/cmd.c
index 87198aa..7a8037a 100644
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -235,6 +235,10 @@ static void _cmd_contexts(struct otr_user_state *ustate, SERVER_REC *irssi,
while (ctxlist) {
fplist = ctxlist->fplist;
+ if (!fplist) {
+ goto cleanup;
+ }
+
switch (ctxlist->state) {
case STENCRYPTED:
IRSSI_MSG("%9%s%9 - %B%s%n - %GEncrypted%n", ctxlist->accountname,
@@ -269,6 +273,7 @@ static void _cmd_contexts(struct otr_user_state *ustate, SERVER_REC *irssi,
ctxlist = ctxlist->next;
}
+cleanup:
while ((ctxlist = ctxnext)) {
ctxnext = ctxlist->next;
fpnext = ctxlist->fplist;
diff --git a/src/otr.c b/src/otr.c
index 52bc4ce..06575fe 100644
--- a/src/otr.c
+++ b/src/otr.c
@@ -119,7 +119,7 @@ static void add_peer_context_cb(void *data, ConnContext *context)
return;
}
- context->active_fingerprint = context->active_fingerprint;
+ opc->active_fingerprint = context->active_fingerprint;
context->app_data = opc;
context->app_data_free = destroy_peer_context_cb;
@@ -175,6 +175,33 @@ error:
}
/*
+ * Check if fingerprint is in an encrypted context.
+ *
+ * Return 1 if it does, else 0.
+ */
+static int check_fp_encrypted_msgstate(Fingerprint *fp)
+{
+ int ret;
+ ConnContext *context;
+
+ assert(fp);
+
+ /* Loop on all fingerprint's context(es). */
+ for (context = fp->context; context != NULL; context = context->next) {
+ if (context->msgstate == OTRL_MSGSTATE_ENCRYPTED) {
+ ret = 1;
+ goto end;
+ }
+ }
+
+ /* No state is in an encrypted state. */
+ ret = 0;
+
+end:
+ return ret;
+}
+
+/*
* Get a context from a pair.
*/
ConnContext *otr_find_context(SERVER_REC *irssi, const char *nick, int create)
@@ -452,7 +479,7 @@ void otr_trust(SERVER_REC *irssi, const char *nick, char *str_fp,
/* Always NEED a peer context or else code error. */
assert(opc);
- fp_trust = opc->active_fingerprint;
+ fp_trust = ctx->active_fingerprint;
} else {
fp_trust = otr_find_hash_fingerprint_from_human(str_fp, ustate);
}
@@ -836,9 +863,10 @@ end:
void otr_forget(SERVER_REC *irssi, const char *nick, char *str_fp,
struct otr_user_state *ustate)
{
+ int ret;
char fp[OTRL_PRIVKEY_FPRINT_HUMAN_LEN];
Fingerprint *fp_forget;
- ConnContext *ctx;
+ ConnContext *ctx = NULL;
struct otr_peer_context *opc;
if (!irssi && !str_fp) {
@@ -862,14 +890,14 @@ void otr_forget(SERVER_REC *irssi, const char *nick, char *str_fp,
fp_forget = otr_find_hash_fingerprint_from_human(str_fp, ustate);
}
- IRSSI_DEBUG("Forgetting fingerprint: %s", (str_fp != NULL) ? str_fp : fp);
-
if (fp_forget) {
/* Don't do anything if context is in encrypted state. */
- if (fp_forget->context->msgstate == OTRL_MSGSTATE_ENCRYPTED) {
+ ret = check_fp_encrypted_msgstate(fp_forget);
+ if (ret) {
IRSSI_NOTICE(irssi, nick, "Fingerprint "
"context is still encrypted. Finish the OTR "
- "session to forget fingerprint (%9/otr finish%9).");
+ "session before forgetting a fingerprint "
+ "(%9/otr finish%9).");
goto end;
}
--
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