Bugzilla – Attachment 2943 Details for
Bug 2434
scp can send arbitrary control characters / escape sequences to the terminal
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Generate display name outside of sighandler
0002-Generate-display-name-outside-of-sighandler.patch (text/plain), 3.71 KB, created by
Darren Tucker
on 2017-02-15 16:47:41 AEDT
(
hide
)
Description:
Generate display name outside of sighandler
Filename:
MIME Type:
Creator:
Darren Tucker
Created:
2017-02-15 16:47:41 AEDT
Size:
3.71 KB
patch
obsolete
>From f076ee5aac6326cf9883598686f7e481c8a12d59 Mon Sep 17 00:00:00 2001 >From: Darren Tucker <dtucker@zip.com.au> >Date: Wed, 15 Feb 2017 16:41:46 +1100 >Subject: [PATCH 2/2] Generate display name outside of sighandler. > >Move the generation of the padded/truncated display name outside >of signal context and run through the UTF8 snmprintf (and if that >fails, strnvis). >--- > progressmeter.c | 36 +++++++++++++++++++++++++++--------- > progressmeter.h | 1 + > scp.c | 1 + > sftp-client.c | 1 + > 4 files changed, 30 insertions(+), 9 deletions(-) > >diff --git a/progressmeter.c b/progressmeter.c >index 4d924c5..00f0d63 100644 >--- a/progressmeter.c >+++ b/progressmeter.c >@@ -75,6 +75,9 @@ static int bytes_per_second; /* current speed in bytes per second */ > static int win_size; /* terminal window size */ > static volatile sig_atomic_t win_resized; /* for window resizing */ > >+static char displayname[2][MAX_WINSIZE]; >+static volatile sig_atomic_t displayname_num; >+ > /* units for format_size */ > static const char unit[] = " KMGT"; > >@@ -119,14 +122,13 @@ format_size(char *buf, int size, off_t bytes) > void > refresh_progress_meter(void) > { >- char buf[MAX_WINSIZE + 1], displayname[MAX_WINSIZE]; >+ char buf[MAX_WINSIZE + 1]; > off_t transferred; > double elapsed, now; > int percent; > off_t bytes_left; > int cur_speed; > int hours, minutes, seconds; >- int file_len; > > transferred = *counter - (cur_pos ? cur_pos : start_pos); > cur_pos = *counter; >@@ -155,18 +157,13 @@ refresh_progress_meter(void) > } else > bytes_per_second = cur_speed; > >- /* filename */ >- file_len = win_size - 35; >- displayname[0] = '\0'; >- if (file_len > 0) >- snprintf(displayname, file_len, "%*s ", file_len * -1, file); >- > /* percent of transfer done */ > if (end_pos == 0 || cur_pos == end_pos) > percent = 100; > else > percent = ((float)cur_pos / end_pos) * 100; >- snprintf(buf, sizeof(buf), "\r%s %3d%% ", displayname, percent); >+ snprintf(buf, sizeof(buf), "\r%s %3d%% ", displayname[displayname_num], >+ percent); > > /* amount transferred */ > format_size(buf + strlen(buf), win_size - strlen(buf), >@@ -216,6 +213,26 @@ refresh_progress_meter(void) > last_update = now; > } > >+void >+update_progress_displayname(void) >+{ >+ sig_atomic_t n = displayname_num ^ 1; >+ int len, cols, file_len = win_size - 36; >+ char buf[MAX_WINSIZE]; >+ >+ displayname[n][0] = '\0'; >+ if (file_len > 0) { >+ cols = file_len; >+ if (snmprintf(displayname[n], sizeof displayname[0], &cols, >+ "%*s", file_len * -1, file) == -1) { >+ strnvis(buf, file, sizeof buf, VIS_SAFE); >+ snprintf(displayname[n], sizeof displayname[0], "%*s", >+ file_len * -1 , buf); >+ } >+ } >+ displayname_num = n; >+} >+ > /*ARGSUSED*/ > static void > update_progress_meter(int ignore) >@@ -249,6 +266,7 @@ start_progress_meter(const char *f, off_t filesize, off_t *ctr) > bytes_per_second = 0; > > setscreensize(); >+ update_progress_displayname(); > if (can_output()) > refresh_progress_meter(); > >diff --git a/progressmeter.h b/progressmeter.h >index bf179dc..246fd79 100644 >--- a/progressmeter.h >+++ b/progressmeter.h >@@ -24,4 +24,5 @@ > */ > > void start_progress_meter(const char *, off_t, off_t *); >+void update_progress_displayname(void); > void stop_progress_meter(void); >diff --git a/scp.c b/scp.c >index b4db851..59beb10 100644 >--- a/scp.c >+++ b/scp.c >@@ -561,6 +561,7 @@ scpio(void *_cnt, size_t s) > *cnt += s; > if (limit_kbps > 0) > bandwidth_limit(&bwlimit, s); >+ update_progress_displayname(); > return 0; > } > >diff --git a/sftp-client.c b/sftp-client.c >index d47be0e..a87e96c 100644 >--- a/sftp-client.c >+++ b/sftp-client.c >@@ -95,6 +95,7 @@ sftpio(void *_bwlimit, size_t amount) > struct bwlimit *bwlimit = (struct bwlimit *)_bwlimit; > > bandwidth_limit(bwlimit, amount); >+ update_progress_displayname(); > return 0; > } > >-- >2.7.4 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 2434
:
2678
|
2858
|
2942
|
2943
|
3228