int OsSSLConnectionSocket::read(char* buffer,
                             int bufferLength,
                             UtlString* ipAddress,
                             int* port)
{
    // Overide base class version as recvfrom does not
    // seem to return host info correctly for TCP
    // Use base class version without the remote host info
    int bytesRead = -1;

    bytesRead = SSL_read (mSSL, buffer, bufferLength);

#ifdef VALGRIND_MAKE_READABLE
    // If we are using Valgrind, we have to compensate for the fact that
    // Valgrind thinks all the output of SSL_read is undefined.
    // (This probably comes from SSL's use of uninitialized memory as part
    // of its key-generation algorithm.)
    VALGRIND_DISCARD(VALGRIND_MAKE_READABLE(&bytesRead, sizeof (bytesRead)));
    if (bytesRead > 0)
    {
       VALGRIND_DISCARD(VALGRIND_MAKE_READABLE(buffer, bytesRead));
    }
#endif /* VALGRIND_MAKE_READABLE */
    // Explicitly get the remote host info.
    getRemoteHostIp(ipAddress);
    *port = getRemoteHostPort();
    return(bytesRead);
}
示例#2
0
/*
 * Read from an OpenSSL BIO in non-blocking mode.
 */
static int
bio_read (BIO *bio, struct buffer *buf, int maxlen, const char *desc)
{
  int i;
  int ret = 0;
  ASSERT (buf->len >= 0);
  if (buf->len)
    {
      ;
    }
  else
    {
      int len = buf_forward_capacity (buf);
      if (maxlen < len)
	len = maxlen;

      /*
       * BIO_read brackets most of the serious RSA
       * key negotiation number crunching.
       */
      i = BIO_read (bio, BPTR (buf), len);

      VALGRIND_MAKE_READABLE ((void *) &i, sizeof (i));

#ifdef BIO_DEBUG
      bio_debug_data ("read", bio, BPTR (buf), i, desc);
#endif
      if (i < 0)
	{
	  if (BIO_should_retry (bio))
	    {
	      ;
	    }
	  else
	    {
	      msg (D_TLS_ERRORS | M_SSL, "TLS_ERROR: BIO read %s error",
		   desc);
	      buf->len = 0;
	      ret = -1;
	      ERR_clear_error ();
	    }
	}
      else if (!i)
	{
	  buf->len = 0;
	}
      else
	{			/* successful read */
	  dmsg (D_HANDSHAKE_VERBOSE, "BIO read %s %d bytes", desc, i);
	  buf->len = i;
	  ret = 1;
	  VALGRIND_MAKE_READABLE ((void *) BPTR (buf), BLEN (buf));
	}
    }
  return ret;
}
示例#3
0
static int
_evas_common_rgba_image_surface_alloc(Image_Entry *ie, unsigned int w, unsigned int h)
{
   RGBA_Image   *im = (RGBA_Image *) ie;
   size_t        siz = 0;

#ifdef EVAS_CSERVE
   if (ie->data1) return 0;
#endif   
   if (im->image.no_free) return 0;

   if (im->flags & RGBA_IMAGE_ALPHA_ONLY)
     siz = w * h * sizeof(DATA8);
   else
     siz = w * h * sizeof(DATA32);

   if (im->image.data) free(im->image.data);
   im->image.data = malloc(siz);
   if (!im->image.data) return -1;

#ifdef HAVE_VALGRIND
# ifdef VALGRIND_MAKE_READABLE
   VALGRIND_MAKE_READABLE(im->image.data, siz);
# else
#  ifdef VALGRIND_MAKE_MEM_DEFINED
   VALGRIND_MAKE_MEM_DEFINED(im->image.data, siz);
#  endif
# endif
#endif

   return 0;
}
示例#4
0
int main(int argc, char** argv)
{
    struct rlimit rlim;
    const char *cp;
    int i, loglevel;

    /* Start the debugging-log system ASAP.  First find out how many
       "-d"s were specified.  This is a pre-scan of the command line. */
    loglevel = 0;
    for (i = 1; i < argc; i++) {
        if (argv[i][0] != '-')
            break;
        if (0 == strcmp(argv[i], "--"))
            break;
        if (0 == strcmp(argv[i], "-d"))
            loglevel++;
    }

    /* ... and start the debug logger.  Now we can safely emit logging
       messages all through startup. */
    VG_(debugLog_startup)(loglevel, "Stage 1");

    // Initial stack pointer is to argc, which is immediately before argv[0]
    // on the stack.  Nb: Assumes argc is word-aligned.
// in case of netbsd initial stack pointer will beeeeeeee return argc argv
    init_sp = argv - 1;

    /* The Linux libc startup sequence leaves this in an apparently
       undefined state, but it really is defined, so mark it so. */
    VALGRIND_MAKE_READABLE(init_sp, sizeof(int));
    cp = getenv(VALGRINDLIB);

    if (cp != NULL)
        valgrind_lib = cp;

    /* Set the address space limit as high as it will go, since we make
       a lot of very large mappings. */
#ifndef VGO_netbsdelf2
    getrlimit(RLIMIT_AS, &rlim);
    rlim.rlim_cur = rlim.rlim_max;
    setrlimit(RLIMIT_AS, &rlim);
#endif
#ifdef VGO_netbsdelf2
    getrlimit(RLIMIT_RSS, &rlim);
    rlim.rlim_cur = rlim.rlim_max;
    setrlimit(RLIMIT_RSS, &rlim);
#endif
    /* move onto another stack so we can play with the main one */
    VG_(debugLog)(1, "stage1", "main(): running main2() on new stack\n");
    jump_and_switch_stacks(
        (Addr) stack + sizeof(stack),  /* stack */
        (Addr) main2                   /* where to */

    );

    /*NOTREACHED*/
    assert(0);
}
示例#5
0
/* Resize a block of memory, possibly re-allocating it.  */
void *
ggc_realloc_stat (void *x, size_t size MEM_STAT_DECL)
{
  void *r;
  size_t old_size;

  if (x == NULL)
    return ggc_alloc_stat (size PASS_MEM_STAT);

  old_size = ggc_get_size (x);

  if (size <= old_size)
    {
      /* Mark the unwanted memory as unaccessible.  We also need to make
	 the "new" size accessible, since ggc_get_size returns the size of
	 the pool, not the size of the individually allocated object, the
	 size which was previously made accessible.  Unfortunately, we
	 don't know that previously allocated size.  Without that
	 knowledge we have to lose some initialization-tracking for the
	 old parts of the object.  An alternative is to mark the whole
	 old_size as reachable, but that would lose tracking of writes
	 after the end of the object (by small offsets).  Discard the
	 handle to avoid handle leak.  */
      VALGRIND_DISCARD (VALGRIND_MAKE_NOACCESS ((char *) x + size,
						old_size - size));
      VALGRIND_DISCARD (VALGRIND_MAKE_READABLE (x, size));
      return x;
    }

  r = ggc_alloc_stat (size PASS_MEM_STAT);

  /* Since ggc_get_size returns the size of the pool, not the size of the
     individually allocated object, we'd access parts of the old object
     that were marked invalid with the memcpy below.  We lose a bit of the
     initialization-tracking since some of it may be uninitialized.  */
  VALGRIND_DISCARD (VALGRIND_MAKE_READABLE (x, old_size));

  memcpy (r, x, old_size);

  /* The old object is not supposed to be used anymore.  */
  ggc_free (x);

  return r;
}
int OsSSLConnectionSocket::read(char* buffer, int bufferLength)
{
    // Use base class implementation
    int bytesRead = -1;

    bytesRead = SSL_read (mSSL, buffer, bufferLength);

#ifdef VALGRIND_MAKE_READABLE
    // If we are using Valgrind, we have to compensate for the fact that
    // Valgrind thinks all the output of SSL_read is undefined.
    // (This probably comes from SSL's use of uninitialized memory as part
    // of its key-generation algorithm.)
    VALGRIND_DISCARD(VALGRIND_MAKE_READABLE(&bytesRead, sizeof (bytesRead)));
    if (bytesRead > 0)
    {
       VALGRIND_DISCARD(VALGRIND_MAKE_READABLE(buffer, bytesRead));
    }
#endif /* VALGRIND_MAKE_READABLE */

    return(bytesRead);
}
示例#7
0
static void
readwrap(exa_ringbuf_t *rng, char *buf, size_t nbytes)
{
  char *data = rng->data;
  int n, p;

  EXA_ASSERT(nbytes < rng->size);

#ifdef HAVE_VALGRIND_MEMCHECK_H
#  ifdef VALGRIND_MAKE_MEM_DEFINED /* Valgrind >= 3.2 */
      VALGRIND_MAKE_MEM_DEFINED(rng->data, rng->size);
#  else /* Valgrind < 3.2 */
      VALGRIND_MAKE_READABLE(rng->data, rng->size);
#  endif
#endif

  p = rng->pRd;

  if (p + nbytes >= rng->size)
    {
      /* wrap around */
      n = rng->size - p;
      if (buf)
	{
	  memcpy(buf, data + p, n);
	  buf += n;
	}
      nbytes -= n;
      p = 0;
    }

  /* direct read */
  if (buf)
    memcpy(buf, data + p, nbytes);
  rng->pRd = p + nbytes;

  EXA_ASSERT(rng->pRd < rng->size);
  EXA_ASSERT(rng->pWr < rng->size);
}
示例#8
0
void *sb_encoder_init(const SpeexMode *m)
{
   int i;
   spx_int32_t tmp;
   SBEncState *st;
   const SpeexSBMode *mode;

   st = (SBEncState*)speex_alloc(sizeof(SBEncState));
   if (!st)
      return NULL;
   st->mode = m;
   mode = (const SpeexSBMode*)m->mode;


   st->st_low = speex_encoder_init(mode->nb_mode);
#if defined(VAR_ARRAYS) || defined (USE_ALLOCA)
   st->stack = NULL;
#else
   /*st->stack = (char*)speex_alloc_scratch(SB_ENC_STACK);*/
   speex_encoder_ctl(st->st_low, SPEEX_GET_STACK, &st->stack);
#endif

   st->full_frame_size = 2*mode->frameSize;
   st->frame_size = mode->frameSize;
   st->subframeSize = mode->subframeSize;
   st->nbSubframes = mode->frameSize/mode->subframeSize;
   st->windowSize = st->frame_size+st->subframeSize;
   st->lpcSize=mode->lpcSize;

   st->encode_submode = 1;
   st->submodes=mode->submodes;
   st->submodeSelect = st->submodeID=mode->defaultSubmode;
   
   tmp=9;
   speex_encoder_ctl(st->st_low, SPEEX_SET_QUALITY, &tmp);
   tmp=1;
   speex_encoder_ctl(st->st_low, SPEEX_SET_WIDEBAND, &tmp);

   st->lpc_floor = mode->lpc_floor;
   st->gamma1=mode->gamma1;
   st->gamma2=mode->gamma2;
   st->first=1;

   st->high=(spx_word16_t*)speex_alloc((st->windowSize-st->frame_size)*sizeof(spx_word16_t));

   st->h0_mem=(spx_word16_t*)speex_alloc((QMF_ORDER)*sizeof(spx_word16_t));
   st->h1_mem=(spx_word16_t*)speex_alloc((QMF_ORDER)*sizeof(spx_word16_t));

   st->window= lpc_window;

   st->lagWindow = lag_window;

   st->old_lsp = (spx_lsp_t*)speex_alloc(st->lpcSize*sizeof(spx_lsp_t));
   st->old_qlsp = (spx_lsp_t*)speex_alloc(st->lpcSize*sizeof(spx_lsp_t));
   st->interp_qlpc = (spx_coef_t*)speex_alloc(st->lpcSize*sizeof(spx_coef_t));
   st->pi_gain = (spx_word32_t*)speex_alloc((st->nbSubframes)*sizeof(spx_word32_t));
   st->exc_rms = (spx_word16_t*)speex_alloc((st->nbSubframes)*sizeof(spx_word16_t));
   st->innov_rms_save = NULL;
   
   st->mem_sp = (spx_mem_t*)speex_alloc((st->lpcSize)*sizeof(spx_mem_t));
   st->mem_sp2 = (spx_mem_t*)speex_alloc((st->lpcSize)*sizeof(spx_mem_t));
   st->mem_sw = (spx_mem_t*)speex_alloc((st->lpcSize)*sizeof(spx_mem_t));

   for (i=0;i<st->lpcSize;i++)
      st->old_lsp[i]= DIV32(MULT16_16(QCONST16(3.1415927f, LSP_SHIFT), i+1), st->lpcSize+1);

#ifndef DISABLE_VBR
   st->vbr_quality = 8;
   st->vbr_enabled = 0;
   st->vbr_max = 0;
   st->vbr_max_high = 20000;  /* We just need a big value here */
   st->vad_enabled = 0;
   st->abr_enabled = 0;
   st->relative_quality=0;
#endif /* #ifndef DISABLE_VBR */

   st->complexity=2;
   speex_encoder_ctl(st->st_low, SPEEX_GET_SAMPLING_RATE, &st->sampling_rate);
   st->sampling_rate*=2;
#ifdef ENABLE_VALGRIND
   VALGRIND_MAKE_READABLE(st, (st->stack-(char*)st));
#endif
   return st;
}