1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. |
2 | * |
3 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
4 | * of this software and associated documentation files (the "Software"), to |
5 | * deal in the Software without restriction, including without limitation the |
6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
7 | * sell copies of the Software, and to permit persons to whom the Software is |
8 | * furnished to do so, subject to the following conditions: |
9 | * |
10 | * The above copyright notice and this permission notice shall be included in |
11 | * all copies or substantial portions of the Software. |
12 | * |
13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
19 | * IN THE SOFTWARE. |
20 | */ |
21 | |
22 | #include "uv.h" |
23 | #include "task.h" |
24 | #include <string.h> |
25 | |
26 | |
27 | static void set_title(const char* title) { |
28 | char buffer[512]; |
29 | int err; |
30 | |
31 | err = uv_get_process_title(buffer, sizeof(buffer)); |
32 | ASSERT(err == 0); |
33 | |
34 | err = uv_set_process_title(title); |
35 | ASSERT(err == 0); |
36 | |
37 | err = uv_get_process_title(buffer, sizeof(buffer)); |
38 | ASSERT(err == 0); |
39 | |
40 | ASSERT(strcmp(buffer, title) == 0); |
41 | } |
42 | |
43 | |
44 | static void uv_get_process_title_edge_cases(void) { |
45 | char buffer[512]; |
46 | int r; |
47 | |
48 | /* Test a NULL buffer */ |
49 | r = uv_get_process_title(NULL, 100); |
50 | ASSERT(r == UV_EINVAL); |
51 | |
52 | /* Test size of zero */ |
53 | r = uv_get_process_title(buffer, 0); |
54 | ASSERT(r == UV_EINVAL); |
55 | |
56 | /* Test for insufficient buffer size */ |
57 | r = uv_get_process_title(buffer, 1); |
58 | ASSERT(r == UV_ENOBUFS); |
59 | } |
60 | |
61 | |
62 | TEST_IMPL(process_title) { |
63 | #if defined(__sun) || defined(__CYGWIN__) || defined(__MSYS__) |
64 | RETURN_SKIP("uv_(get|set)_process_title is not implemented." ); |
65 | #endif |
66 | |
67 | /* Check for format string vulnerabilities. */ |
68 | set_title("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s" ); |
69 | set_title("new title" ); |
70 | |
71 | /* Check uv_get_process_title() edge cases */ |
72 | uv_get_process_title_edge_cases(); |
73 | |
74 | return 0; |
75 | } |
76 | |