forked from libuv/libuv
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fs: don't nullify req->bufs on EINTR
uv__fs_buf_iter currently sets req->bufs to NULL after it is done, but if the operation fails with EINTR then it will be retried, at which point it expects the bufs to not be NULL, causing a seg fault as in nodejs/node#4291. uv__fs_buf_iter should not set req->bufs to NULL if the operation fails with EINTR. Also, when it sets req->bufs to NULL, it should set req->nbufs to 0 as well, so we don't have the messy situation of a positive nbufs with no actual bufs.
- Loading branch information
Dave
committed
Dec 23, 2015
1 parent
c861972
commit 034d353
Showing
5 changed files
with
85 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* Copyright libuv project contributors. All rights reserved. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to | ||
* deal in the Software without restriction, including without limitation the | ||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
* sell copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
* IN THE SOFTWARE. | ||
*/ | ||
|
||
#include "uv.h" | ||
#include "task.h" | ||
#include <unistd.h> | ||
|
||
static uv_loop_t* loop; | ||
static uv_fs_t read_req; | ||
static uv_buf_t iov; | ||
|
||
static char buf[32]; | ||
static char test_buf[] = "test-buffer\n"; | ||
int pipe_fds[2]; | ||
|
||
struct thread_ctx { | ||
uv_barrier_t barrier; | ||
int fd; | ||
}; | ||
|
||
static void thread_main(void* arg) { | ||
kill(getpid(), SIGUSR1); | ||
write(pipe_fds[1], test_buf, sizeof(test_buf)); | ||
} | ||
|
||
void sig_func(int sig) { | ||
printf("Caught signal: %d\n",sig); | ||
} | ||
|
||
TEST_IMPL(eintr_handling) { | ||
struct thread_ctx ctx; | ||
uv_thread_t thread; | ||
int nread; | ||
|
||
struct sigaction sig_handler = {.sa_handler=sig_func}; | ||
sigaction(SIGUSR1, &sig_handler, 0); | ||
|
||
iov = uv_buf_init(buf, sizeof(buf)); | ||
loop = uv_default_loop(); | ||
|
||
ASSERT(0 == pipe(pipe_fds)); | ||
ASSERT(0 == uv_thread_create(&thread, thread_main, &ctx)); | ||
|
||
nread = uv_fs_read(loop, &read_req, pipe_fds[0], &iov, 1, -1, NULL); | ||
|
||
ASSERT(nread == sizeof(test_buf)); | ||
ASSERT(0 == strcmp(buf, test_buf)); | ||
|
||
close(pipe_fds[0]); | ||
close(pipe_fds[1]); | ||
|
||
MAKE_VALGRIND_HAPPY(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters