Blame test/test-process-title.c

Packit b5b901
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
Packit b5b901
 *
Packit b5b901
 * Permission is hereby granted, free of charge, to any person obtaining a copy
Packit b5b901
 * of this software and associated documentation files (the "Software"), to
Packit b5b901
 * deal in the Software without restriction, including without limitation the
Packit b5b901
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
Packit b5b901
 * sell copies of the Software, and to permit persons to whom the Software is
Packit b5b901
 * furnished to do so, subject to the following conditions:
Packit b5b901
 *
Packit b5b901
 * The above copyright notice and this permission notice shall be included in
Packit b5b901
 * all copies or substantial portions of the Software.
Packit b5b901
 *
Packit b5b901
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Packit b5b901
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Packit b5b901
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Packit b5b901
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Packit b5b901
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
Packit b5b901
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
Packit b5b901
 * IN THE SOFTWARE.
Packit b5b901
 */
Packit b5b901
Packit b5b901
#include "uv.h"
Packit b5b901
#include "task.h"
Packit b5b901
#include <string.h>
Packit b5b901
Packit b5b901
Packit b5b901
static void set_title(const char* title) {
Packit b5b901
  char buffer[512];
Packit b5b901
  int err;
Packit b5b901
Packit b5b901
  err = uv_get_process_title(buffer, sizeof(buffer));
Packit b5b901
  ASSERT(err == 0);
Packit b5b901
Packit b5b901
  err = uv_set_process_title(title);
Packit b5b901
  ASSERT(err == 0);
Packit b5b901
Packit b5b901
  err = uv_get_process_title(buffer, sizeof(buffer));
Packit b5b901
  ASSERT(err == 0);
Packit b5b901
Packit b5b901
  ASSERT(strcmp(buffer, title) == 0);
Packit b5b901
}
Packit b5b901
Packit b5b901
Packit b5b901
static void uv_get_process_title_edge_cases(void) {
Packit b5b901
  char buffer[512];
Packit b5b901
  int r;
Packit b5b901
Packit b5b901
  /* Test a NULL buffer */
Packit b5b901
  r = uv_get_process_title(NULL, 100);
Packit b5b901
  ASSERT(r == UV_EINVAL);
Packit b5b901
Packit b5b901
  /* Test size of zero */
Packit b5b901
  r = uv_get_process_title(buffer, 0);
Packit b5b901
  ASSERT(r == UV_EINVAL);
Packit b5b901
Packit b5b901
  /* Test for insufficient buffer size */
Packit b5b901
  r = uv_get_process_title(buffer, 1);
Packit b5b901
  ASSERT(r == UV_ENOBUFS);
Packit b5b901
}
Packit b5b901
Packit b5b901
Packit b5b901
TEST_IMPL(process_title) {
Packit b5b901
#if defined(__sun) || defined(__CYGWIN__) || defined(__MSYS__)
Packit b5b901
  RETURN_SKIP("uv_(get|set)_process_title is not implemented.");
Packit b5b901
#else
Packit b5b901
  /* Check for format string vulnerabilities. */
Packit b5b901
  set_title("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s");
Packit b5b901
  set_title("new title");
Packit b5b901
Packit b5b901
  /* Check uv_get_process_title() edge cases */
Packit b5b901
  uv_get_process_title_edge_cases();
Packit b5b901
Packit b5b901
  return 0;
Packit b5b901
#endif
Packit b5b901
}