summaryrefslogtreecommitdiff
path: root/sftp.c
diff options
context:
space:
mode:
authordtucker@openbsd.org <dtucker@openbsd.org>2020-01-23 07:10:22 +0000
committerDarren Tucker <dtucker@dtucker.net>2020-01-23 18:51:25 +1100
commit3bf2a6ac791d64046a537335a0f1d5e43579c5ad (patch)
tree76fcc0f1be306541c074be4aed3aca66023f0962 /sftp.c
parente027c044c796f3a01081a91bee55741204283f28 (diff)
upstream: Replace all calls to signal(2) with a wrapper around
sigaction(2). This wrapper blocks all other signals during the handler preventing races between handlers, and sets SA_RESTART which should reduce the potential for short read/write operations. OpenBSD-Commit-ID: 5e047663fd77a40d7b07bdabe68529df51fd2519
Diffstat (limited to 'sftp.c')
-rw-r--r--sftp.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/sftp.c b/sftp.c
index 54538ff96..ff14d3c29 100644
--- a/sftp.c
+++ b/sftp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sftp.c,v 1.196 2019/11/01 03:54:33 djm Exp $ */ 1/* $OpenBSD: sftp.c,v 1.197 2020/01/23 07:10:22 dtucker Exp $ */
2/* 2/*
3 * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org> 3 * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
4 * 4 *
@@ -2243,7 +2243,7 @@ interactive_loop(struct sftp_conn *conn, char *file1, char *file2)
2243 interactive = !batchmode && isatty(STDIN_FILENO); 2243 interactive = !batchmode && isatty(STDIN_FILENO);
2244 err = 0; 2244 err = 0;
2245 for (;;) { 2245 for (;;) {
2246 signal(SIGINT, SIG_IGN); 2246 ssh_signal(SIGINT, SIG_IGN);
2247 2247
2248 if (el == NULL) { 2248 if (el == NULL) {
2249 if (interactive) 2249 if (interactive)
@@ -2275,14 +2275,14 @@ interactive_loop(struct sftp_conn *conn, char *file1, char *file2)
2275 2275
2276 /* Handle user interrupts gracefully during commands */ 2276 /* Handle user interrupts gracefully during commands */
2277 interrupted = 0; 2277 interrupted = 0;
2278 signal(SIGINT, cmd_interrupt); 2278 ssh_signal(SIGINT, cmd_interrupt);
2279 2279
2280 err = parse_dispatch_command(conn, cmd, &remote_path, 2280 err = parse_dispatch_command(conn, cmd, &remote_path,
2281 startdir, batchmode, !interactive && el == NULL); 2281 startdir, batchmode, !interactive && el == NULL);
2282 if (err != 0) 2282 if (err != 0)
2283 break; 2283 break;
2284 } 2284 }
2285 signal(SIGCHLD, SIG_DFL); 2285 ssh_signal(SIGCHLD, SIG_DFL);
2286 free(remote_path); 2286 free(remote_path);
2287 free(startdir); 2287 free(startdir);
2288 free(conn); 2288 free(conn);
@@ -2339,20 +2339,20 @@ connect_to_server(char *path, char **args, int *in, int *out)
2339 * kill it too. Contrawise, since sftp sends SIGTERMs to the 2339 * kill it too. Contrawise, since sftp sends SIGTERMs to the
2340 * underlying ssh, it must *not* ignore that signal. 2340 * underlying ssh, it must *not* ignore that signal.
2341 */ 2341 */
2342 signal(SIGINT, SIG_IGN); 2342 ssh_signal(SIGINT, SIG_IGN);
2343 signal(SIGTERM, SIG_DFL); 2343 ssh_signal(SIGTERM, SIG_DFL);
2344 execvp(path, args); 2344 execvp(path, args);
2345 fprintf(stderr, "exec: %s: %s\n", path, strerror(errno)); 2345 fprintf(stderr, "exec: %s: %s\n", path, strerror(errno));
2346 _exit(1); 2346 _exit(1);
2347 } 2347 }
2348 2348
2349 signal(SIGTERM, killchild); 2349 ssh_signal(SIGTERM, killchild);
2350 signal(SIGINT, killchild); 2350 ssh_signal(SIGINT, killchild);
2351 signal(SIGHUP, killchild); 2351 ssh_signal(SIGHUP, killchild);
2352 signal(SIGTSTP, suspchild); 2352 ssh_signal(SIGTSTP, suspchild);
2353 signal(SIGTTIN, suspchild); 2353 ssh_signal(SIGTTIN, suspchild);
2354 signal(SIGTTOU, suspchild); 2354 ssh_signal(SIGTTOU, suspchild);
2355 signal(SIGCHLD, sigchld_handler); 2355 ssh_signal(SIGCHLD, sigchld_handler);
2356 close(c_in); 2356 close(c_in);
2357 close(c_out); 2357 close(c_out);
2358} 2358}