openbsd: fix uv_exepath(smallbuf) UV_EINVAL error
Write as much of the path as possible to the output buffer. Before this commit, passing in a buffer that was too small to hold the result failed with a UV_EINVAL error. PR-URL: https://github.com/libuv/libuv/pull/104 Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
This commit is contained in:
parent
885b1ecda0
commit
d17a8e45f5
@ -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:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user