Fossil SCM
Increase the amount of randomness in the probe string used to initialize an SSH synchronization link.
Commit
0e9b58c80c16e000f275b32edab066c943cd6d09
Parent
62c565ec96f2bd9…
1 file changed
+17
-10
+17
-10
| --- src/http_transport.c | ||
| +++ src/http_transport.c | ||
| @@ -97,29 +97,37 @@ | ||
| 97 | 97 | #ifdef __MINGW32__ |
| 98 | 98 | static char zDefaultSshCmd[] = "ssh -T"; |
| 99 | 99 | #else |
| 100 | 100 | static char zDefaultSshCmd[] = "ssh -e none -T"; |
| 101 | 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 | +} | |
| 102 | 113 | |
| 103 | 114 | /* |
| 104 | 115 | ** Bring up an SSH link. This involves sending some "echo" commands and |
| 105 | 116 | ** get back appropriate responses. The point is to move past the MOTD and |
| 106 | 117 | ** verify that the link is working. |
| 107 | 118 | */ |
| 108 | 119 | 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 */ | |
| 114 | 124 | int nIn; /* Size of input */ |
| 115 | 125 | static const int nBuf = 10000; /* Size of input buffer */ |
| 116 | 126 | |
| 117 | 127 | 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)); | |
| 121 | 129 | fprintf(sshOut, "echo %s\n", zProbe); |
| 122 | 130 | fflush(sshOut); |
| 123 | 131 | if( g.fSshTrace ){ |
| 124 | 132 | printf("Sent: [echo %s]\n", zProbe); |
| 125 | 133 | fflush(stdout); |
| @@ -140,12 +148,11 @@ | ||
| 140 | 148 | if( g.fSshTrace ){ |
| 141 | 149 | printf("Fetching more text. Looking for [%s]...\n", zProbe); |
| 142 | 150 | fflush(stdout); |
| 143 | 151 | } |
| 144 | 152 | } |
| 145 | - sqlite3_randomness(sizeof(iRandom), &iRandom); | |
| 146 | - sqlite3_snprintf(sizeof(zProbe), zProbe, "probe-%08x", iRandom); | |
| 153 | + nProbe = random_probe(zProbe, sizeof(zProbe)); | |
| 147 | 154 | fprintf(sshOut, "echo %s\n", zProbe); |
| 148 | 155 | fflush(sshOut); |
| 149 | 156 | if( g.fSshTrace ){ |
| 150 | 157 | printf("Sent: [echo %s]\n", zProbe); |
| 151 | 158 | fflush(stdout); |
| 152 | 159 |
| --- 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 |