Subject: Re: [libssh2] #181: _libssh2_debug doesnt terminate buffer

Re: [libssh2] #181: _libssh2_debug doesnt terminate buffer

From: libssh2 Trac <trac_at_libssh2.stuge.se>
Date: Wed, 23 Jun 2010 08:16:39 -0000

#181: _libssh2_debug doesnt terminate buffer
-------------------------------+--------------------------------------------
  Reporter: john@… | Owner: bagder
      Type: enhancement | Status: assigned
  Priority: normal | Milestone: 1.2.7
 Component: API | Version: 1.2.6
Resolution: | Keywords:
    Blocks: | Blocked By:
-------------------------------+--------------------------------------------

Comment (by john@…):

 No in the function '''_libssh2_debug''' the debug string is stored in a
 variable called '''buffer'''. This is not a terminated string. When the
 '''(session->tracehandler)''' function is called I cant treat the buffer
 passed to me as a string (as it's not terminated). This means I can't use
 "%s" in a format buffer.

 As the '''_libssh2_debug''' uses "write" to output the debug information
 the lack of termination is not a problem. However I have other debug that
 uses "printf", which is buffered, and I need the debug to come out in the
 correct order (write will bypass the printf buffer).

 Here is a '''diff -u''' output of '''misc.c''' showing the changes I have
 made

 --- misc.c Thu Jun 3 12:52:02 2010
 +++ /usr2/other/libssh2/libssh2-1.2.6/src/misc.c Wed Jun 23
 09:16:10 2010
 @@ -405,12 +405,15 @@
      }
      now.tv_sec -= firstsec;

 - len = snprintf(buffer, sizeof(buffer), "[libssh2] %d.%06d %s: ",
 + /* Add the session pointer to the debug output, to aid tracking */
 + len = snprintf(buffer, sizeof(buffer), "[libssh2 0x%p] %d.%06d %s:
 ",session,
                     (int)now.tv_sec, (int)now.tv_usec, contexttext);

      va_start(vargs, format);
      len += vsnprintf(buffer + len, 1535 - len, format, vargs);
      buffer[len] = '\n';
 + /* terminate the buffer (make it a string) */
 + buffer[len+1] = '\0';
      va_end(vargs);

      if (session->tracehandler) {

-- 
Ticket URL: <http://trac.libssh2.org/ticket/181#comment:2>
libssh2 <http://trac.libssh2.org/>
C library for writing portable SSH2 clients
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2010-06-23