Пример #1
0
ssize_t send(int sockfd, const void *buf, size_t len, int flags)
{

  hostile_initialize();

  (void) pthread_once(&function_lookup_once, set_local);

  if (is_called() == false)
  {
    if (__function.frequency)
    {
      if (--not_until < 0 && random() % __function.frequency)
      {
        __function._used++;
        shutdown(sockfd, SHUT_RDWR);
        close(sockfd);
        errno= ECONNRESET;
        return -1;
      }
    }
  }

  set_called();
  ssize_t ret= __function.function.send(sockfd, buf, len, flags);
  reset_called();

  return ret;
}
Пример #2
0
int getaddrinfo(const char *node, const char *service,
                const struct addrinfo *hints,
                struct addrinfo **res)
{
  hostile_initialize();

  (void) pthread_once(&function_lookup_once, set_local);

  if (is_called() == false)
  {
    if (__function.frequency)
    {
      if (--not_until < 0 && random() % __function.frequency)
      {
#if 0
        perror("HOSTILE CLOSE() of socket during getaddrinfo()");
#endif
        return EAI_FAIL;
      }
    }
  }

  set_called();
  int ret= __function.function.getaddrinfo(node, service, hints, res);
  reset_called();

  return ret;
}
Пример #3
0
int pipe2(int pipefd[2], int flags)
{
  hostile_initialize();

  (void) pthread_once(&function_lookup_once, set_local);

  set_called();
  int ret= __function.function.pipe2(pipefd, flags);
  reset_called();

  return ret;
}
Пример #4
0
int poll(struct pollfd *fds, nfds_t nfds, int timeout)
{

  hostile_initialize();

  (void) pthread_once(&function_lookup_once, set_local);

  if (is_called() == false)
  {
    if (__function.frequency)
    {
      if (--not_until < 0 && random() % __function.frequency)
      {
        for (nfds_t x= 0; x < nfds; nfds++)
        {
          switch (hostile_poll_type)
          {
            case HOSTILE_POLL_CLOSED:
              shutdown(fds[x].fd, SHUT_RDWR);
              close(fds[x].fd);
              fds[x].revents= POLLIN|POLLHUP;
              break;

            case HOSTILE_POLL_SHUT_WR:
              shutdown(fds[x].fd, SHUT_WR);
              close(fds[x].fd);
              fds[x].revents= POLLIN;
              break;

            case HOSTILE_POLL_SHUT_RD:
              shutdown(fds[x].fd, SHUT_RD);
              fds[x].revents= POLLIN;
              break;

            default:
              assert(0);
              abort();
          }
        }
        return nfds;
      }
    }
  }

  set_called();
  int ret= __function.function.poll(fds, nfds, timeout);
  reset_called();

  return ret;
}
Пример #5
0
bool libhostile_is_accept()
{
  hostile_initialize();

  (void) pthread_once(&function_lookup_once, set_local);

  fprintf(stderr, "libhostile_is_accept() %s\n", __function.frequency ? "true" : "false");
  if (__function.frequency)
  {
    return true;
  }

  return false;
}
Пример #6
0
void *malloc(size_t size)
{
  hostile_initialize();
  (void) pthread_once(&function_lookup_once, set_malloc);

  if (__function.frequency)
  {
    if (--not_until < 0 && random() % __function.frequency)
    {
      fprintf(stderr, "Mid=evil on malloc()\n");
      errno= ENOMEM;
      return NULL;
    }
  }

  return __function.function.malloc(size);

}
Пример #7
0
int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
{

  hostile_initialize();

  (void) pthread_once(&function_lookup_once, set_local);

  if (is_called() == false)
  {
    if (__function.frequency)
    {
      if (--not_until < 0 && random() % __function.frequency)
      {
        if (random() % 1)
        {
          shutdown(sockfd, SHUT_RDWR);
          close(sockfd);
          errno= ECONNABORTED;
          return -1;
        }
        else
        {
          shutdown(sockfd, SHUT_RDWR);
          close(sockfd);
          errno= EMFILE;
          return -1;
        }
      }
    }
  }

  set_called();
  int ret= __function.function.accept(sockfd, addr, addrlen);
  reset_called();

  return ret;
}