Changeset a2fadb4 in code


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.

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • icb.c

    r270fd23 ra2fadb4  
    8282
    8383        is->last = getmonotime();
    84         type = msg[1];
    85         msg += 2;
     84        type = msg[0];
     85        msg++;
    8686        if (!ISSETF(is->flags, ICB_SF_LOGGEDIN) && type != ICB_M_LOGIN) {
    8787                icb_error(is, "Not logged in");
     
    378378    const char *fmt, ...)
    379379{
    380         char buf[ICB_MSGSIZE];
     380        char buf[ICB_MSGSIZE - 10]; /* truncate to make sure all fits */
    381381        va_list ap;
    382382        struct icb_session *s;
     
    481481icb_dowho(struct icb_session *is, struct icb_group *ig)
    482482{
    483         char buf[ICB_MSGSIZE];
     483        char buf[ICB_MSGSIZE - 10]; /* truncate to make sure all fits */
    484484        struct icb_session *s;
    485485        int nusers = 0;
     
    510510icb_who(struct icb_session *is, struct icb_group *ig)
    511511{
    512         char buf[ICB_MSGSIZE];
     512        char buf[ICB_MSGSIZE - 10]; /* truncate to make sure all fits */
    513513        struct icb_group *g;
    514514
  • icb.h

    r270fd23 ra2fadb4  
    1818#include <sys/tree.h>
    1919
     20/*
     21 * ICB packet has the following format: <length><type><data>
     22 * <lenght> is one byte length of the packet excluding the <lenght> byte;
     23 * <type> is one byte type of the packet;
     24 * <data> might not be null-terminated.
     25 */
    2026#define ICB_MSGSIZE              256
    2127
     
    7177        char                     client[ICB_MAXNICKLEN];
    7278        char                     host[MAXHOSTNAMELEN];
    73         char                     buffer[ICB_MSGSIZE+1];
     79        char                     buffer[ICB_MSGSIZE];
    7480        struct event             ev;
    7581        struct bufferevent      *bev;
  • 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);
  • logger.c

    r270fd23 ra2fadb4  
    197197                        return;
    198198                /* terminate the buffer */
    199                 m[MIN(nread - sizeof *e, ICB_MSGSIZE)] = '\0';
     199                m[MIN(nread - sizeof *e, ICB_MSGSIZE - 1)] = '\0';
    200200                /* find the appropriate log file */
    201201                for (i = 0; i < nlogfiles; i++)
Note: See TracChangeset for help on using the changeset viewer.