Skip to main content
  • Home
  • login
  • Browse the archive

    swh mirror partner logo
swh logo
SoftwareHeritage
Software
Heritage
Mirror
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Revision 1d0671b81f18385ee6e73eed12b27fb25f27c67d authored by Dr. Matthias St. Pierre on 21 October 2018, 16:49:19 UTC, committed by Dr. Matthias St. Pierre on 26 October 2018, 06:50:26 UTC
RAND_load_file(): avoid adding small chunks to RAND_add()
Increase the load buffer size such that it exceeds the chunk
size by a comfortable amount. This is done to avoid calling
RAND_add() with a small final chunk. Instead, such a small
final chunk will be added together with the previous chunk
(unless it's the only one).

Related-to: #7449

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/7456)
1 parent 13ce862
  • Files
  • Changes
  • 620dde6
  • /
  • test
  • /
  • bio_callback_test.c
Raw File
Cook and download a directory from the Software Heritage Vault

You have requested the cooking of the directory with identifier None into a standard tar.gz archive.

Are you sure you want to continue ?

Download a directory from the Software Heritage Vault

You have requested the download of the directory with identifier None as a standard tar.gz archive.

Are you sure you want to continue ?

Cook and download a revision from the Software Heritage Vault

You have requested the cooking of the history heading to revision with identifier swh:1:rev:1d0671b81f18385ee6e73eed12b27fb25f27c67d into a bare git archive.

Are you sure you want to continue ?

Download a revision from the Software Heritage Vault

You have requested the download of the history heading to revision with identifier swh:1:rev:1d0671b81f18385ee6e73eed12b27fb25f27c67d as a bare git archive.

Are you sure you want to continue ?

Invalid Email !

The provided email is not well-formed.

Download link has expired

The requested archive is no longer available for download from the Software Heritage Vault.

Do you want to cook it again ?

Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • revision
  • content
revision badge
swh:1:rev:1d0671b81f18385ee6e73eed12b27fb25f27c67d
content badge Iframe embedding
swh:1:cnt:8a17602d791b2c986212477b0caa4ad17738dc46
bio_callback_test.c
/*
 * Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
 *
 * Licensed under the OpenSSL license (the "License").  You may not use
 * this file except in compliance with the License.  You can obtain a copy
 * in the file LICENSE in the source distribution or at
 * https://www.openssl.org/source/license.html
 */
#include <stdio.h>
#include <string.h>
#include <openssl/bio.h>

#include "testutil.h"

#define MAXCOUNT 5
static int         my_param_count;
static BIO        *my_param_b[MAXCOUNT];
static int         my_param_oper[MAXCOUNT];
static const char *my_param_argp[MAXCOUNT];
static int         my_param_argi[MAXCOUNT];
static long        my_param_argl[MAXCOUNT];
static long        my_param_ret[MAXCOUNT];

static long my_bio_callback(BIO *b, int oper, const char *argp, int argi,
                            long argl, long ret)
{
    if (my_param_count >= MAXCOUNT)
        return -1;
    my_param_b[my_param_count]    = b;
    my_param_oper[my_param_count] = oper;
    my_param_argp[my_param_count] = argp;
    my_param_argi[my_param_count] = argi;
    my_param_argl[my_param_count] = argl;
    my_param_ret[my_param_count]  = ret;
    my_param_count++;
    return ret;
}

static int test_bio_callback(void)
{
    int ok = 0;
    BIO *bio;
    int i;
    char test1[] = "test";
    const int test1len = sizeof(test1) - 1;
    char test2[] = "hello";
    const int test2len = sizeof(test2) - 1;
    char buf[16];

    my_param_count = 0;

    bio = BIO_new(BIO_s_mem());
    if (bio == NULL)
        goto err;

    BIO_set_callback(bio, my_bio_callback);
    i = BIO_write(bio, test1, test1len);
    if (!TEST_int_eq(i, test1len)
            || !TEST_int_eq(my_param_count, 2)
            || !TEST_ptr_eq(my_param_b[0], bio)
            || !TEST_int_eq(my_param_oper[0], BIO_CB_WRITE)
            || !TEST_ptr_eq(my_param_argp[0], test1)
            || !TEST_int_eq(my_param_argi[0], test1len)
            || !TEST_long_eq(my_param_argl[0], 0L)
            || !TEST_long_eq(my_param_ret[0], 1L)
            || !TEST_ptr_eq(my_param_b[1], bio)
            || !TEST_int_eq(my_param_oper[1], BIO_CB_WRITE | BIO_CB_RETURN)
            || !TEST_ptr_eq(my_param_argp[1], test1)
            || !TEST_int_eq(my_param_argi[1], test1len)
            || !TEST_long_eq(my_param_argl[1], 0L)
            || !TEST_long_eq(my_param_ret[1], (long)test1len))
        goto err;

    my_param_count = 0;
    i = BIO_read(bio, buf, sizeof(buf));
    if (!TEST_mem_eq(buf, i, test1, test1len)
            || !TEST_int_eq(my_param_count, 2)
            || !TEST_ptr_eq(my_param_b[0], bio)
            || !TEST_int_eq(my_param_oper[0], BIO_CB_READ)
            || !TEST_ptr_eq(my_param_argp[0], buf)
            || !TEST_int_eq(my_param_argi[0], sizeof(buf))
            || !TEST_long_eq(my_param_argl[0], 0L)
            || !TEST_long_eq(my_param_ret[0], 1L)
            || !TEST_ptr_eq(my_param_b[1], bio)
            || !TEST_int_eq(my_param_oper[1], BIO_CB_READ | BIO_CB_RETURN)
            || !TEST_ptr_eq(my_param_argp[1], buf)
            || !TEST_int_eq(my_param_argi[1], sizeof(buf))
            || !TEST_long_eq(my_param_argl[1], 0L)
            || !TEST_long_eq(my_param_ret[1], (long)test1len))
        goto err;

    /* By default a mem bio returns -1 if it has run out of data */
    my_param_count = 0;
    i = BIO_read(bio, buf, sizeof(buf));
    if (!TEST_int_eq(i, -1)
            || !TEST_int_eq(my_param_count, 2)
            || !TEST_ptr_eq(my_param_b[0], bio)
            || !TEST_int_eq(my_param_oper[0], BIO_CB_READ)
            || !TEST_ptr_eq(my_param_argp[0], buf)
            || !TEST_int_eq(my_param_argi[0], sizeof(buf))
            || !TEST_long_eq(my_param_argl[0], 0L)
            || !TEST_long_eq(my_param_ret[0], 1L)
            || !TEST_ptr_eq(my_param_b[1], bio)
            || !TEST_int_eq(my_param_oper[1], BIO_CB_READ | BIO_CB_RETURN)
            || !TEST_ptr_eq(my_param_argp[1], buf)
            || !TEST_int_eq(my_param_argi[1], sizeof(buf))
            || !TEST_long_eq(my_param_argl[1], 0L)
            || !TEST_long_eq(my_param_ret[1], -1L))
        goto err;

    /* Force the mem bio to return 0 if it has run out of data */
    BIO_set_mem_eof_return(bio, 0);
    my_param_count = 0;
    i = BIO_read(bio, buf, sizeof(buf));
    if (!TEST_int_eq(i, 0)
            || !TEST_int_eq(my_param_count, 2)
            || !TEST_ptr_eq(my_param_b[0], bio)
            || !TEST_int_eq(my_param_oper[0], BIO_CB_READ)
            || !TEST_ptr_eq(my_param_argp[0], buf)
            || !TEST_int_eq(my_param_argi[0], sizeof(buf))
            || !TEST_long_eq(my_param_argl[0], 0L)
            || !TEST_long_eq(my_param_ret[0], 1L)
            || !TEST_ptr_eq(my_param_b[1], bio)
            || !TEST_int_eq(my_param_oper[1], BIO_CB_READ | BIO_CB_RETURN)
            || !TEST_ptr_eq(my_param_argp[1], buf)
            || !TEST_int_eq(my_param_argi[1], sizeof(buf))
            || !TEST_long_eq(my_param_argl[1], 0L)
            || !TEST_long_eq(my_param_ret[1], 0L))
        goto err;

    my_param_count = 0;
    i = BIO_puts(bio, test2);
    if (!TEST_int_eq(i, 5)
            || !TEST_int_eq(my_param_count, 2)
            || !TEST_ptr_eq(my_param_b[0], bio)
            || !TEST_int_eq(my_param_oper[0], BIO_CB_PUTS)
            || !TEST_ptr_eq(my_param_argp[0], test2)
            || !TEST_int_eq(my_param_argi[0], 0)
            || !TEST_long_eq(my_param_argl[0], 0L)
            || !TEST_long_eq(my_param_ret[0], 1L)
            || !TEST_ptr_eq(my_param_b[1], bio)
            || !TEST_int_eq(my_param_oper[1], BIO_CB_PUTS | BIO_CB_RETURN)
            || !TEST_ptr_eq(my_param_argp[1], test2)
            || !TEST_int_eq(my_param_argi[1], 0)
            || !TEST_long_eq(my_param_argl[1], 0L)
            || !TEST_long_eq(my_param_ret[1], (long)test2len))
        goto err;

    my_param_count = 0;
    i = BIO_free(bio);
    if (!TEST_int_eq(i, 1)
            || !TEST_int_eq(my_param_count, 1)
            || !TEST_ptr_eq(my_param_b[0], bio)
            || !TEST_int_eq(my_param_oper[0], BIO_CB_FREE)
            || !TEST_ptr_eq(my_param_argp[0], NULL)
            || !TEST_int_eq(my_param_argi[0], 0)
            || !TEST_long_eq(my_param_argl[0], 0L)
            || !TEST_long_eq(my_param_ret[0], 1L))
        goto finish;

    ok = 1;
    goto finish;

err:
    BIO_free(bio);

finish:
    /* This helps finding memory leaks with ASAN */
    memset(my_param_b, 0, sizeof(my_param_b));
    memset(my_param_argp, 0, sizeof(my_param_argp));
    return ok;
}

int setup_tests(void)
{
    ADD_TEST(test_bio_callback);
    return 1;
}
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

ENEA — Copyright (C), ENEA. License: GNU AGPLv3+.
Legal notes  ::  JavaScript license information ::  Web API

back to top