ext/libuv/src/unix/openbsd.c in libuv-1.1.3 vs ext/libuv/src/unix/openbsd.c in libuv-1.2.0
- old
+ new
@@ -83,11 +83,11 @@
size_t argsbuf_size = 100U;
size_t exepath_size;
pid_t mypid;
int err;
- if (buffer == NULL || size == NULL)
+ if (buffer == NULL || size == NULL || *size == 0)
return -EINVAL;
mypid = getpid();
for (;;) {
err = -ENOMEM;
@@ -106,20 +106,22 @@
err = -errno;
goto out;
}
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:
free(argsbuf);