Revision 1641 trunk/nntpgrab_core/nntpconnection.c

nntpconnection.c (revision 1641)
929 929
        nntpgrab_core_emit_part_progress_update(FALSE, conn->server_info.servername, conn->poll_fd.fd, conn->file->subject, conn->part->part_num, conn->article_bytes_downloaded, conn->part->size);
930 930
    }
931 931

                
932
    /* Do we have enough useful data? */
933
    if (length < 5) {
934
        /* Nope, push the data back in the recv buffer and try again later */
935

                
936
        /* If the read_msg call returned less then 5 bytes the buffer must be empty */
937
        g_return_if_fail(conn->recv_buffer_length == 0);
938

                
939
        memcpy(conn->recv_buffer, buf, length);
940
        conn->recv_buffer_length = length;
941

                
942
        return;
943
    }
944

                
945 932
    /* Check for the end sequence */
946
    if (!strncmp(buf + length - 5, "\r\n.\r\n", 5) ||
947
        !strncmp(buf + length - 3, "\n.\n", 3)) {
933
    if ((length >= 5 && !strncmp(buf + length - 5, "\r\n.\r\n", 5)) ||
934
        (length >= 3 && !strncmp(buf + length - 3, "\n.\n", 3))) {
948 935

                
949 936
        /* End sequence found! */
950 937

                
951 938
        /* Calculate the number of bytes we don't need to write to disk */
952
        if (!strncmp(buf + length - 5, "\r\n.\r\n", 5)) {
939
        if (length >= 5 && !strncmp(buf + length - 5, "\r\n.\r\n", 5)) {
953 940
            length -= 5;
954 941
        } else {
955 942
            length -= 3;

Also available in: Unified diff