Hi,

BIO_printf function replaces the last char of the output with \0 under
certain conditions.

In the following code, the problem occurs:

  /* sample code */
  char *str="aaa...aaa"; /* 2046 characters */
  BIO_printf(bio, "%s\r\n", str); /* 2046(str) + 2("\r\n") = 2048 */

this problem occurs equally when the size is 3072/4096 bytes(it doesn't
occur when the size is 1024 bytes).

It seems that this problem occurs in the "_dopr" function.

File:crypto/bio/b_print.c
---------------------------------
_dopr(...)
{
    char ch;
    LLONG value;
    LDOUBLE fvalue;
    char *strvalue;
...
    *truncated = (currlen > *maxlen - 1);
    if (*truncated)
        currlen = *maxlen - 1;
    doapr_outch(sbuffer, buffer, &currlen, maxlen, '\0');
    *retlen = currlen - 1;
    return;
}
---------------------------------

the last char of the output of the doapr_outch function becomes \0 when the
variable "currlen" and "maxlen" are 2048.

I could resolve the problem by making the following change to "doapr_outch":

File:crypto/bio/b_print.c

# diff -u crypto/bio/b_print.c.org crypto/bio/b_print.c
--- crypto/bio/b_print.c.org    2007-09-16 02:05:11.000000000 +0900
+++ crypto/bio/b_print.c        2013-08-23 02:10:22.000000000 +0900
@@ -734,7 +734,7 @@
     assert(*sbuffer != NULL || buffer != NULL);

     if (buffer) {
-       while (*currlen >= *maxlen) {
+       while (*currlen >= *maxlen - 1 ) {
            if (*buffer == NULL) {
                if (*maxlen == 0)
                    *maxlen = 1024;

\0 is added to the last, so I increased the buffer size when "currlen" is
greater than or equal to "maxlen" - 1.

Best regards,
soushi
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           majord...@openssl.org

Reply via email to