1 Binary files fossil-1.32.orig/src/.manifest.c.swp and fossil-1.32-smime/src/.manifest.c.swp differ 2 diff -uNr fossil-1.32.orig/src/manifest.c fossil-1.32-smime/src/manifest.c 3 --- fossil-1.32.orig/src/manifest.c 2015-03-14 08:20:34.000000000 -0500 4 +++ fossil-1.32-smime/src/manifest.c 2015-03-27 00:32:19.288505002 -0500 5 @@ -229,23 +229,163 @@ 6 ** Remove the PGP signature from the artifact, if there is one. 7 */ 8 static void remove_pgp_signature(char **pz, int *pn){ 9 - char *z = *pz; 10 - int n = *pn; 11 - int i; 12 - if( strncmp(z, "-----BEGIN PGP SIGNED MESSAGE-----", 34)!=0 ) return; 13 - for(i=34; i<n && !after_blank_line(z+i); i++){} 14 - if( i>=n ) return; 15 - z += i; 16 - n -= i; 17 - *pz = z; 18 - for(i=n-1; i>=0; i--){ 19 - if( z[i]=='\n' && strncmp(&z[i],"\n-----BEGIN PGP SIGNATURE-", 25)==0 ){ 20 - n = i+1; 21 - break; 22 - } 23 - } 24 - *pn = n; 25 - return; 26 + char *manifest, boundary[256]; 27 + int manifest_len; 28 + int idx; 29 + int line_start, line_end, boundary_start, boundary_end, boundary_len; 30 + int manifestclear_start, manifestclear_end, manifestclear_len; 31 + int allow_quote; 32 + 33 + manifest = *pz; 34 + manifest_len = *pn; 35 + 36 + if (manifest_len >= 34 && memcmp(manifest, "-----BEGIN PGP SIGNED MESSAGE-----", 34) == 0) { 37 + /* Process as a GPG clear-signed message */ 38 + 39 + for (idx = 34; idx < manifest_len && !after_blank_line(manifest + idx); idx++) { 40 + /* Nothing to do here, we're just iterating over the contents */ 41 + } 42 + 43 + if (idx >= manifest_len) { 44 + return; 45 + } 46 + 47 + manifest += idx; 48 + manifest_len -= idx; 49 + 50 + if (manifest_len < 25) { 51 + return; 52 + } 53 + 54 + for (idx = manifest_len - 25; idx >= 0; idx--) { 55 + if (manifest[idx] != '\n') { 56 + continue; 57 + } 58 + 59 + if (memcmp(&manifest[idx],"\n-----BEGIN PGP SIGNATURE-", 25) == 0) { 60 + manifest_len = idx + 1; 61 + 62 + break; 63 + } 64 + } 65 + 66 + *pz = manifest; 67 + *pn = manifest_len; 68 + } else if (manifest_len >= 18 && memcmp(manifest, "MIME-Version: 1.0\n", 18) == 0) { 69 + /* Proccess as a multipart MIME message */ 70 + if (manifest_len < 30) { 71 + return; 72 + } 73 + 74 + line_start = -1; 75 + for (idx = 18; idx < manifest_len - 30; idx++) { 76 + if (memcmp(&manifest[idx], "Content-Type: multipart/signed", 30) != 0) { 77 + continue; 78 + } 79 + 80 + line_start = idx; 81 + 82 + break; 83 + } 84 + 85 + if (line_start == -1) { 86 + return; 87 + } 88 + 89 + line_end = -1; 90 + for (idx = line_start + 1; idx < manifest_len; idx++) { 91 + if (manifest[idx] != '\n') { 92 + continue; 93 + } 94 + 95 + line_end = idx - 1; 96 + 97 + break; 98 + } 99 + 100 + if (line_end == -1) { 101 + return; 102 + } 103 + 104 + boundary_start = -1; 105 + allow_quote = 1; 106 + for (idx = line_start; idx < line_end - 9; idx++) { 107 + if (memcmp(&manifest[idx], "boundary=", 9) != 0) { 108 + continue; 109 + } 110 + 111 + if (manifest[idx - 1] != ' ' && manifest[idx - 1] != ';') { 112 + continue; 113 + } 114 + 115 + boundary_start = idx + 9; 116 + 117 + if (manifest[idx + 9] == '"') { 118 + allow_quote = 0; 119 + 120 + boundary_start++; 121 + } 122 + 123 + break; 124 + } 125 + if (boundary_start == -1) { 126 + return; 127 + } 128 + 129 + boundary_end = line_end; 130 + for (idx = boundary_start; idx < line_end; idx++) { 131 + if (manifest[idx] == '"' && allow_quote) { 132 + continue; 133 + } 134 + 135 + if (manifest[idx] != ' ' && manifest[idx] != ';' && manifest[idx] != '"') { 136 + continue; 137 + } 138 + 139 + boundary_end = idx; 140 + 141 + break; 142 + } 143 + 144 + boundary_len = boundary_end - boundary_start; 145 + boundary_len = snprintf(boundary, sizeof(boundary), "\n--%.*s\n", boundary_len, manifest + boundary_start); 146 + 147 + manifestclear_start = -1; 148 + for (idx = 0; idx < manifest_len - boundary_len; idx++) { 149 + if (memcmp(&manifest[idx], boundary, boundary_len) != 0) { 150 + continue; 151 + } 152 + 153 + manifestclear_start = idx + boundary_len; 154 + 155 + break; 156 + } 157 + 158 + if (manifestclear_start == -1) { 159 + return; 160 + } 161 + 162 + manifestclear_end = -1; 163 + for (idx = manifestclear_start; idx < manifest_len - boundary_len; idx++) { 164 + if (memcmp(&manifest[idx], boundary, boundary_len) != 0) { 165 + continue; 166 + } 167 + 168 + manifestclear_end = idx; 169 + 170 + break; 171 + } 172 + 173 + if (manifestclear_end == -1) { 174 + return; 175 + } 176 + 177 + manifestclear_len = manifestclear_end - manifestclear_start; 178 + *pz = &manifest[manifestclear_start]; 179 + *pn = manifestclear_len; 180 + } 181 + 182 + return; 183 } 184 185 /* |