[Pkg-privacy-commits] [libotr] 125/225: Fix warning from clang in proto.c

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 12:45:10 UTC 2015


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

infinity0 pushed a commit to branch master
in repository libotr.

commit f0f8a26dda75e5b97eddbc69f3ccb33e107d808b
Author: Ian Goldberg <iang at cs.uwaterloo.ca>
Date:   Wed Aug 21 09:23:08 2013 -0400

    Fix warning from clang in proto.c
    
    Before, trying to fragment a message into more than 65535 pieces would
    cause incorrect fragments to be output.
    
    Now, it just returns an error (as that is disallowed by the spec).
    
    Thanks to Teemu Huovila <thuovila at cs.helsinki.fi> for reporting the issue.
---
 ChangeLog   |  8 ++++++++
 src/proto.c | 18 +++++++++++++-----
 2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 042937e..7488afd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2013-08-21
+
+	* src/proto.c: Fix warning from clang in proto.c. Before, trying
+	to fragment a message into more than 65535 pieces would cause
+	incorrect fragments to be output.  Now, it just returns an error
+	(as that is disallowed by the spec).  Thanks to Teemu Huovila
+	<thuovila at cs.helsinki.fi> for reporting the issue.
+
 2013-08-08
 
 	* Protocol-v3.html: Random exponents in SMP should be 1536 bits.
diff --git a/src/proto.c b/src/proto.c
index b6c773a..dba32e2 100644
--- a/src/proto.c
+++ b/src/proto.c
@@ -990,13 +990,19 @@ gcry_error_t otrl_proto_fragment_create(int mms, int fragment_count,
 {
     char *fragdata;
     int fragdatalen = 0;
-    unsigned short curfrag = 0;
+    int curfrag = 0;
     int index = 0;
     int msglen = strlen(message);
     /* Should vary by number of msgs */
     int headerlen = context->protocol_version == 3 ? 37 : 19;
 
-    char **fragmentarray = malloc(fragment_count * sizeof(char*));
+    char **fragmentarray;
+
+    if (fragment_count < 1 || fragment_count > 65535) {
+	return gcry_error(GPG_ERR_INV_VALUE);
+    }
+
+    fragmentarray = malloc(fragment_count * sizeof(char*));
     if(!fragmentarray) return gcry_error(GPG_ERR_ENOMEM);
 
     /*
@@ -1034,13 +1040,15 @@ gcry_error_t otrl_proto_fragment_create(int mms, int fragment_count,
 	 */
 	if (context->auth.protocol_version != 3) {
 	    snprintf(fragmentmsg, fragdatalen + headerlen,
-		    "?OTR,%05hu,%05hu,%s,", curfrag, fragment_count, fragdata);
+		    "?OTR,%05hu,%05hu,%s,", (unsigned short)curfrag,
+			    (unsigned short)fragment_count, fragdata);
 	} else {
 	    /* V3 messages require instance tags in the header */
 	    snprintf(fragmentmsg, fragdatalen + headerlen,
 		    "?OTR|%08x|%08x,%05hu,%05hu,%s,",
-		    context->our_instance, context->their_instance, curfrag,
-		    fragment_count, fragdata);
+		    context->our_instance, context->their_instance,
+		    (unsigned short)curfrag, (unsigned short)fragment_count,
+		    fragdata);
 	}
 	fragmentmsg[fragdatalen + headerlen] = 0;
 

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



More information about the Pkg-privacy-commits mailing list