Fossil SCM

Increase the amount of randomness in the probe string used to initialize an SSH synchronization link.

drh 2012-11-12 15:12 trunk
Commit 0e9b58c80c16e000f275b32edab066c943cd6d09
1 file changed +17 -10
--- src/http_transport.c
+++ src/http_transport.c
@@ -97,29 +97,37 @@
9797
#ifdef __MINGW32__
9898
static char zDefaultSshCmd[] = "ssh -T";
9999
#else
100100
static char zDefaultSshCmd[] = "ssh -e none -T";
101101
#endif
102
+
103
+/*
104
+** Generate a random SSH link problem keyword
105
+*/
106
+static int random_probe(char *zProbe, int nProbe){
107
+ unsigned r[4];
108
+ sqlite3_randomness(sizeof(r), r);
109
+ sqlite3_snprintf(nProbe, zProbe, "probe-%08x%08x%08x%08x",
110
+ r[0], r[1], r[2], r[3]);
111
+ return (int)strlen(zProbe);
112
+}
102113
103114
/*
104115
** Bring up an SSH link. This involves sending some "echo" commands and
105116
** get back appropriate responses. The point is to move past the MOTD and
106117
** verify that the link is working.
107118
*/
108119
static void transport_ssh_startup(void){
109
- char *zIn; /* An input line received back from remote */
110
- int nWait; /* Number of times waiting for the MOTD */
111
- unsigned iRandom; /* Random probe value */
112
- char zProbe[30]; /* Text of the random probe */
113
- int nProbe; /* Size of probe message */
120
+ char *zIn; /* An input line received back from remote */
121
+ int nWait; /* Number of times waiting for the MOTD */
122
+ char zProbe[40]; /* Text of the random probe */
123
+ int nProbe; /* Size of probe message */
114124
int nIn; /* Size of input */
115125
static const int nBuf = 10000; /* Size of input buffer */
116126
117127
zIn = fossil_malloc(nBuf);
118
- sqlite3_randomness(sizeof(iRandom), &iRandom);
119
- sqlite3_snprintf(sizeof(zProbe), zProbe, "probe-%08x", iRandom);
120
- nProbe = (int)strlen(zProbe);
128
+ nProbe = random_probe(zProbe, sizeof(zProbe));
121129
fprintf(sshOut, "echo %s\n", zProbe);
122130
fflush(sshOut);
123131
if( g.fSshTrace ){
124132
printf("Sent: [echo %s]\n", zProbe);
125133
fflush(stdout);
@@ -140,12 +148,11 @@
140148
if( g.fSshTrace ){
141149
printf("Fetching more text. Looking for [%s]...\n", zProbe);
142150
fflush(stdout);
143151
}
144152
}
145
- sqlite3_randomness(sizeof(iRandom), &iRandom);
146
- sqlite3_snprintf(sizeof(zProbe), zProbe, "probe-%08x", iRandom);
153
+ nProbe = random_probe(zProbe, sizeof(zProbe));
147154
fprintf(sshOut, "echo %s\n", zProbe);
148155
fflush(sshOut);
149156
if( g.fSshTrace ){
150157
printf("Sent: [echo %s]\n", zProbe);
151158
fflush(stdout);
152159
--- src/http_transport.c
+++ src/http_transport.c
@@ -97,29 +97,37 @@
97 #ifdef __MINGW32__
98 static char zDefaultSshCmd[] = "ssh -T";
99 #else
100 static char zDefaultSshCmd[] = "ssh -e none -T";
101 #endif
 
 
 
 
 
 
 
 
 
 
 
102
103 /*
104 ** Bring up an SSH link. This involves sending some "echo" commands and
105 ** get back appropriate responses. The point is to move past the MOTD and
106 ** verify that the link is working.
107 */
108 static void transport_ssh_startup(void){
109 char *zIn; /* An input line received back from remote */
110 int nWait; /* Number of times waiting for the MOTD */
111 unsigned iRandom; /* Random probe value */
112 char zProbe[30]; /* Text of the random probe */
113 int nProbe; /* Size of probe message */
114 int nIn; /* Size of input */
115 static const int nBuf = 10000; /* Size of input buffer */
116
117 zIn = fossil_malloc(nBuf);
118 sqlite3_randomness(sizeof(iRandom), &iRandom);
119 sqlite3_snprintf(sizeof(zProbe), zProbe, "probe-%08x", iRandom);
120 nProbe = (int)strlen(zProbe);
121 fprintf(sshOut, "echo %s\n", zProbe);
122 fflush(sshOut);
123 if( g.fSshTrace ){
124 printf("Sent: [echo %s]\n", zProbe);
125 fflush(stdout);
@@ -140,12 +148,11 @@
140 if( g.fSshTrace ){
141 printf("Fetching more text. Looking for [%s]...\n", zProbe);
142 fflush(stdout);
143 }
144 }
145 sqlite3_randomness(sizeof(iRandom), &iRandom);
146 sqlite3_snprintf(sizeof(zProbe), zProbe, "probe-%08x", iRandom);
147 fprintf(sshOut, "echo %s\n", zProbe);
148 fflush(sshOut);
149 if( g.fSshTrace ){
150 printf("Sent: [echo %s]\n", zProbe);
151 fflush(stdout);
152
--- src/http_transport.c
+++ src/http_transport.c
@@ -97,29 +97,37 @@
97 #ifdef __MINGW32__
98 static char zDefaultSshCmd[] = "ssh -T";
99 #else
100 static char zDefaultSshCmd[] = "ssh -e none -T";
101 #endif
102
103 /*
104 ** Generate a random SSH link problem keyword
105 */
106 static int random_probe(char *zProbe, int nProbe){
107 unsigned r[4];
108 sqlite3_randomness(sizeof(r), r);
109 sqlite3_snprintf(nProbe, zProbe, "probe-%08x%08x%08x%08x",
110 r[0], r[1], r[2], r[3]);
111 return (int)strlen(zProbe);
112 }
113
114 /*
115 ** Bring up an SSH link. This involves sending some "echo" commands and
116 ** get back appropriate responses. The point is to move past the MOTD and
117 ** verify that the link is working.
118 */
119 static void transport_ssh_startup(void){
120 char *zIn; /* An input line received back from remote */
121 int nWait; /* Number of times waiting for the MOTD */
122 char zProbe[40]; /* Text of the random probe */
123 int nProbe; /* Size of probe message */
 
124 int nIn; /* Size of input */
125 static const int nBuf = 10000; /* Size of input buffer */
126
127 zIn = fossil_malloc(nBuf);
128 nProbe = random_probe(zProbe, sizeof(zProbe));
 
 
129 fprintf(sshOut, "echo %s\n", zProbe);
130 fflush(sshOut);
131 if( g.fSshTrace ){
132 printf("Sent: [echo %s]\n", zProbe);
133 fflush(stdout);
@@ -140,12 +148,11 @@
148 if( g.fSshTrace ){
149 printf("Fetching more text. Looking for [%s]...\n", zProbe);
150 fflush(stdout);
151 }
152 }
153 nProbe = random_probe(zProbe, sizeof(zProbe));
 
154 fprintf(sshOut, "echo %s\n", zProbe);
155 fflush(sshOut);
156 if( g.fSshTrace ){
157 printf("Sent: [echo %s]\n", zProbe);
158 fflush(stdout);
159

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button