Changeset a2fadb4 in code for icbd.c


Ignore:
Timestamp:
Mar 7, 2014, 3:21:30 PM (11 years ago)
Author:
Mike Belopuhov <mike@…>
Branches:
master
Children:
8871953
Parents:
270fd23
git-author:
Mike Belopuhov <mike@…> (03/07/14 15:17:23)
git-committer:
Mike Belopuhov <mike@…> (03/07/14 15:21:30)
Message:

Get rid of ICB_MSGSIZE+1, fix various off-by-ones and do some truncation
where necessary.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icbd.c

    r270fd23 ra2fadb4  
    378378{
    379379        struct icb_session *is = (struct icb_session *)arg;
     380        unsigned char length;
    380381
    381382        while (EVBUFFER_LENGTH(EVBUFFER_INPUT(bev)) > 0) {
    382383                if (is->length == 0) {
    383384                        /* read length */
    384                         is->rlen = bufferevent_read(bev, is->buffer, 1);
    385                         is->length = (size_t)(unsigned char)is->buffer[0];
    386                         if (is->length == 0) {
     385                        bufferevent_read(bev, &length, 1);
     386                        if (length == 0) {
     387                                /*
     388                                 * An extension has been proposed:
     389                                 * if length is 0, the packet is part of an
     390                                 * "extended packet". The packet should be
     391                                 * treated as if length was 255 and the next
     392                                 * packet received from the sender should be
     393                                 * appended to this packet.
     394                                 *
     395                                 * This server doesn't support this yet.
     396                                 */
    387397                                icbd_drop(is, "invalid packet");
    388398                                return;
    389399                        }
     400                        is->length = (size_t)length;
     401                        is->rlen = 0;
    390402                }
    391403                /* read as much as we can */
     
    406418                if (is->rlen < is->length)
    407419                        return;
     420                /* null-terminate the data */
     421                is->buffer[MIN(is->rlen, ICB_MSGSIZE - 1)] = '\0';
    408422                /* process the message in full */
    409423                icb_input(is);
Note: See TracChangeset for help on using the changeset viewer.