view libpurple/protocols/zephyr/ZMakeAscii.c @ 29871:6d2ba42595fe

oscar: Fix a race condition that leads to a crash. With SSL enabled, if we start connecting and something calls purple_account_disconnect between when an SSL flap connection is started and when the connection is actually established, it isn't properly cleaned up (and we try to close the flap), which leads to free-after-use. You can simulate this by adding a timeout-triggered disconnect to the end of oscar_connect_to_bos. [02/22/10 17:11:51] <libpurple/oscar> Destroying oscar connection of type 0x0002. Disconnect reason is 0 [02/22/10 17:11:51] <libpurple/oscar> Disconnected. Code is 0x0000 and msg is (hiicq:17126): GLib-WARNING **: giounix.c:400Error while getting flags for FD: Bad file descriptor (9) [02/22/10 17:11:51] <libpurple/oscar> Scheduling destruction of FLAP connection of type 0x0002 [02/22/10 17:11:51] <libpurple/oscar> Signed off. ... [02/22/10 17:11:51] <libpurple/oscar> Destroying oscar connection of type 0x7261. Disconnect reason is 1668179315
author Paul Aurich <paul@darkrain42.org>
date Mon, 22 Feb 2010 17:53:38 +0000
parents 5fe8042783c1
children a8cc50c2279f
line wrap: on
line source

/* This file is part of the Project Athena Zephyr Notification System.
 * It contains source for the ZMakeAscii function.
 *
 *	Created by:	Robert French
 *
 *	Copyright (c) 1987 by the Massachusetts Institute of Technology.
 *	For copying and distribution information, see the file
 *	"mit-copyright.h". 
 */

#include "internal.h"

static char *itox_chars = "0123456789ABCDEF";

Code_t ZMakeAscii(ptr, len, field, num)
    register char *ptr;
    int len;
    unsigned char *field;
    int num;
{
    int i;

    for (i=0;i<num;i++) {
	/* we need to add "0x" if we are between 4 byte pieces */
	if ((i & 3) == 0) {
	    if (len < (i?4:3))
		return ZERR_FIELDLEN;
	    /* except at the beginning, put a space in before the "0x" */
	    if (i) {
		*ptr++ = ' ';
		len--;
	    }
	    *ptr++ = '0';
	    *ptr++ = 'x';
	    len -= 2;
	} 
	if (len < 3)
	    return ZERR_FIELDLEN;
	*ptr++ = itox_chars[(int) (field[i] >> 4)];
	*ptr++ = itox_chars[(int) (field[i] & 0xf)];
	len -= 2;
    }

    *ptr = '\0';
    return ZERR_NONE;
}

Code_t ZMakeAscii32(ptr, len, value)
    register char *ptr;
    int len;
    unsigned long value;
{
    if (len < 11)
	return ZERR_FIELDLEN;
    *ptr++ = '0';
    *ptr++ = 'x';
    *ptr++ = itox_chars[(value >> 28) & 0xf];
    *ptr++ = itox_chars[(value >> 24) & 0xf];
    *ptr++ = itox_chars[(value >> 20) & 0xf];
    *ptr++ = itox_chars[(value >> 16) & 0xf];
    *ptr++ = itox_chars[(value >> 12) & 0xf];
    *ptr++ = itox_chars[(value >>  8) & 0xf];
    *ptr++ = itox_chars[(value >>  4) & 0xf];
    *ptr++ = itox_chars[(value >>  0) & 0xf];
    *ptr = 0;
    return ZERR_NONE;
}

Code_t ZMakeAscii16(ptr, len, value)
    register char *ptr;
    int len;
    unsigned int value;
{
    if (len < 7)
	return ZERR_FIELDLEN;
    *ptr++ = '0';
    *ptr++ = 'x';
    *ptr++ = itox_chars[(value >> 12) & 0xf];
    *ptr++ = itox_chars[(value >>  8) & 0xf];
    *ptr++ = itox_chars[(value >>  4) & 0xf];
    *ptr++ = itox_chars[(value >>  0) & 0xf];
    *ptr = 0;
    return ZERR_NONE;
}