summaryrefslogtreecommitdiff
path: root/atomicio.c
diff options
context:
space:
mode:
authordtucker@openbsd.org <dtucker@openbsd.org>2019-01-23 08:01:46 +0000
committerDarren Tucker <dtucker@dtucker.net>2019-01-24 12:30:30 +1100
commit8976f1c4b2721c26e878151f52bdf346dfe2d54c (patch)
tree528e309cbe5944c0127a1c3fa0752fe2f9701232 /atomicio.c
parent6249451f381755f792c6b9e2c2f80cdc699c14e2 (diff)
upstream: Sanitize scp filenames via snmprintf. To do this we move
the progressmeter formatting outside of signal handler context and have the atomicio callback called for EINTR too. bz#2434 with contributions from djm and jjelen at redhat.com, ok djm@ OpenBSD-Commit-ID: 1af61c1f70e4f3bd8ab140b9f1fa699481db57d8
Diffstat (limited to 'atomicio.c')
-rw-r--r--atomicio.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/atomicio.c b/atomicio.c
index cffa9fa7d..845b328ee 100644
--- a/atomicio.c
+++ b/atomicio.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: atomicio.c,v 1.28 2016/07/27 23:18:12 djm Exp $ */ 1/* $OpenBSD: atomicio.c,v 1.29 2019/01/23 08:01:46 dtucker Exp $ */
2/* 2/*
3 * Copyright (c) 2006 Damien Miller. All rights reserved. 3 * Copyright (c) 2006 Damien Miller. All rights reserved.
4 * Copyright (c) 2005 Anil Madhavapeddy. All rights reserved. 4 * Copyright (c) 2005 Anil Madhavapeddy. All rights reserved.
@@ -67,9 +67,14 @@ atomicio6(ssize_t (*f) (int, void *, size_t), int fd, void *_s, size_t n,
67 res = (f) (fd, s + pos, n - pos); 67 res = (f) (fd, s + pos, n - pos);
68 switch (res) { 68 switch (res) {
69 case -1: 69 case -1:
70 if (errno == EINTR) 70 if (errno == EINTR) {
71 /* possible SIGALARM, update callback */
72 if (cb != NULL && cb(cb_arg, 0) == -1) {
73 errno = EINTR;
74 return pos;
75 }
71 continue; 76 continue;
72 if (errno == EAGAIN || errno == EWOULDBLOCK) { 77 } else if (errno == EAGAIN || errno == EWOULDBLOCK) {
73 (void)poll(&pfd, 1, -1); 78 (void)poll(&pfd, 1, -1);
74 continue; 79 continue;
75 } 80 }
@@ -124,9 +129,14 @@ atomiciov6(ssize_t (*f) (int, const struct iovec *, int), int fd,
124 res = (f) (fd, iov, iovcnt); 129 res = (f) (fd, iov, iovcnt);
125 switch (res) { 130 switch (res) {
126 case -1: 131 case -1:
127 if (errno == EINTR) 132 if (errno == EINTR) {
133 /* possible SIGALARM, update callback */
134 if (cb != NULL && cb(cb_arg, 0) == -1) {
135 errno = EINTR;
136 return pos;
137 }
128 continue; 138 continue;
129 if (errno == EAGAIN || errno == EWOULDBLOCK) { 139 } else if (errno == EAGAIN || errno == EWOULDBLOCK) {
130 (void)poll(&pfd, 1, -1); 140 (void)poll(&pfd, 1, -1);
131 continue; 141 continue;
132 } 142 }