summaryrefslogtreecommitdiff
path: root/deps/uv/src/unix/openbsd.c
diff options
context:
space:
mode:
Diffstat (limited to 'deps/uv/src/unix/openbsd.c')
-rw-r--r--deps/uv/src/unix/openbsd.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/deps/uv/src/unix/openbsd.c b/deps/uv/src/unix/openbsd.c
index cde8d4d0c9..3e7ae848ee 100644
--- a/deps/uv/src/unix/openbsd.c
+++ b/deps/uv/src/unix/openbsd.c
@@ -85,7 +85,7 @@ int uv_exepath(char* buffer, size_t* size) {
pid_t mypid;
int err;
- if (buffer == NULL || size == NULL)
+ if (buffer == NULL || size == NULL || *size == 0)
return -EINVAL;
mypid = getpid();
@@ -108,17 +108,19 @@ int uv_exepath(char* buffer, size_t* size) {
}
argsbuf_size *= 2U;
}
+
if (argsbuf[0] == NULL) {
err = -EINVAL; /* FIXME(bnoordhuis) More appropriate error. */
goto out;
}
+
+ *size -= 1;
exepath_size = strlen(argsbuf[0]);
- if (exepath_size >= *size) {
- err = -EINVAL;
- goto out;
- }
- memcpy(buffer, argsbuf[0], exepath_size + 1U);
- *size = exepath_size;
+ if (*size > exepath_size)
+ *size = exepath_size;
+
+ memcpy(buffer, argsbuf[0], *size);
+ buffer[*size] = '\0';
err = 0;
out: