[OTR-dev] otrl_base64_otr_decode() function...

Justin Ferguson jnferguson at gmail.com
Wed Jul 18 02:13:59 EDT 2012


doh, thought i got them all, then read the next case in the callers
switch statement:

(proto.c)
gcry_error_t otrl_proto_accept_data(char **plaintextp, OtrlTLV **tlvsp,
	ConnContext *context, const char *datamsg, unsigned char *flagsp)
{
    char *otrtag, *endtag;
    gcry_error_t err;
    unsigned char *rawmsg = NULL;
    size_t msglen, rawlen, lenp;
    unsigned char *macstart, *macend;
    unsigned char *bufp;
    unsigned int sender_keyid, recipient_keyid;
    gcry_mpi_t sender_next_y = NULL;
    unsigned char ctr[8];
    unsigned int datalen, reveallen;
    unsigned char *data = NULL;
    unsigned char *nul = NULL;
    unsigned char givenmac[20];
    DH_sesskeys *sess;
    unsigned char version;

    *plaintextp = NULL;
    *tlvsp = NULL;
    if (flagsp) *flagsp = 0;
    otrtag = strstr(datamsg, "?OTR:");
    if (!otrtag) {
	goto invval;
    }
    endtag = strchr(otrtag, '.');
    if (endtag) {
	msglen = endtag-otrtag;
    } else {
	msglen = strlen(otrtag);
    }

    /* Base64-decode the message */
    rawlen = ((msglen-5) / 4) * 3;   /* maximum possible */
    rawmsg = malloc(rawlen);
    if (!rawmsg && rawlen > 0) {
	err = gcry_error(GPG_ERR_ENOMEM);
	goto err;
    }
    rawlen = otrl_base64_decode(rawmsg, otrtag+5, msglen-5);  /* actual size */


On Wed, Jul 18, 2012 at 2:08 AM, Justin Ferguson <jnferguson at gmail.com> wrote:
> deja vu, (also looks like parse.c::decode() has the same construct):
>
> gcry_error_t otrl_proto_data_read_flags(const char *datamsg,
>         unsigned char *flagsp)
> {
>     char *otrtag, *endtag;
>     unsigned char *rawmsg = NULL;
>     unsigned char *bufp;
>     size_t msglen, rawlen, lenp;
>     unsigned char version;
>
>     if (flagsp) *flagsp = 0;
>     otrtag = strstr(datamsg, "?OTR:");
>     if (!otrtag) {
>         goto invval;
>     }
>     endtag = strchr(otrtag, '.');
>     if (endtag) {
>         msglen = endtag-otrtag;
>     } else {
>         msglen = strlen(otrtag);
>     }
>
>     /* Base64-decode the message */
>     rawlen = ((msglen-5) / 4) * 3;   /* maximum possible */
>     rawmsg = malloc(rawlen);
>     if (!rawmsg && rawlen > 0) {
>         return gcry_error(GPG_ERR_ENOMEM);
>     }
>     rawlen = otrl_base64_decode(rawmsg, otrtag+5, msglen-5);  /* actual size */
>
>
> On Tue, Jul 17, 2012 at 2:56 PM, Ian Goldberg <ian at cypherpunks.ca> wrote:
>> On Tue, Jul 17, 2012 at 10:39:39PM -0400, Paul Wouters wrote:
>>> On Tue, 17 Jul 2012, Ian Goldberg wrote:
>>>
>>> >@@ -237,7 +237,7 @@ int otrl_base64_otr_decode(const char *msg, unsigned char **
>>> >    }
>>> >
>>> >    /* Base64-decode the message */
>>> >-    rawlen = ((msglen-5) / 4) * 3;   /* maximum possible */
>>> >+    rawlen = ((msglen-5+3) / 4) * 3;   /* maximum possible */
>>> >    rawmsg = malloc(rawlen);
>>> >    if (!rawmsg && rawlen > 0) {
>>> >       return -1;
>>>
>>> Personally, I prefer things like sizeof("===") over literals like '3'.
>>
>> The "3" is actually "4-1", as the way to write ceil(x/4) in C (with
>> integer arithmetic) is (x+3)/4.
>>
>>    - Ian
>> _______________________________________________
>> OTR-dev mailing list
>> OTR-dev at lists.cypherpunks.ca
>> http://lists.cypherpunks.ca/mailman/listinfo/otr-dev



More information about the OTR-dev mailing list