diff options
author | NIIBE Yutaka <[email protected]> | 2023-05-31 07:38:52 +0000 |
---|---|---|
committer | NIIBE Yutaka <[email protected]> | 2023-05-31 07:42:53 +0000 |
commit | efccdb36ec338f3739e1ef3bb2ce0d2a04219566 (patch) | |
tree | 7f05e22f92d796819b3ff3da4a6a5c8542d1fe0f /src | |
parent | Allow use of global system hooks with API version 2. (diff) | |
download | libassuan-efccdb36ec338f3739e1ef3bb2ce0d2a04219566.tar.gz libassuan-efccdb36ec338f3739e1ef3bb2ce0d2a04219566.zip |
w32: Fix error return for sending fd.
* src/system-w32.c (get_file_handle): Have a CTX to compose an error.
(w32_fdpass_send): Check PROCESS_ID.
Compose an error with _assuan_error.
Signed-off-by: NIIBE Yutaka <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/system-w32.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/system-w32.c b/src/system-w32.c index 415cd63..52914e1 100644 --- a/src/system-w32.c +++ b/src/system-w32.c @@ -169,19 +169,26 @@ __assuan_close (assuan_context_t ctx, assuan_fd_t fd) /* Get a file HANDLE for other end to send, from MY_HANDLE. */ static gpg_error_t -get_file_handle (assuan_fd_t my_handle, int process_id, HANDLE *r_handle) +get_file_handle (assuan_context_t ctx, assuan_fd_t my_handle, + int process_id, HANDLE *r_handle) { HANDLE prochandle, newhandle; prochandle = OpenProcess (PROCESS_DUP_HANDLE, FALSE, process_id); if (!prochandle) - return gpg_error (GPG_ERR_ASS_PARAMETER);/*FIXME: error*/ + { + TRACE1 (ctx, ASSUAN_LOG_SYSIO, "assuan_sendfd", ctx, + "OpenProcess failed: %s", _assuan_w32_strerror (ctx, -1)); + return _assuan_error (ctx, gpg_err_code_from_errno (EIO)); + } if (!DuplicateHandle (GetCurrentProcess (), my_handle, prochandle, &newhandle, 0, TRUE, DUPLICATE_SAME_ACCESS)) { + TRACE1 (ctx, ASSUAN_LOG_SYSIO, "assuan_sendfd", ctx, + "DuplicateHandle failed: %s", _assuan_w32_strerror (ctx, -1)); CloseHandle (prochandle); - return gpg_error (GPG_ERR_ASS_PARAMETER);/*FIXME: error*/ + return _assuan_error (ctx, GPG_ERR_ASS_PARAMETER); } CloseHandle (prochandle); *r_handle = newhandle; @@ -195,10 +202,13 @@ w32_fdpass_send (assuan_context_t ctx, assuan_fd_t fd) { char fdpass_msg[256]; int res; - HANDLE file_handle; + HANDLE file_handle = INVALID_HANDLE_VALUE; gpg_error_t err; - err = get_file_handle (fd, ctx->process_id, &file_handle); + if (ctx->process_id == -1) + return _assuan_error (ctx, GPG_ERR_SERVER_FAILED); + + err = get_file_handle (ctx, fd, ctx->process_id, &file_handle); if (err) return err; @@ -206,7 +216,7 @@ w32_fdpass_send (assuan_context_t ctx, assuan_fd_t fd) if (res < 0) { CloseHandle (file_handle); - return gpg_error (GPG_ERR_ASS_PARAMETER);/*FIXME: error*/ + return _assuan_error (ctx, GPG_ERR_ASS_PARAMETER); } err = assuan_transact (ctx, fdpass_msg, NULL, NULL, NULL, NULL, NULL, NULL); |