Fossil SCM
Merge small-fixes into trunk: fixes for the git and svn importers, Range and redirect replies, TH1 commands, URL and proxy handling in sync, the login cookie and access checks on /ambiguous and /info, and refusal of a second fossil= in an ssh URL.
Commit
75d41911e005650db8e6b1e666559380f2c28f30c3cb38a5e5d1dfa2ea3a7f23
Parent
13ebb6cc82476c4…
18 files changed
+24
-12
+61
-20
+2
-4
-15
+15
-6
+94
-33
+2
+9
-1
+1
-1
+3
-3
+59
-49
+4
-1
+3
-2
+1
-1
+2
+52
-21
+2
-1
+16
-4
+24
-12
| --- src/builtin.c | ||
| +++ src/builtin.c | ||
| @@ -305,10 +305,28 @@ | ||
| 305 | 305 | default: { |
| 306 | 306 | return "inline"; |
| 307 | 307 | } |
| 308 | 308 | } |
| 309 | 309 | } |
| 310 | + | |
| 311 | +/* | |
| 312 | +** Add the Javascript file named by zFilename to the queue of requested | |
| 313 | +** javascript resources, if it is not there already. Return 0 on | |
| 314 | +** success, 1 if there is no such built-in file, or 2 if the queue is | |
| 315 | +** full. | |
| 316 | +*/ | |
| 317 | +int builtin_try_request_js(const char *zFilename){ | |
| 318 | + int i = builtin_file_index(zFilename); | |
| 319 | + int j; | |
| 320 | + if( i<0 ) return 1; | |
| 321 | + for(j=0; j<builtin.nReq; j++){ | |
| 322 | + if( builtin.aReq[j]==i ) return 0; /* Already queued or sent */ | |
| 323 | + } | |
| 324 | + if( builtin.nReq>=count(builtin.aReq) ) return 2; | |
| 325 | + builtin.aReq[builtin.nReq++] = i; | |
| 326 | + return 0; | |
| 327 | +} | |
| 310 | 328 | |
| 311 | 329 | /* |
| 312 | 330 | ** The caller wants the Javascript file named by zFilename to be |
| 313 | 331 | ** included in the generated page. Add the file to the queue of |
| 314 | 332 | ** requested javascript resources, if it is not there already. |
| @@ -327,22 +345,16 @@ | ||
| 327 | 345 | ** does not guarantee when the javascript will be included, and it |
| 328 | 346 | ** does not guarantee whether the javascript will be added inline or |
| 329 | 347 | ** delivered as a separate resource. |
| 330 | 348 | */ |
| 331 | 349 | void builtin_request_js(const char *zFilename){ |
| 332 | - int i = builtin_file_index(zFilename); | |
| 333 | - int j; | |
| 334 | - if( i<0 ){ | |
| 335 | - fossil_panic("unknown javascript file: \"%s\"", zFilename); | |
| 336 | - } | |
| 337 | - for(j=0; j<builtin.nReq; j++){ | |
| 338 | - if( builtin.aReq[j]==i ) return; /* Already queued or sent */ | |
| 339 | - } | |
| 340 | - if( builtin.nReq>=count(builtin.aReq) ){ | |
| 341 | - fossil_panic("too many javascript files requested"); | |
| 342 | - } | |
| 343 | - builtin.aReq[builtin.nReq++] = i; | |
| 350 | + switch( builtin_try_request_js(zFilename) ){ | |
| 351 | + case 1: | |
| 352 | + fossil_panic("unknown javascript file: \"%s\"", zFilename); | |
| 353 | + case 2: | |
| 354 | + fossil_panic("too many javascript files requested"); | |
| 355 | + } | |
| 344 | 356 | } |
| 345 | 357 | |
| 346 | 358 | /* |
| 347 | 359 | ** Fulfill all pending requests for javascript files. |
| 348 | 360 | ** |
| 349 | 361 |
| --- src/builtin.c | |
| +++ src/builtin.c | |
| @@ -305,10 +305,28 @@ | |
| 305 | default: { |
| 306 | return "inline"; |
| 307 | } |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | /* |
| 312 | ** The caller wants the Javascript file named by zFilename to be |
| 313 | ** included in the generated page. Add the file to the queue of |
| 314 | ** requested javascript resources, if it is not there already. |
| @@ -327,22 +345,16 @@ | |
| 327 | ** does not guarantee when the javascript will be included, and it |
| 328 | ** does not guarantee whether the javascript will be added inline or |
| 329 | ** delivered as a separate resource. |
| 330 | */ |
| 331 | void builtin_request_js(const char *zFilename){ |
| 332 | int i = builtin_file_index(zFilename); |
| 333 | int j; |
| 334 | if( i<0 ){ |
| 335 | fossil_panic("unknown javascript file: \"%s\"", zFilename); |
| 336 | } |
| 337 | for(j=0; j<builtin.nReq; j++){ |
| 338 | if( builtin.aReq[j]==i ) return; /* Already queued or sent */ |
| 339 | } |
| 340 | if( builtin.nReq>=count(builtin.aReq) ){ |
| 341 | fossil_panic("too many javascript files requested"); |
| 342 | } |
| 343 | builtin.aReq[builtin.nReq++] = i; |
| 344 | } |
| 345 | |
| 346 | /* |
| 347 | ** Fulfill all pending requests for javascript files. |
| 348 | ** |
| 349 |
| --- src/builtin.c | |
| +++ src/builtin.c | |
| @@ -305,10 +305,28 @@ | |
| 305 | default: { |
| 306 | return "inline"; |
| 307 | } |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | /* |
| 312 | ** Add the Javascript file named by zFilename to the queue of requested |
| 313 | ** javascript resources, if it is not there already. Return 0 on |
| 314 | ** success, 1 if there is no such built-in file, or 2 if the queue is |
| 315 | ** full. |
| 316 | */ |
| 317 | int builtin_try_request_js(const char *zFilename){ |
| 318 | int i = builtin_file_index(zFilename); |
| 319 | int j; |
| 320 | if( i<0 ) return 1; |
| 321 | for(j=0; j<builtin.nReq; j++){ |
| 322 | if( builtin.aReq[j]==i ) return 0; /* Already queued or sent */ |
| 323 | } |
| 324 | if( builtin.nReq>=count(builtin.aReq) ) return 2; |
| 325 | builtin.aReq[builtin.nReq++] = i; |
| 326 | return 0; |
| 327 | } |
| 328 | |
| 329 | /* |
| 330 | ** The caller wants the Javascript file named by zFilename to be |
| 331 | ** included in the generated page. Add the file to the queue of |
| 332 | ** requested javascript resources, if it is not there already. |
| @@ -327,22 +345,16 @@ | |
| 345 | ** does not guarantee when the javascript will be included, and it |
| 346 | ** does not guarantee whether the javascript will be added inline or |
| 347 | ** delivered as a separate resource. |
| 348 | */ |
| 349 | void builtin_request_js(const char *zFilename){ |
| 350 | switch( builtin_try_request_js(zFilename) ){ |
| 351 | case 1: |
| 352 | fossil_panic("unknown javascript file: \"%s\"", zFilename); |
| 353 | case 2: |
| 354 | fossil_panic("too many javascript files requested"); |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | /* |
| 359 | ** Fulfill all pending requests for javascript files. |
| 360 | ** |
| 361 |
+61
-20
| --- src/cgi.c | ||
| +++ src/cgi.c | ||
| @@ -78,10 +78,11 @@ | ||
| 78 | 78 | # include <arpa/inet.h> |
| 79 | 79 | # include <sys/times.h> |
| 80 | 80 | # include <sys/time.h> |
| 81 | 81 | # include <sys/wait.h> |
| 82 | 82 | # include <sys/select.h> |
| 83 | +# include <sys/stat.h> | |
| 83 | 84 | # include <errno.h> |
| 84 | 85 | #endif |
| 85 | 86 | #ifdef __EMX__ |
| 86 | 87 | typedef int socklen_t; |
| 87 | 88 | #endif |
| @@ -490,14 +491,26 @@ | ||
| 490 | 491 | |
| 491 | 492 | if( g.fullHttpReply ){ |
| 492 | 493 | if( rangeEnd>0 |
| 493 | 494 | && iReplyStatus==200 |
| 494 | 495 | && fossil_strcmp(P("REQUEST_METHOD"),"GET")==0 |
| 496 | + && fossil_strcmp(zReplyMimeType,"application/x-fossil")!=0 | |
| 495 | 497 | ){ |
| 496 | - iReplyStatus = 206; | |
| 497 | - zReplyStatus = "Partial Content"; | |
| 498 | + int nContent = blob_size(&cgiContent[0]) + blob_size(&cgiContent[1]); | |
| 499 | + if( rangeStart>=nContent ){ | |
| 500 | + iReplyStatus = 416; | |
| 501 | + zReplyStatus = "Range Not Satisfiable"; | |
| 502 | + rangeEnd = nContent; | |
| 503 | + blob_reset(&cgiContent[0]); | |
| 504 | + blob_reset(&cgiContent[1]); | |
| 505 | + }else{ | |
| 506 | + iReplyStatus = 206; | |
| 507 | + zReplyStatus = "Partial Content"; | |
| 508 | + if( rangeEnd>nContent ) rangeEnd = nContent; | |
| 509 | + } | |
| 498 | 510 | } |
| 511 | + if( iReplyStatus!=206 ) rangeStart = 0; | |
| 499 | 512 | blob_appendf(&hdr, "HTTP/1.0 %d %s\r\n", iReplyStatus, zReplyStatus); |
| 500 | 513 | blob_appendf(&hdr, "Date: %s\r\n", cgi_rfc822_datestamp(time(0))); |
| 501 | 514 | blob_appendf(&hdr, "Connection: close\r\n"); |
| 502 | 515 | blob_appendf(&hdr, "X-UA-Compatible: IE=edge\r\n"); |
| 503 | 516 | }else{ |
| @@ -553,11 +566,11 @@ | ||
| 553 | 566 | if( fossil_strcmp(zReplyMimeType,"application/x-fossil")==0 ){ |
| 554 | 567 | cgi_combine_header_and_body(); |
| 555 | 568 | blob_compress(&cgiContent[0], &cgiContent[0]); |
| 556 | 569 | } |
| 557 | 570 | |
| 558 | - if( is_gzippable() && iReplyStatus!=206 ){ | |
| 571 | + if( is_gzippable() && iReplyStatus!=206 && iReplyStatus!=416 ){ | |
| 559 | 572 | int i; |
| 560 | 573 | gzip_begin(0); |
| 561 | 574 | for( i=0; i<2; i++ ){ |
| 562 | 575 | int size = blob_size(&cgiContent[i]); |
| 563 | 576 | if( size>0 ) gzip_step(blob_buffer(&cgiContent[i]), size); |
| @@ -570,10 +583,12 @@ | ||
| 570 | 583 | total_size = blob_size(&cgiContent[0]) + blob_size(&cgiContent[1]); |
| 571 | 584 | if( iReplyStatus==206 ){ |
| 572 | 585 | blob_appendf(&hdr, "Content-Range: bytes %d-%d/%d\r\n", |
| 573 | 586 | rangeStart, rangeEnd-1, total_size); |
| 574 | 587 | total_size = rangeEnd - rangeStart; |
| 588 | + }else if( iReplyStatus==416 ){ | |
| 589 | + blob_appendf(&hdr, "Content-Range: bytes */%d\r\n", rangeEnd); | |
| 575 | 590 | } |
| 576 | 591 | blob_appendf(&hdr, "Content-Length: %d\r\n", total_size); |
| 577 | 592 | }else{ |
| 578 | 593 | total_size = 0; |
| 579 | 594 | } |
| @@ -622,11 +637,18 @@ | ||
| 622 | 637 | const char *zURL, |
| 623 | 638 | int iStat, |
| 624 | 639 | const char *zStat |
| 625 | 640 | ){ |
| 626 | 641 | char *zLocation; |
| 642 | + char *zCopy = 0; | |
| 643 | + int i; | |
| 627 | 644 | CGIDEBUG(("redirect to %s\n", zURL)); |
| 645 | + for(i=0; zURL[i] && (unsigned char)zURL[i]>=' '; i++){} | |
| 646 | + if( zURL[i] ){ | |
| 647 | + zCopy = mprintf("%.*s", i, zURL); | |
| 648 | + zURL = zCopy; | |
| 649 | + } | |
| 628 | 650 | if( fossil_strncmp(zURL,"http:",5)==0 |
| 629 | 651 | || fossil_strncmp(zURL,"https:",6)==0 ){ |
| 630 | 652 | zLocation = mprintf("Location: %s\r\n", zURL); |
| 631 | 653 | }else if( *zURL=='/' ){ |
| 632 | 654 | int n1 = (int)strlen(g.zBaseURL); |
| @@ -634,10 +656,11 @@ | ||
| 634 | 656 | if( g.zBaseURL[n1-1]=='/' ) zURL++; |
| 635 | 657 | zLocation = mprintf("Location: %.*s%s\r\n", n1-n2, g.zBaseURL, zURL); |
| 636 | 658 | }else{ |
| 637 | 659 | zLocation = mprintf("Location: %s/%s\r\n", g.zBaseURL, zURL); |
| 638 | 660 | } |
| 661 | + fossil_free(zCopy); | |
| 639 | 662 | cgi_append_header(zLocation); |
| 640 | 663 | cgi_reset_content(); |
| 641 | 664 | cgi_printf("<html>\n<p>Redirect to %h</p>\n</html>\n", zLocation); |
| 642 | 665 | cgi_set_status(iStat, zStat); |
| 643 | 666 | free(zLocation); |
| @@ -1135,11 +1158,11 @@ | ||
| 1135 | 1158 | *z = 0; |
| 1136 | 1159 | z++; |
| 1137 | 1160 | }else{ |
| 1138 | 1161 | if( i<mxArg-1 ){ azArg[i++] = z; } |
| 1139 | 1162 | while( *z && !fossil_isspace(*z) && *z!=';' && *z!='"' ){ z++; } |
| 1140 | - if( *z && *z!='"' ){ | |
| 1163 | + if( *z && (*z!='"' || z[1]==0) ){ | |
| 1141 | 1164 | *z = 0; |
| 1142 | 1165 | z++; |
| 1143 | 1166 | } |
| 1144 | 1167 | } |
| 1145 | 1168 | } |
| @@ -1263,10 +1286,11 @@ | ||
| 1263 | 1286 | json_err( FSL_JSON_E_INVALID_REQUEST, |
| 1264 | 1287 | "Request envelope must be a JSON Object (not array).", 1 ); |
| 1265 | 1288 | }else{ /* generic error message */ |
| 1266 | 1289 | json_err( FSL_JSON_E_INVALID_REQUEST, NULL, 1 ); |
| 1267 | 1290 | } |
| 1291 | + if( g.isHTTP ) cgi_reply(); | |
| 1268 | 1292 | fossil_exit( g.isHTTP ? 0 : 1); |
| 1269 | 1293 | } |
| 1270 | 1294 | #endif /* FOSSIL_ENABLE_JSON */ |
| 1271 | 1295 | |
| 1272 | 1296 | /* |
| @@ -1273,26 +1297,29 @@ | ||
| 1273 | 1297 | ** Log HTTP traffic to a file. Begin the log on first use. Close the log |
| 1274 | 1298 | ** when the argument is NULL. |
| 1275 | 1299 | */ |
| 1276 | 1300 | void cgi_trace(const char *z){ |
| 1277 | 1301 | static FILE *pLog = 0; |
| 1302 | + static char zFile[50]; | |
| 1278 | 1303 | if( g.fHttpTrace==0 ) return; |
| 1279 | 1304 | if( z==0 ){ |
| 1280 | 1305 | if( pLog ) fclose(pLog); |
| 1281 | 1306 | pLog = 0; |
| 1282 | 1307 | return; |
| 1283 | 1308 | } |
| 1284 | 1309 | if( pLog==0 ){ |
| 1285 | - char zFile[50]; | |
| 1310 | + const char *zMode = zFile[0] ? "ab" : "wb"; | |
| 1311 | + if( zFile[0]==0 ){ | |
| 1286 | 1312 | #if defined(_WIN32) |
| 1287 | - unsigned r; | |
| 1288 | - sqlite3_randomness(sizeof(r), &r); | |
| 1289 | - sqlite3_snprintf(sizeof(zFile), zFile, "httplog-%08x.txt", r); | |
| 1313 | + unsigned r; | |
| 1314 | + sqlite3_randomness(sizeof(r), &r); | |
| 1315 | + sqlite3_snprintf(sizeof(zFile), zFile, "httplog-%08x.txt", r); | |
| 1290 | 1316 | #else |
| 1291 | - sqlite3_snprintf(sizeof(zFile), zFile, "httplog-%05d.txt", getpid()); | |
| 1317 | + sqlite3_snprintf(sizeof(zFile), zFile, "httplog-%05d.txt", getpid()); | |
| 1292 | 1318 | #endif |
| 1293 | - pLog = fossil_fopen(zFile, "wb"); | |
| 1319 | + } | |
| 1320 | + pLog = fossil_fopen(zFile, zMode); | |
| 1294 | 1321 | if( pLog ){ |
| 1295 | 1322 | fprintf(stderr, "# open log on %s\n", zFile); |
| 1296 | 1323 | }else{ |
| 1297 | 1324 | fprintf(stderr, "# failed to open %s\n", zFile); |
| 1298 | 1325 | return; |
| @@ -1837,11 +1864,11 @@ | ||
| 1837 | 1864 | int cgi_all(const char *z, ...){ |
| 1838 | 1865 | va_list ap; |
| 1839 | 1866 | char *z2; |
| 1840 | 1867 | if( cgi_parameter(z,0)==0 ) return 0; |
| 1841 | 1868 | va_start(ap, z); |
| 1842 | - while( (z2 = va_arg(ap, char*))==0 ){ | |
| 1869 | + while( (z2 = va_arg(ap, char*))!=0 ){ | |
| 1843 | 1870 | if( cgi_parameter(z2,0)==0 ) return 0; |
| 1844 | 1871 | } |
| 1845 | 1872 | va_end(ap); |
| 1846 | 1873 | return 1; |
| 1847 | 1874 | } |
| @@ -2267,15 +2294,21 @@ | ||
| 2267 | 2294 | if( zIpAddr!=0 ){ |
| 2268 | 2295 | g.zIpAddr = fossil_strdup(zIpAddr); |
| 2269 | 2296 | cgi_replace_parameter("REMOTE_ADDR", g.zIpAddr); |
| 2270 | 2297 | } |
| 2271 | 2298 | }else if( fossil_strcmp(zFieldName,"range:")==0 ){ |
| 2272 | - int x1 = 0; | |
| 2273 | - int x2 = 0; | |
| 2274 | - if( sscanf(zVal,"bytes=%d-%d",&x1,&x2)==2 && x1>=0 && x1<=x2 ){ | |
| 2275 | - rangeStart = x1; | |
| 2276 | - rangeEnd = x2+1; | |
| 2299 | + sqlite3_int64 x1, x2; | |
| 2300 | + char *zEnd; | |
| 2301 | + if( strncmp(zVal,"bytes=",6)==0 && fossil_isdigit(zVal[6]) ){ | |
| 2302 | + x1 = strtoll(&zVal[6], &zEnd, 10); | |
| 2303 | + if( zEnd[0]=='-' && fossil_isdigit(zEnd[1]) ){ | |
| 2304 | + x2 = strtoll(&zEnd[1], 0, 10); | |
| 2305 | + if( x1<=x2 && x2<0x7fffffff ){ | |
| 2306 | + rangeStart = (int)x1; | |
| 2307 | + rangeEnd = (int)x2 + 1; | |
| 2308 | + } | |
| 2309 | + } | |
| 2277 | 2310 | } |
| 2278 | 2311 | } |
| 2279 | 2312 | } |
| 2280 | 2313 | cgi_setenv("REQUEST_SCHEME",zScheme); |
| 2281 | 2314 | cgi_init(); |
| @@ -2618,10 +2651,12 @@ | ||
| 2618 | 2651 | struct sockaddr_in6 inaddr6; /* Address for IPv6 */ |
| 2619 | 2652 | struct sockaddr_in inaddr4; /* Address for IPv4 */ |
| 2620 | 2653 | struct sockaddr_un uxaddr; /* The address for unix-domain sockets */ |
| 2621 | 2654 | int opt = 1; /* setsockopt flag */ |
| 2622 | 2655 | int rc; /* Result code from system calls */ |
| 2656 | + mode_t mSock = 0660; /* Permissions for a unix-domain socket */ | |
| 2657 | + mode_t mOld; /* Saved umask */ | |
| 2623 | 2658 | int iPort = mnPort; /* Port to try to use */ |
| 2624 | 2659 | const char *zRequestType; /* Type of requests to listen for */ |
| 2625 | 2660 | |
| 2626 | 2661 | |
| 2627 | 2662 | if( flags & HTTP_SERVER_SCGI ){ |
| @@ -2661,17 +2696,23 @@ | ||
| 2661 | 2696 | mxListen = listen4; |
| 2662 | 2697 | listen6 = -1; |
| 2663 | 2698 | |
| 2664 | 2699 | /* Set the access permission for the new socket. Default to 0660. |
| 2665 | 2700 | ** But use an alternative specified by --socket-mode if available. |
| 2666 | - ** Do this before bind() to avoid a race condition. */ | |
| 2701 | + ** Set it through the umask that bind() uses to avoid a race | |
| 2702 | + ** condition. */ | |
| 2667 | 2703 | if( g.zSockMode ){ |
| 2668 | - file_set_mode(g.zSockName, listen4, g.zSockMode, 0); | |
| 2669 | - }else{ | |
| 2670 | - file_set_mode(g.zSockName, listen4, "0660", 1); | |
| 2704 | + char *zEnd = 0; | |
| 2705 | + mSock = (mode_t)strtol(g.zSockMode, &zEnd, 0); | |
| 2706 | + if( zEnd[0] ){ | |
| 2707 | + fossil_fatal("cannot change permissions on %s to \"%s\"", | |
| 2708 | + g.zSockName, g.zSockMode); | |
| 2709 | + } | |
| 2671 | 2710 | } |
| 2711 | + mOld = umask(~mSock & 0777); | |
| 2672 | 2712 | rc = bind(listen4, (struct sockaddr*)&uxaddr, sizeof(uxaddr)); |
| 2713 | + umask(mOld); | |
| 2673 | 2714 | /* Set the owner of the socket if requested by --socket-owner. This |
| 2674 | 2715 | ** must wait until after bind(), after the filesystem object has been |
| 2675 | 2716 | ** created. See https://lkml.org/lkml/2004/11/1/84 and |
| 2676 | 2717 | ** https://fossil-scm.org/forum/forumpost/7517680ef9684c57 */ |
| 2677 | 2718 | if( g.zSockOwner ){ |
| 2678 | 2719 |
| --- src/cgi.c | |
| +++ src/cgi.c | |
| @@ -78,10 +78,11 @@ | |
| 78 | # include <arpa/inet.h> |
| 79 | # include <sys/times.h> |
| 80 | # include <sys/time.h> |
| 81 | # include <sys/wait.h> |
| 82 | # include <sys/select.h> |
| 83 | # include <errno.h> |
| 84 | #endif |
| 85 | #ifdef __EMX__ |
| 86 | typedef int socklen_t; |
| 87 | #endif |
| @@ -490,14 +491,26 @@ | |
| 490 | |
| 491 | if( g.fullHttpReply ){ |
| 492 | if( rangeEnd>0 |
| 493 | && iReplyStatus==200 |
| 494 | && fossil_strcmp(P("REQUEST_METHOD"),"GET")==0 |
| 495 | ){ |
| 496 | iReplyStatus = 206; |
| 497 | zReplyStatus = "Partial Content"; |
| 498 | } |
| 499 | blob_appendf(&hdr, "HTTP/1.0 %d %s\r\n", iReplyStatus, zReplyStatus); |
| 500 | blob_appendf(&hdr, "Date: %s\r\n", cgi_rfc822_datestamp(time(0))); |
| 501 | blob_appendf(&hdr, "Connection: close\r\n"); |
| 502 | blob_appendf(&hdr, "X-UA-Compatible: IE=edge\r\n"); |
| 503 | }else{ |
| @@ -553,11 +566,11 @@ | |
| 553 | if( fossil_strcmp(zReplyMimeType,"application/x-fossil")==0 ){ |
| 554 | cgi_combine_header_and_body(); |
| 555 | blob_compress(&cgiContent[0], &cgiContent[0]); |
| 556 | } |
| 557 | |
| 558 | if( is_gzippable() && iReplyStatus!=206 ){ |
| 559 | int i; |
| 560 | gzip_begin(0); |
| 561 | for( i=0; i<2; i++ ){ |
| 562 | int size = blob_size(&cgiContent[i]); |
| 563 | if( size>0 ) gzip_step(blob_buffer(&cgiContent[i]), size); |
| @@ -570,10 +583,12 @@ | |
| 570 | total_size = blob_size(&cgiContent[0]) + blob_size(&cgiContent[1]); |
| 571 | if( iReplyStatus==206 ){ |
| 572 | blob_appendf(&hdr, "Content-Range: bytes %d-%d/%d\r\n", |
| 573 | rangeStart, rangeEnd-1, total_size); |
| 574 | total_size = rangeEnd - rangeStart; |
| 575 | } |
| 576 | blob_appendf(&hdr, "Content-Length: %d\r\n", total_size); |
| 577 | }else{ |
| 578 | total_size = 0; |
| 579 | } |
| @@ -622,11 +637,18 @@ | |
| 622 | const char *zURL, |
| 623 | int iStat, |
| 624 | const char *zStat |
| 625 | ){ |
| 626 | char *zLocation; |
| 627 | CGIDEBUG(("redirect to %s\n", zURL)); |
| 628 | if( fossil_strncmp(zURL,"http:",5)==0 |
| 629 | || fossil_strncmp(zURL,"https:",6)==0 ){ |
| 630 | zLocation = mprintf("Location: %s\r\n", zURL); |
| 631 | }else if( *zURL=='/' ){ |
| 632 | int n1 = (int)strlen(g.zBaseURL); |
| @@ -634,10 +656,11 @@ | |
| 634 | if( g.zBaseURL[n1-1]=='/' ) zURL++; |
| 635 | zLocation = mprintf("Location: %.*s%s\r\n", n1-n2, g.zBaseURL, zURL); |
| 636 | }else{ |
| 637 | zLocation = mprintf("Location: %s/%s\r\n", g.zBaseURL, zURL); |
| 638 | } |
| 639 | cgi_append_header(zLocation); |
| 640 | cgi_reset_content(); |
| 641 | cgi_printf("<html>\n<p>Redirect to %h</p>\n</html>\n", zLocation); |
| 642 | cgi_set_status(iStat, zStat); |
| 643 | free(zLocation); |
| @@ -1135,11 +1158,11 @@ | |
| 1135 | *z = 0; |
| 1136 | z++; |
| 1137 | }else{ |
| 1138 | if( i<mxArg-1 ){ azArg[i++] = z; } |
| 1139 | while( *z && !fossil_isspace(*z) && *z!=';' && *z!='"' ){ z++; } |
| 1140 | if( *z && *z!='"' ){ |
| 1141 | *z = 0; |
| 1142 | z++; |
| 1143 | } |
| 1144 | } |
| 1145 | } |
| @@ -1263,10 +1286,11 @@ | |
| 1263 | json_err( FSL_JSON_E_INVALID_REQUEST, |
| 1264 | "Request envelope must be a JSON Object (not array).", 1 ); |
| 1265 | }else{ /* generic error message */ |
| 1266 | json_err( FSL_JSON_E_INVALID_REQUEST, NULL, 1 ); |
| 1267 | } |
| 1268 | fossil_exit( g.isHTTP ? 0 : 1); |
| 1269 | } |
| 1270 | #endif /* FOSSIL_ENABLE_JSON */ |
| 1271 | |
| 1272 | /* |
| @@ -1273,26 +1297,29 @@ | |
| 1273 | ** Log HTTP traffic to a file. Begin the log on first use. Close the log |
| 1274 | ** when the argument is NULL. |
| 1275 | */ |
| 1276 | void cgi_trace(const char *z){ |
| 1277 | static FILE *pLog = 0; |
| 1278 | if( g.fHttpTrace==0 ) return; |
| 1279 | if( z==0 ){ |
| 1280 | if( pLog ) fclose(pLog); |
| 1281 | pLog = 0; |
| 1282 | return; |
| 1283 | } |
| 1284 | if( pLog==0 ){ |
| 1285 | char zFile[50]; |
| 1286 | #if defined(_WIN32) |
| 1287 | unsigned r; |
| 1288 | sqlite3_randomness(sizeof(r), &r); |
| 1289 | sqlite3_snprintf(sizeof(zFile), zFile, "httplog-%08x.txt", r); |
| 1290 | #else |
| 1291 | sqlite3_snprintf(sizeof(zFile), zFile, "httplog-%05d.txt", getpid()); |
| 1292 | #endif |
| 1293 | pLog = fossil_fopen(zFile, "wb"); |
| 1294 | if( pLog ){ |
| 1295 | fprintf(stderr, "# open log on %s\n", zFile); |
| 1296 | }else{ |
| 1297 | fprintf(stderr, "# failed to open %s\n", zFile); |
| 1298 | return; |
| @@ -1837,11 +1864,11 @@ | |
| 1837 | int cgi_all(const char *z, ...){ |
| 1838 | va_list ap; |
| 1839 | char *z2; |
| 1840 | if( cgi_parameter(z,0)==0 ) return 0; |
| 1841 | va_start(ap, z); |
| 1842 | while( (z2 = va_arg(ap, char*))==0 ){ |
| 1843 | if( cgi_parameter(z2,0)==0 ) return 0; |
| 1844 | } |
| 1845 | va_end(ap); |
| 1846 | return 1; |
| 1847 | } |
| @@ -2267,15 +2294,21 @@ | |
| 2267 | if( zIpAddr!=0 ){ |
| 2268 | g.zIpAddr = fossil_strdup(zIpAddr); |
| 2269 | cgi_replace_parameter("REMOTE_ADDR", g.zIpAddr); |
| 2270 | } |
| 2271 | }else if( fossil_strcmp(zFieldName,"range:")==0 ){ |
| 2272 | int x1 = 0; |
| 2273 | int x2 = 0; |
| 2274 | if( sscanf(zVal,"bytes=%d-%d",&x1,&x2)==2 && x1>=0 && x1<=x2 ){ |
| 2275 | rangeStart = x1; |
| 2276 | rangeEnd = x2+1; |
| 2277 | } |
| 2278 | } |
| 2279 | } |
| 2280 | cgi_setenv("REQUEST_SCHEME",zScheme); |
| 2281 | cgi_init(); |
| @@ -2618,10 +2651,12 @@ | |
| 2618 | struct sockaddr_in6 inaddr6; /* Address for IPv6 */ |
| 2619 | struct sockaddr_in inaddr4; /* Address for IPv4 */ |
| 2620 | struct sockaddr_un uxaddr; /* The address for unix-domain sockets */ |
| 2621 | int opt = 1; /* setsockopt flag */ |
| 2622 | int rc; /* Result code from system calls */ |
| 2623 | int iPort = mnPort; /* Port to try to use */ |
| 2624 | const char *zRequestType; /* Type of requests to listen for */ |
| 2625 | |
| 2626 | |
| 2627 | if( flags & HTTP_SERVER_SCGI ){ |
| @@ -2661,17 +2696,23 @@ | |
| 2661 | mxListen = listen4; |
| 2662 | listen6 = -1; |
| 2663 | |
| 2664 | /* Set the access permission for the new socket. Default to 0660. |
| 2665 | ** But use an alternative specified by --socket-mode if available. |
| 2666 | ** Do this before bind() to avoid a race condition. */ |
| 2667 | if( g.zSockMode ){ |
| 2668 | file_set_mode(g.zSockName, listen4, g.zSockMode, 0); |
| 2669 | }else{ |
| 2670 | file_set_mode(g.zSockName, listen4, "0660", 1); |
| 2671 | } |
| 2672 | rc = bind(listen4, (struct sockaddr*)&uxaddr, sizeof(uxaddr)); |
| 2673 | /* Set the owner of the socket if requested by --socket-owner. This |
| 2674 | ** must wait until after bind(), after the filesystem object has been |
| 2675 | ** created. See https://lkml.org/lkml/2004/11/1/84 and |
| 2676 | ** https://fossil-scm.org/forum/forumpost/7517680ef9684c57 */ |
| 2677 | if( g.zSockOwner ){ |
| 2678 |
| --- src/cgi.c | |
| +++ src/cgi.c | |
| @@ -78,10 +78,11 @@ | |
| 78 | # include <arpa/inet.h> |
| 79 | # include <sys/times.h> |
| 80 | # include <sys/time.h> |
| 81 | # include <sys/wait.h> |
| 82 | # include <sys/select.h> |
| 83 | # include <sys/stat.h> |
| 84 | # include <errno.h> |
| 85 | #endif |
| 86 | #ifdef __EMX__ |
| 87 | typedef int socklen_t; |
| 88 | #endif |
| @@ -490,14 +491,26 @@ | |
| 491 | |
| 492 | if( g.fullHttpReply ){ |
| 493 | if( rangeEnd>0 |
| 494 | && iReplyStatus==200 |
| 495 | && fossil_strcmp(P("REQUEST_METHOD"),"GET")==0 |
| 496 | && fossil_strcmp(zReplyMimeType,"application/x-fossil")!=0 |
| 497 | ){ |
| 498 | int nContent = blob_size(&cgiContent[0]) + blob_size(&cgiContent[1]); |
| 499 | if( rangeStart>=nContent ){ |
| 500 | iReplyStatus = 416; |
| 501 | zReplyStatus = "Range Not Satisfiable"; |
| 502 | rangeEnd = nContent; |
| 503 | blob_reset(&cgiContent[0]); |
| 504 | blob_reset(&cgiContent[1]); |
| 505 | }else{ |
| 506 | iReplyStatus = 206; |
| 507 | zReplyStatus = "Partial Content"; |
| 508 | if( rangeEnd>nContent ) rangeEnd = nContent; |
| 509 | } |
| 510 | } |
| 511 | if( iReplyStatus!=206 ) rangeStart = 0; |
| 512 | blob_appendf(&hdr, "HTTP/1.0 %d %s\r\n", iReplyStatus, zReplyStatus); |
| 513 | blob_appendf(&hdr, "Date: %s\r\n", cgi_rfc822_datestamp(time(0))); |
| 514 | blob_appendf(&hdr, "Connection: close\r\n"); |
| 515 | blob_appendf(&hdr, "X-UA-Compatible: IE=edge\r\n"); |
| 516 | }else{ |
| @@ -553,11 +566,11 @@ | |
| 566 | if( fossil_strcmp(zReplyMimeType,"application/x-fossil")==0 ){ |
| 567 | cgi_combine_header_and_body(); |
| 568 | blob_compress(&cgiContent[0], &cgiContent[0]); |
| 569 | } |
| 570 | |
| 571 | if( is_gzippable() && iReplyStatus!=206 && iReplyStatus!=416 ){ |
| 572 | int i; |
| 573 | gzip_begin(0); |
| 574 | for( i=0; i<2; i++ ){ |
| 575 | int size = blob_size(&cgiContent[i]); |
| 576 | if( size>0 ) gzip_step(blob_buffer(&cgiContent[i]), size); |
| @@ -570,10 +583,12 @@ | |
| 583 | total_size = blob_size(&cgiContent[0]) + blob_size(&cgiContent[1]); |
| 584 | if( iReplyStatus==206 ){ |
| 585 | blob_appendf(&hdr, "Content-Range: bytes %d-%d/%d\r\n", |
| 586 | rangeStart, rangeEnd-1, total_size); |
| 587 | total_size = rangeEnd - rangeStart; |
| 588 | }else if( iReplyStatus==416 ){ |
| 589 | blob_appendf(&hdr, "Content-Range: bytes */%d\r\n", rangeEnd); |
| 590 | } |
| 591 | blob_appendf(&hdr, "Content-Length: %d\r\n", total_size); |
| 592 | }else{ |
| 593 | total_size = 0; |
| 594 | } |
| @@ -622,11 +637,18 @@ | |
| 637 | const char *zURL, |
| 638 | int iStat, |
| 639 | const char *zStat |
| 640 | ){ |
| 641 | char *zLocation; |
| 642 | char *zCopy = 0; |
| 643 | int i; |
| 644 | CGIDEBUG(("redirect to %s\n", zURL)); |
| 645 | for(i=0; zURL[i] && (unsigned char)zURL[i]>=' '; i++){} |
| 646 | if( zURL[i] ){ |
| 647 | zCopy = mprintf("%.*s", i, zURL); |
| 648 | zURL = zCopy; |
| 649 | } |
| 650 | if( fossil_strncmp(zURL,"http:",5)==0 |
| 651 | || fossil_strncmp(zURL,"https:",6)==0 ){ |
| 652 | zLocation = mprintf("Location: %s\r\n", zURL); |
| 653 | }else if( *zURL=='/' ){ |
| 654 | int n1 = (int)strlen(g.zBaseURL); |
| @@ -634,10 +656,11 @@ | |
| 656 | if( g.zBaseURL[n1-1]=='/' ) zURL++; |
| 657 | zLocation = mprintf("Location: %.*s%s\r\n", n1-n2, g.zBaseURL, zURL); |
| 658 | }else{ |
| 659 | zLocation = mprintf("Location: %s/%s\r\n", g.zBaseURL, zURL); |
| 660 | } |
| 661 | fossil_free(zCopy); |
| 662 | cgi_append_header(zLocation); |
| 663 | cgi_reset_content(); |
| 664 | cgi_printf("<html>\n<p>Redirect to %h</p>\n</html>\n", zLocation); |
| 665 | cgi_set_status(iStat, zStat); |
| 666 | free(zLocation); |
| @@ -1135,11 +1158,11 @@ | |
| 1158 | *z = 0; |
| 1159 | z++; |
| 1160 | }else{ |
| 1161 | if( i<mxArg-1 ){ azArg[i++] = z; } |
| 1162 | while( *z && !fossil_isspace(*z) && *z!=';' && *z!='"' ){ z++; } |
| 1163 | if( *z && (*z!='"' || z[1]==0) ){ |
| 1164 | *z = 0; |
| 1165 | z++; |
| 1166 | } |
| 1167 | } |
| 1168 | } |
| @@ -1263,10 +1286,11 @@ | |
| 1286 | json_err( FSL_JSON_E_INVALID_REQUEST, |
| 1287 | "Request envelope must be a JSON Object (not array).", 1 ); |
| 1288 | }else{ /* generic error message */ |
| 1289 | json_err( FSL_JSON_E_INVALID_REQUEST, NULL, 1 ); |
| 1290 | } |
| 1291 | if( g.isHTTP ) cgi_reply(); |
| 1292 | fossil_exit( g.isHTTP ? 0 : 1); |
| 1293 | } |
| 1294 | #endif /* FOSSIL_ENABLE_JSON */ |
| 1295 | |
| 1296 | /* |
| @@ -1273,26 +1297,29 @@ | |
| 1297 | ** Log HTTP traffic to a file. Begin the log on first use. Close the log |
| 1298 | ** when the argument is NULL. |
| 1299 | */ |
| 1300 | void cgi_trace(const char *z){ |
| 1301 | static FILE *pLog = 0; |
| 1302 | static char zFile[50]; |
| 1303 | if( g.fHttpTrace==0 ) return; |
| 1304 | if( z==0 ){ |
| 1305 | if( pLog ) fclose(pLog); |
| 1306 | pLog = 0; |
| 1307 | return; |
| 1308 | } |
| 1309 | if( pLog==0 ){ |
| 1310 | const char *zMode = zFile[0] ? "ab" : "wb"; |
| 1311 | if( zFile[0]==0 ){ |
| 1312 | #if defined(_WIN32) |
| 1313 | unsigned r; |
| 1314 | sqlite3_randomness(sizeof(r), &r); |
| 1315 | sqlite3_snprintf(sizeof(zFile), zFile, "httplog-%08x.txt", r); |
| 1316 | #else |
| 1317 | sqlite3_snprintf(sizeof(zFile), zFile, "httplog-%05d.txt", getpid()); |
| 1318 | #endif |
| 1319 | } |
| 1320 | pLog = fossil_fopen(zFile, zMode); |
| 1321 | if( pLog ){ |
| 1322 | fprintf(stderr, "# open log on %s\n", zFile); |
| 1323 | }else{ |
| 1324 | fprintf(stderr, "# failed to open %s\n", zFile); |
| 1325 | return; |
| @@ -1837,11 +1864,11 @@ | |
| 1864 | int cgi_all(const char *z, ...){ |
| 1865 | va_list ap; |
| 1866 | char *z2; |
| 1867 | if( cgi_parameter(z,0)==0 ) return 0; |
| 1868 | va_start(ap, z); |
| 1869 | while( (z2 = va_arg(ap, char*))!=0 ){ |
| 1870 | if( cgi_parameter(z2,0)==0 ) return 0; |
| 1871 | } |
| 1872 | va_end(ap); |
| 1873 | return 1; |
| 1874 | } |
| @@ -2267,15 +2294,21 @@ | |
| 2294 | if( zIpAddr!=0 ){ |
| 2295 | g.zIpAddr = fossil_strdup(zIpAddr); |
| 2296 | cgi_replace_parameter("REMOTE_ADDR", g.zIpAddr); |
| 2297 | } |
| 2298 | }else if( fossil_strcmp(zFieldName,"range:")==0 ){ |
| 2299 | sqlite3_int64 x1, x2; |
| 2300 | char *zEnd; |
| 2301 | if( strncmp(zVal,"bytes=",6)==0 && fossil_isdigit(zVal[6]) ){ |
| 2302 | x1 = strtoll(&zVal[6], &zEnd, 10); |
| 2303 | if( zEnd[0]=='-' && fossil_isdigit(zEnd[1]) ){ |
| 2304 | x2 = strtoll(&zEnd[1], 0, 10); |
| 2305 | if( x1<=x2 && x2<0x7fffffff ){ |
| 2306 | rangeStart = (int)x1; |
| 2307 | rangeEnd = (int)x2 + 1; |
| 2308 | } |
| 2309 | } |
| 2310 | } |
| 2311 | } |
| 2312 | } |
| 2313 | cgi_setenv("REQUEST_SCHEME",zScheme); |
| 2314 | cgi_init(); |
| @@ -2618,10 +2651,12 @@ | |
| 2651 | struct sockaddr_in6 inaddr6; /* Address for IPv6 */ |
| 2652 | struct sockaddr_in inaddr4; /* Address for IPv4 */ |
| 2653 | struct sockaddr_un uxaddr; /* The address for unix-domain sockets */ |
| 2654 | int opt = 1; /* setsockopt flag */ |
| 2655 | int rc; /* Result code from system calls */ |
| 2656 | mode_t mSock = 0660; /* Permissions for a unix-domain socket */ |
| 2657 | mode_t mOld; /* Saved umask */ |
| 2658 | int iPort = mnPort; /* Port to try to use */ |
| 2659 | const char *zRequestType; /* Type of requests to listen for */ |
| 2660 | |
| 2661 | |
| 2662 | if( flags & HTTP_SERVER_SCGI ){ |
| @@ -2661,17 +2696,23 @@ | |
| 2696 | mxListen = listen4; |
| 2697 | listen6 = -1; |
| 2698 | |
| 2699 | /* Set the access permission for the new socket. Default to 0660. |
| 2700 | ** But use an alternative specified by --socket-mode if available. |
| 2701 | ** Set it through the umask that bind() uses to avoid a race |
| 2702 | ** condition. */ |
| 2703 | if( g.zSockMode ){ |
| 2704 | char *zEnd = 0; |
| 2705 | mSock = (mode_t)strtol(g.zSockMode, &zEnd, 0); |
| 2706 | if( zEnd[0] ){ |
| 2707 | fossil_fatal("cannot change permissions on %s to \"%s\"", |
| 2708 | g.zSockName, g.zSockMode); |
| 2709 | } |
| 2710 | } |
| 2711 | mOld = umask(~mSock & 0777); |
| 2712 | rc = bind(listen4, (struct sockaddr*)&uxaddr, sizeof(uxaddr)); |
| 2713 | umask(mOld); |
| 2714 | /* Set the owner of the socket if requested by --socket-owner. This |
| 2715 | ** must wait until after bind(), after the filesystem object has been |
| 2716 | ** created. See https://lkml.org/lkml/2004/11/1/84 and |
| 2717 | ** https://fossil-scm.org/forum/forumpost/7517680ef9684c57 */ |
| 2718 | if( g.zSockOwner ){ |
| 2719 |
+2
-4
| --- src/export.c | ||
| +++ src/export.c | ||
| @@ -309,14 +309,12 @@ | ||
| 309 | 309 | if( !cur_tok || strlen(cur_tok)<2 ){ |
| 310 | 310 | return -1; |
| 311 | 311 | } |
| 312 | 312 | mark->rid = atoi(&cur_tok[1]); |
| 313 | 313 | type_ = cur_tok[0]; |
| 314 | - if( type_!='c' && type_!='b' ){ | |
| 315 | - /* This is probably a blob mark */ | |
| 316 | - mark->name = NULL; | |
| 317 | - return 0; | |
| 314 | + if( (type_!='c' && type_!='b') || mark->rid<=0 ){ | |
| 315 | + return -1; | |
| 318 | 316 | } |
| 319 | 317 | |
| 320 | 318 | cur_tok = strtok(NULL, " \t"); |
| 321 | 319 | if( !cur_tok ){ |
| 322 | 320 | /* This mark was generated by an older version of Fossil and doesn't |
| 323 | 321 |
| --- src/export.c | |
| +++ src/export.c | |
| @@ -309,14 +309,12 @@ | |
| 309 | if( !cur_tok || strlen(cur_tok)<2 ){ |
| 310 | return -1; |
| 311 | } |
| 312 | mark->rid = atoi(&cur_tok[1]); |
| 313 | type_ = cur_tok[0]; |
| 314 | if( type_!='c' && type_!='b' ){ |
| 315 | /* This is probably a blob mark */ |
| 316 | mark->name = NULL; |
| 317 | return 0; |
| 318 | } |
| 319 | |
| 320 | cur_tok = strtok(NULL, " \t"); |
| 321 | if( !cur_tok ){ |
| 322 | /* This mark was generated by an older version of Fossil and doesn't |
| 323 |
| --- src/export.c | |
| +++ src/export.c | |
| @@ -309,14 +309,12 @@ | |
| 309 | if( !cur_tok || strlen(cur_tok)<2 ){ |
| 310 | return -1; |
| 311 | } |
| 312 | mark->rid = atoi(&cur_tok[1]); |
| 313 | type_ = cur_tok[0]; |
| 314 | if( (type_!='c' && type_!='b') || mark->rid<=0 ){ |
| 315 | return -1; |
| 316 | } |
| 317 | |
| 318 | cur_tok = strtok(NULL, " \t"); |
| 319 | if( !cur_tok ){ |
| 320 | /* This mark was generated by an older version of Fossil and doesn't |
| 321 |
-15
| --- src/file.c | ||
| +++ src/file.c | ||
| @@ -765,25 +765,10 @@ | ||
| 765 | 765 | iMTime = file_mtime(zFile, RepoFILE); |
| 766 | 766 | zDate = db_text(0, "SELECT datetime(%lld, 'unixepoch')", iMTime); |
| 767 | 767 | fossil_print("Set mtime of \"%s\" to %s (%lld)\n", zFile, zDate, iMTime); |
| 768 | 768 | } |
| 769 | 769 | |
| 770 | -/* | |
| 771 | -** Change access permissions on a file. | |
| 772 | -*/ | |
| 773 | -void file_set_mode(const char *zFN, int fd, const char *zMode, int bNoErr){ | |
| 774 | -#if !defined(_WIN32) | |
| 775 | - mode_t m; | |
| 776 | - char *zEnd = 0; | |
| 777 | - m = strtol(zMode, &zEnd, 0); | |
| 778 | - if( (zEnd[0] || fchmod(fd, m)) && !bNoErr ){ | |
| 779 | - fossil_fatal("cannot change permissions on %s to \"%s\"", | |
| 780 | - zFN, zMode); | |
| 781 | - } | |
| 782 | -#endif | |
| 783 | -} | |
| 784 | - | |
| 785 | 770 | /* Change the owner of a file to zOwner. zOwner can be of the form |
| 786 | 771 | ** USER:GROUP. |
| 787 | 772 | */ |
| 788 | 773 | void file_set_owner(const char *zFN, int fd, const char *zOwner){ |
| 789 | 774 | #if !defined(_WIN32) |
| 790 | 775 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -765,25 +765,10 @@ | |
| 765 | iMTime = file_mtime(zFile, RepoFILE); |
| 766 | zDate = db_text(0, "SELECT datetime(%lld, 'unixepoch')", iMTime); |
| 767 | fossil_print("Set mtime of \"%s\" to %s (%lld)\n", zFile, zDate, iMTime); |
| 768 | } |
| 769 | |
| 770 | /* |
| 771 | ** Change access permissions on a file. |
| 772 | */ |
| 773 | void file_set_mode(const char *zFN, int fd, const char *zMode, int bNoErr){ |
| 774 | #if !defined(_WIN32) |
| 775 | mode_t m; |
| 776 | char *zEnd = 0; |
| 777 | m = strtol(zMode, &zEnd, 0); |
| 778 | if( (zEnd[0] || fchmod(fd, m)) && !bNoErr ){ |
| 779 | fossil_fatal("cannot change permissions on %s to \"%s\"", |
| 780 | zFN, zMode); |
| 781 | } |
| 782 | #endif |
| 783 | } |
| 784 | |
| 785 | /* Change the owner of a file to zOwner. zOwner can be of the form |
| 786 | ** USER:GROUP. |
| 787 | */ |
| 788 | void file_set_owner(const char *zFN, int fd, const char *zOwner){ |
| 789 | #if !defined(_WIN32) |
| 790 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -765,25 +765,10 @@ | |
| 765 | iMTime = file_mtime(zFile, RepoFILE); |
| 766 | zDate = db_text(0, "SELECT datetime(%lld, 'unixepoch')", iMTime); |
| 767 | fossil_print("Set mtime of \"%s\" to %s (%lld)\n", zFile, zDate, iMTime); |
| 768 | } |
| 769 | |
| 770 | /* Change the owner of a file to zOwner. zOwner can be of the form |
| 771 | ** USER:GROUP. |
| 772 | */ |
| 773 | void file_set_owner(const char *zFN, int fd, const char *zOwner){ |
| 774 | #if !defined(_WIN32) |
| 775 |
+15
-6
| --- src/http.c | ||
| +++ src/http.c | ||
| @@ -86,11 +86,13 @@ | ||
| 86 | 86 | if( g.url.passwd ){ |
| 87 | 87 | zPw = g.url.passwd; |
| 88 | 88 | }else if( g.cgiOutput ){ |
| 89 | 89 | /* Password failure while doing a sync from the web interface */ |
| 90 | 90 | cgi_printf("*** incorrect or missing password for user %h\n", zLogin); |
| 91 | - zPw = 0; | |
| 91 | + blob_reset(&pw); | |
| 92 | + blob_reset(&nonce); | |
| 93 | + return; | |
| 92 | 94 | }else{ |
| 93 | 95 | /* Password failure while doing a sync from the command-line interface */ |
| 94 | 96 | url_prompt_for_password(); |
| 95 | 97 | zPw = g.url.passwd; |
| 96 | 98 | } |
| @@ -437,17 +439,19 @@ | ||
| 437 | 439 | ** It still might return a NULL pointer if for some reason it cannot |
| 438 | 440 | ** find and open the last http-reply-N.txt file. |
| 439 | 441 | */ |
| 440 | 442 | char *http_last_trace_reply(void){ |
| 441 | 443 | Blob x; |
| 442 | - int n; | |
| 443 | 444 | char *zFilename; |
| 444 | 445 | if( g.fHttpTrace==0 ) return 0; |
| 445 | 446 | zFilename = mprintf("http-reply-%d.txt", traceCnt); |
| 446 | - n = blob_read_from_file(&x, zFilename, ExtFILE); | |
| 447 | + if( file_size(zFilename, ExtFILE)<=0 ){ | |
| 448 | + fossil_free(zFilename); | |
| 449 | + return 0; | |
| 450 | + } | |
| 451 | + blob_read_from_file(&x, zFilename, ExtFILE); | |
| 447 | 452 | fossil_free(zFilename); |
| 448 | - if( n<=0 ) return 0; | |
| 449 | 453 | return blob_str(&x); |
| 450 | 454 | } |
| 451 | 455 | |
| 452 | 456 | /* |
| 453 | 457 | ** Return true if z is a valud extension according to RFC 9112 s 7.1.1. |
| @@ -721,10 +725,11 @@ | ||
| 721 | 725 | } |
| 722 | 726 | }else if( ( rc==301 || rc==302 || rc==307 || rc==308 ) && |
| 723 | 727 | fossil_strnicmp(zLine, "location:", 9)==0 ){ |
| 724 | 728 | int i, j; |
| 725 | 729 | int wasHttps; |
| 730 | + int wasProxy; | |
| 726 | 731 | int priorUrlFlags; |
| 727 | 732 | |
| 728 | 733 | if ( --maxRedirect == 0){ |
| 729 | 734 | if( (mHttpFlags & HTTP_QUIET)==0 ){ |
| 730 | 735 | fossil_warning("redirect limit exceeded"); |
| @@ -750,10 +755,11 @@ | ||
| 750 | 755 | &zLine[i]); |
| 751 | 756 | } |
| 752 | 757 | goto write_err; |
| 753 | 758 | } |
| 754 | 759 | wasHttps = g.url.isHttps; |
| 760 | + wasProxy = g.url.useProxy; | |
| 755 | 761 | priorUrlFlags = g.url.flags; |
| 756 | 762 | url_parse(&zLine[i], 0); |
| 757 | 763 | if( wasHttps && !g.url.isHttps ){ |
| 758 | 764 | if( (mHttpFlags & HTTP_QUIET)==0 ){ |
| 759 | 765 | fossil_warning("cannot redirect from HTTPS to HTTP"); |
| @@ -773,10 +779,11 @@ | ||
| 773 | 779 | g.zHttpAuth = get_httpauth(); |
| 774 | 780 | if( (rc==301 || rc==308) && (priorUrlFlags & URL_REMEMBER)!=0 ){ |
| 775 | 781 | g.url.flags |= URL_REMEMBER; |
| 776 | 782 | url_remember(); |
| 777 | 783 | } |
| 784 | + if( wasProxy ) url_enable_proxy(0); | |
| 778 | 785 | return http_exchange(pSend, pReply, mHttpFlags, |
| 779 | 786 | maxRedirect, zAltMimetype); |
| 780 | 787 | }else if( fossil_strnicmp(zLine, "content-type: ", 14)==0 ){ |
| 781 | 788 | if( fossil_strnicmp(&zLine[14], "application/x-fossil-debug", -1)==0 ){ |
| 782 | 789 | isCompressed = 0; |
| @@ -934,10 +941,11 @@ | ||
| 934 | 941 | iRecvLen = transport_receive(&g.url, blob_buffer(pReply), iLength); |
| 935 | 942 | if( mHttpFlags & HTTP_VERBOSE ){ |
| 936 | 943 | fossil_print("Reply received: %d of %d bytes\n", iRecvLen, iLength); |
| 937 | 944 | } |
| 938 | 945 | if( iRecvLen != iLength ){ |
| 946 | + blob_resize(pReply, iRecvLen); | |
| 939 | 947 | if( mHttpFlags & HTTP_QUIET ) goto write_err; |
| 940 | 948 | fossil_warning("response truncated: got %d bytes of %d", |
| 941 | 949 | iRecvLen, iLength); |
| 942 | 950 | goto write_err; |
| 943 | 951 | } |
| @@ -960,16 +968,17 @@ | ||
| 960 | 968 | } |
| 961 | 969 | if( isError ){ |
| 962 | 970 | char *z; |
| 963 | 971 | int i, j; |
| 964 | 972 | z = blob_str(pReply); |
| 965 | - for(i=j=0; z[i]; i++, j++){ | |
| 973 | + for(i=j=0; z[i]; i++){ | |
| 966 | 974 | if( z[i]=='<' ){ |
| 967 | 975 | while( z[i] && z[i]!='>' ) i++; |
| 968 | 976 | if( z[i]==0 ) break; |
| 977 | + }else{ | |
| 978 | + z[j++] = z[i]; | |
| 969 | 979 | } |
| 970 | - z[j] = z[i]; | |
| 971 | 980 | } |
| 972 | 981 | z[j] = 0; |
| 973 | 982 | if( mHttpFlags & HTTP_QUIET ){ |
| 974 | 983 | /* no-op */ |
| 975 | 984 | }else if( mHttpFlags & HTTP_VERBOSE ){ |
| 976 | 985 |
| --- src/http.c | |
| +++ src/http.c | |
| @@ -86,11 +86,13 @@ | |
| 86 | if( g.url.passwd ){ |
| 87 | zPw = g.url.passwd; |
| 88 | }else if( g.cgiOutput ){ |
| 89 | /* Password failure while doing a sync from the web interface */ |
| 90 | cgi_printf("*** incorrect or missing password for user %h\n", zLogin); |
| 91 | zPw = 0; |
| 92 | }else{ |
| 93 | /* Password failure while doing a sync from the command-line interface */ |
| 94 | url_prompt_for_password(); |
| 95 | zPw = g.url.passwd; |
| 96 | } |
| @@ -437,17 +439,19 @@ | |
| 437 | ** It still might return a NULL pointer if for some reason it cannot |
| 438 | ** find and open the last http-reply-N.txt file. |
| 439 | */ |
| 440 | char *http_last_trace_reply(void){ |
| 441 | Blob x; |
| 442 | int n; |
| 443 | char *zFilename; |
| 444 | if( g.fHttpTrace==0 ) return 0; |
| 445 | zFilename = mprintf("http-reply-%d.txt", traceCnt); |
| 446 | n = blob_read_from_file(&x, zFilename, ExtFILE); |
| 447 | fossil_free(zFilename); |
| 448 | if( n<=0 ) return 0; |
| 449 | return blob_str(&x); |
| 450 | } |
| 451 | |
| 452 | /* |
| 453 | ** Return true if z is a valud extension according to RFC 9112 s 7.1.1. |
| @@ -721,10 +725,11 @@ | |
| 721 | } |
| 722 | }else if( ( rc==301 || rc==302 || rc==307 || rc==308 ) && |
| 723 | fossil_strnicmp(zLine, "location:", 9)==0 ){ |
| 724 | int i, j; |
| 725 | int wasHttps; |
| 726 | int priorUrlFlags; |
| 727 | |
| 728 | if ( --maxRedirect == 0){ |
| 729 | if( (mHttpFlags & HTTP_QUIET)==0 ){ |
| 730 | fossil_warning("redirect limit exceeded"); |
| @@ -750,10 +755,11 @@ | |
| 750 | &zLine[i]); |
| 751 | } |
| 752 | goto write_err; |
| 753 | } |
| 754 | wasHttps = g.url.isHttps; |
| 755 | priorUrlFlags = g.url.flags; |
| 756 | url_parse(&zLine[i], 0); |
| 757 | if( wasHttps && !g.url.isHttps ){ |
| 758 | if( (mHttpFlags & HTTP_QUIET)==0 ){ |
| 759 | fossil_warning("cannot redirect from HTTPS to HTTP"); |
| @@ -773,10 +779,11 @@ | |
| 773 | g.zHttpAuth = get_httpauth(); |
| 774 | if( (rc==301 || rc==308) && (priorUrlFlags & URL_REMEMBER)!=0 ){ |
| 775 | g.url.flags |= URL_REMEMBER; |
| 776 | url_remember(); |
| 777 | } |
| 778 | return http_exchange(pSend, pReply, mHttpFlags, |
| 779 | maxRedirect, zAltMimetype); |
| 780 | }else if( fossil_strnicmp(zLine, "content-type: ", 14)==0 ){ |
| 781 | if( fossil_strnicmp(&zLine[14], "application/x-fossil-debug", -1)==0 ){ |
| 782 | isCompressed = 0; |
| @@ -934,10 +941,11 @@ | |
| 934 | iRecvLen = transport_receive(&g.url, blob_buffer(pReply), iLength); |
| 935 | if( mHttpFlags & HTTP_VERBOSE ){ |
| 936 | fossil_print("Reply received: %d of %d bytes\n", iRecvLen, iLength); |
| 937 | } |
| 938 | if( iRecvLen != iLength ){ |
| 939 | if( mHttpFlags & HTTP_QUIET ) goto write_err; |
| 940 | fossil_warning("response truncated: got %d bytes of %d", |
| 941 | iRecvLen, iLength); |
| 942 | goto write_err; |
| 943 | } |
| @@ -960,16 +968,17 @@ | |
| 960 | } |
| 961 | if( isError ){ |
| 962 | char *z; |
| 963 | int i, j; |
| 964 | z = blob_str(pReply); |
| 965 | for(i=j=0; z[i]; i++, j++){ |
| 966 | if( z[i]=='<' ){ |
| 967 | while( z[i] && z[i]!='>' ) i++; |
| 968 | if( z[i]==0 ) break; |
| 969 | } |
| 970 | z[j] = z[i]; |
| 971 | } |
| 972 | z[j] = 0; |
| 973 | if( mHttpFlags & HTTP_QUIET ){ |
| 974 | /* no-op */ |
| 975 | }else if( mHttpFlags & HTTP_VERBOSE ){ |
| 976 |
| --- src/http.c | |
| +++ src/http.c | |
| @@ -86,11 +86,13 @@ | |
| 86 | if( g.url.passwd ){ |
| 87 | zPw = g.url.passwd; |
| 88 | }else if( g.cgiOutput ){ |
| 89 | /* Password failure while doing a sync from the web interface */ |
| 90 | cgi_printf("*** incorrect or missing password for user %h\n", zLogin); |
| 91 | blob_reset(&pw); |
| 92 | blob_reset(&nonce); |
| 93 | return; |
| 94 | }else{ |
| 95 | /* Password failure while doing a sync from the command-line interface */ |
| 96 | url_prompt_for_password(); |
| 97 | zPw = g.url.passwd; |
| 98 | } |
| @@ -437,17 +439,19 @@ | |
| 439 | ** It still might return a NULL pointer if for some reason it cannot |
| 440 | ** find and open the last http-reply-N.txt file. |
| 441 | */ |
| 442 | char *http_last_trace_reply(void){ |
| 443 | Blob x; |
| 444 | char *zFilename; |
| 445 | if( g.fHttpTrace==0 ) return 0; |
| 446 | zFilename = mprintf("http-reply-%d.txt", traceCnt); |
| 447 | if( file_size(zFilename, ExtFILE)<=0 ){ |
| 448 | fossil_free(zFilename); |
| 449 | return 0; |
| 450 | } |
| 451 | blob_read_from_file(&x, zFilename, ExtFILE); |
| 452 | fossil_free(zFilename); |
| 453 | return blob_str(&x); |
| 454 | } |
| 455 | |
| 456 | /* |
| 457 | ** Return true if z is a valud extension according to RFC 9112 s 7.1.1. |
| @@ -721,10 +725,11 @@ | |
| 725 | } |
| 726 | }else if( ( rc==301 || rc==302 || rc==307 || rc==308 ) && |
| 727 | fossil_strnicmp(zLine, "location:", 9)==0 ){ |
| 728 | int i, j; |
| 729 | int wasHttps; |
| 730 | int wasProxy; |
| 731 | int priorUrlFlags; |
| 732 | |
| 733 | if ( --maxRedirect == 0){ |
| 734 | if( (mHttpFlags & HTTP_QUIET)==0 ){ |
| 735 | fossil_warning("redirect limit exceeded"); |
| @@ -750,10 +755,11 @@ | |
| 755 | &zLine[i]); |
| 756 | } |
| 757 | goto write_err; |
| 758 | } |
| 759 | wasHttps = g.url.isHttps; |
| 760 | wasProxy = g.url.useProxy; |
| 761 | priorUrlFlags = g.url.flags; |
| 762 | url_parse(&zLine[i], 0); |
| 763 | if( wasHttps && !g.url.isHttps ){ |
| 764 | if( (mHttpFlags & HTTP_QUIET)==0 ){ |
| 765 | fossil_warning("cannot redirect from HTTPS to HTTP"); |
| @@ -773,10 +779,11 @@ | |
| 779 | g.zHttpAuth = get_httpauth(); |
| 780 | if( (rc==301 || rc==308) && (priorUrlFlags & URL_REMEMBER)!=0 ){ |
| 781 | g.url.flags |= URL_REMEMBER; |
| 782 | url_remember(); |
| 783 | } |
| 784 | if( wasProxy ) url_enable_proxy(0); |
| 785 | return http_exchange(pSend, pReply, mHttpFlags, |
| 786 | maxRedirect, zAltMimetype); |
| 787 | }else if( fossil_strnicmp(zLine, "content-type: ", 14)==0 ){ |
| 788 | if( fossil_strnicmp(&zLine[14], "application/x-fossil-debug", -1)==0 ){ |
| 789 | isCompressed = 0; |
| @@ -934,10 +941,11 @@ | |
| 941 | iRecvLen = transport_receive(&g.url, blob_buffer(pReply), iLength); |
| 942 | if( mHttpFlags & HTTP_VERBOSE ){ |
| 943 | fossil_print("Reply received: %d of %d bytes\n", iRecvLen, iLength); |
| 944 | } |
| 945 | if( iRecvLen != iLength ){ |
| 946 | blob_resize(pReply, iRecvLen); |
| 947 | if( mHttpFlags & HTTP_QUIET ) goto write_err; |
| 948 | fossil_warning("response truncated: got %d bytes of %d", |
| 949 | iRecvLen, iLength); |
| 950 | goto write_err; |
| 951 | } |
| @@ -960,16 +968,17 @@ | |
| 968 | } |
| 969 | if( isError ){ |
| 970 | char *z; |
| 971 | int i, j; |
| 972 | z = blob_str(pReply); |
| 973 | for(i=j=0; z[i]; i++){ |
| 974 | if( z[i]=='<' ){ |
| 975 | while( z[i] && z[i]!='>' ) i++; |
| 976 | if( z[i]==0 ) break; |
| 977 | }else{ |
| 978 | z[j++] = z[i]; |
| 979 | } |
| 980 | } |
| 981 | z[j] = 0; |
| 982 | if( mHttpFlags & HTTP_QUIET ){ |
| 983 | /* no-op */ |
| 984 | }else if( mHttpFlags & HTTP_VERBOSE ){ |
| 985 |
+94
-33
| --- src/import.c | ||
| +++ src/import.c | ||
| @@ -569,10 +569,11 @@ | ||
| 569 | 569 | gg.xFinish(); |
| 570 | 570 | gg.xFinish = finish_blob; |
| 571 | 571 | }else |
| 572 | 572 | if( strncmp(zLine, "commit ", 7)==0 ){ |
| 573 | 573 | const char *zRefName; |
| 574 | + int nRef; | |
| 574 | 575 | gg.xFinish(); |
| 575 | 576 | gg.xFinish = finish_commit; |
| 576 | 577 | trim_newline(&zLine[7]); |
| 577 | 578 | zRefName = &zLine[7]; |
| 578 | 579 | |
| @@ -592,13 +593,15 @@ | ||
| 592 | 593 | ** last commit that holds that tag. |
| 593 | 594 | ** |
| 594 | 595 | ** None of the above is explained in the git-fast-export |
| 595 | 596 | ** documentation. We had to figure it out via trial and error. |
| 596 | 597 | */ |
| 597 | - for(i=5; i<(int)strlen(zRefName) && zRefName[i]!='/'; i++){} | |
| 598 | - gg.tagCommit = strncmp(&zRefName[5], "tags", 4)==0; /* pattern B */ | |
| 599 | - if( zRefName[i+1]!=0 ) zRefName += i+1; | |
| 598 | + nRef = (int)strlen(zRefName); | |
| 599 | + for(i=5; i<nRef && zRefName[i]!='/'; i++){} | |
| 600 | + gg.tagCommit = nRef>=9 | |
| 601 | + && strncmp(&zRefName[5], "tags", 4)==0; /* pattern B */ | |
| 602 | + if( i<nRef && zRefName[i+1]!=0 ) zRefName += i+1; | |
| 600 | 603 | if( fossil_strcmp(zRefName, "master")==0 ) zRefName = ggit.zMasterName; |
| 601 | 604 | gg.zBranch = fossil_strdup(zRefName); |
| 602 | 605 | gg.fromLoaded = 0; |
| 603 | 606 | }else |
| 604 | 607 | if( strncmp(zLine, "tag ", 4)==0 ){ |
| @@ -625,10 +628,13 @@ | ||
| 625 | 628 | fossil_print("%s\n", &zLine[9]); |
| 626 | 629 | fflush(stdout); |
| 627 | 630 | }else |
| 628 | 631 | if( strncmp(zLine, "data ", 5)==0 ){ |
| 629 | 632 | fossil_free(gg.aData); gg.aData = 0; |
| 633 | + if( !fossil_isdigit(zLine[5]) || strtoll(&zLine[5], 0, 10)>=0x7fffffff ){ | |
| 634 | + goto malformed_line; | |
| 635 | + } | |
| 630 | 636 | gg.nData = atoi(&zLine[5]); |
| 631 | 637 | if( gg.nData ){ |
| 632 | 638 | int got; |
| 633 | 639 | gg.aData = fossil_malloc( gg.nData+1 ); |
| 634 | 640 | got = fread(gg.aData, 1, gg.nData, pIn); |
| @@ -666,10 +672,11 @@ | ||
| 666 | 672 | || strncmp(zLine, "committer ",10)==0 ){ |
| 667 | 673 | sqlite3_int64 secSince1970; |
| 668 | 674 | z = strchr(zLine, ' '); |
| 669 | 675 | while( fossil_isspace(*z) ) z++; |
| 670 | 676 | if( (zTo=strchr(z, '>'))==NULL ) goto malformed_line; |
| 677 | + if( zTo[1]!=' ' ) goto malformed_line; | |
| 671 | 678 | *(++zTo) = '\0'; |
| 672 | 679 | /* |
| 673 | 680 | ** If --attribute requested, lookup user in fx_ table by email address, |
| 674 | 681 | ** otherwise lookup Git {author,committer} contact info in user table. If |
| 675 | 682 | ** no matches, use email address as username for check-in attribution. |
| @@ -688,14 +695,16 @@ | ||
| 688 | 695 | gg.zUser = db_text(gg.zUser, |
| 689 | 696 | "SELECT user FROM fx_git WHERE email=%Q", z); |
| 690 | 697 | } |
| 691 | 698 | secSince1970 = 0; |
| 692 | 699 | for(zTo++; fossil_isdigit(*zTo); zTo++){ |
| 700 | + if( secSince1970>=100000000000LL ) goto malformed_line; | |
| 693 | 701 | secSince1970 = secSince1970*10 + *zTo - '0'; |
| 694 | 702 | } |
| 695 | 703 | fossil_free(gg.zDate); |
| 696 | 704 | gg.zDate = db_text(0, "SELECT datetime(%lld, 'unixepoch')",secSince1970); |
| 705 | + if( gg.zDate==0 || strlen(gg.zDate)<19 ) goto malformed_line; | |
| 697 | 706 | gg.zDate[10] = 'T'; |
| 698 | 707 | }else |
| 699 | 708 | if( strncmp(zLine, "from ", 5)==0 ){ |
| 700 | 709 | trim_newline(&zLine[5]); |
| 701 | 710 | fossil_free(gg.zFromMark); |
| @@ -860,10 +869,11 @@ | ||
| 860 | 869 | KeyVal *aHeaders; |
| 861 | 870 | int nHeaders; |
| 862 | 871 | char *pRawProps; |
| 863 | 872 | KeyVal *aProps; |
| 864 | 873 | int nProps; |
| 874 | + int deletesExec; /* A property delta deletes svn:executable */ | |
| 865 | 875 | Blob content; |
| 866 | 876 | int contentFlag; |
| 867 | 877 | } SvnRecord; |
| 868 | 878 | |
| 869 | 879 | #define svn_find_header(rec, zHeader) \ |
| @@ -892,20 +902,35 @@ | ||
| 892 | 902 | fossil_free(rec->aHeaders); |
| 893 | 903 | fossil_free(rec->aProps); |
| 894 | 904 | fossil_free(rec->pRawProps); |
| 895 | 905 | blob_reset(&rec->content); |
| 896 | 906 | } |
| 907 | + | |
| 908 | +/* | |
| 909 | +** Return the decimal number at z. It must be all digits up to the byte | |
| 910 | +** cEnd and no more than 2147483647, or else the dump is broken. | |
| 911 | +*/ | |
| 912 | +static int svn_number(const char *z, char cEnd){ | |
| 913 | + i64 v = 0; | |
| 914 | + int i; | |
| 915 | + for(i=0; fossil_isdigit(z[i]) && v<=0x7fffffff; i++){ | |
| 916 | + v = v*10 + z[i] - '0'; | |
| 917 | + } | |
| 918 | + if( i==0 || z[i]!=cEnd || v>0x7fffffff ){ | |
| 919 | + fossil_fatal("svn-dump data format broken"); | |
| 920 | + } | |
| 921 | + return (int)v; | |
| 922 | +} | |
| 897 | 923 | |
| 898 | 924 | static int svn_read_headers(FILE *pIn, SvnRecord *rec){ |
| 899 | 925 | char zLine[1000]; |
| 926 | + char *z; | |
| 900 | 927 | |
| 901 | 928 | rec->aHeaders = 0; |
| 902 | 929 | rec->nHeaders = 0; |
| 903 | - while( fgets(zLine, sizeof(zLine), pIn) ){ | |
| 904 | - if( zLine[0]!='\n' ) break; | |
| 905 | - } | |
| 906 | - if( feof(pIn) ) return 0; | |
| 930 | + while( (z = fgets(zLine, sizeof(zLine), pIn))!=0 && zLine[0]=='\n' ){} | |
| 931 | + if( z==0 ) return 0; | |
| 907 | 932 | do{ |
| 908 | 933 | char *sep; |
| 909 | 934 | if( zLine[0]=='\n' ) break; |
| 910 | 935 | rec->nHeaders += 1; |
| 911 | 936 | rec->aHeaders = fossil_realloc(rec->aHeaders, |
| @@ -917,10 +942,13 @@ | ||
| 917 | 942 | fossil_fatal("bad header line: [%s]", zLine); |
| 918 | 943 | } |
| 919 | 944 | *sep = 0; |
| 920 | 945 | rec->aHeaders[rec->nHeaders-1].zVal = sep+1; |
| 921 | 946 | sep = strchr(rec->aHeaders[rec->nHeaders-1].zVal, '\n'); |
| 947 | + if( !sep ){ | |
| 948 | + fossil_fatal("svn-dump data format broken"); | |
| 949 | + } | |
| 922 | 950 | *sep = 0; |
| 923 | 951 | while(rec->aHeaders[rec->nHeaders-1].zVal |
| 924 | 952 | && fossil_isspace(*(rec->aHeaders[rec->nHeaders-1].zVal)) ) |
| 925 | 953 | { |
| 926 | 954 | rec->aHeaders[rec->nHeaders-1].zVal++; |
| @@ -939,16 +967,14 @@ | ||
| 939 | 967 | const char *zLen; |
| 940 | 968 | |
| 941 | 969 | rec->pRawProps = 0; |
| 942 | 970 | rec->aProps = 0; |
| 943 | 971 | rec->nProps = 0; |
| 972 | + rec->deletesExec = 0; | |
| 944 | 973 | zLen = svn_find_header(*rec, "Prop-content-length"); |
| 945 | 974 | if( zLen ){ |
| 946 | - nRawProps = atoi(zLen); | |
| 947 | - if( nRawProps<0 ){ | |
| 948 | - fossil_fatal("svn-dump data format broken"); | |
| 949 | - } | |
| 975 | + nRawProps = svn_number(zLen, 0); | |
| 950 | 976 | } |
| 951 | 977 | if( nRawProps ){ |
| 952 | 978 | int got; |
| 953 | 979 | char *zLine; |
| 954 | 980 | char *zEnd; /* Start of the PROPS-END marker */ |
| @@ -964,27 +990,30 @@ | ||
| 964 | 990 | zEnd = pRawProps+nRawProps-10; |
| 965 | 991 | while( zLine<zEnd ){ |
| 966 | 992 | char *eol; |
| 967 | 993 | int propLen; |
| 968 | 994 | if( zLine[0]=='D' ){ |
| 969 | - propLen = atoi(&zLine[2]); | |
| 995 | + propLen = svn_number(&zLine[2], '\n'); | |
| 970 | 996 | eol = strchr(zLine, '\n'); |
| 971 | - if( eol==0 || eol>=zEnd || propLen<0 || propLen>zEnd-eol ){ | |
| 997 | + if( eol==0 || eol>=zEnd || propLen>zEnd-eol ){ | |
| 972 | 998 | fossil_fatal("svn-dump data format broken"); |
| 999 | + } | |
| 1000 | + if( propLen==14 && strncmp(eol+1, "svn:executable", 14)==0 ){ | |
| 1001 | + rec->deletesExec = 1; | |
| 973 | 1002 | } |
| 974 | 1003 | zLine = eol+1+propLen+1; |
| 975 | 1004 | }else{ |
| 976 | 1005 | if( zLine[0]!='K' ){ |
| 977 | 1006 | fossil_fatal("svn-dump data format broken"); |
| 978 | 1007 | } |
| 979 | - propLen = atoi(&zLine[2]); | |
| 1008 | + propLen = svn_number(&zLine[2], '\n'); | |
| 980 | 1009 | eol = strchr(zLine, '\n'); |
| 981 | 1010 | if( eol==0 || eol>=zEnd ){ |
| 982 | 1011 | fossil_fatal("svn-dump data format broken"); |
| 983 | 1012 | } |
| 984 | 1013 | zLine = eol+1; |
| 985 | - if( propLen<0 || propLen>=zEnd-zLine ){ | |
| 1014 | + if( propLen>=zEnd-zLine ){ | |
| 986 | 1015 | fossil_fatal("svn-dump data format broken"); |
| 987 | 1016 | } |
| 988 | 1017 | eol = zLine+propLen; |
| 989 | 1018 | if( *eol!='\n' ){ |
| 990 | 1019 | fossil_fatal("svn-dump data format broken"); |
| @@ -996,17 +1025,17 @@ | ||
| 996 | 1025 | rec->aProps[rec->nProps-1].zKey = zLine; |
| 997 | 1026 | zLine = eol+1; |
| 998 | 1027 | if( zLine[0]!='V' ){ |
| 999 | 1028 | fossil_fatal("svn-dump data format broken"); |
| 1000 | 1029 | } |
| 1001 | - propLen = atoi(&zLine[2]); | |
| 1030 | + propLen = svn_number(&zLine[2], '\n'); | |
| 1002 | 1031 | eol = strchr(zLine, '\n'); |
| 1003 | 1032 | if( eol==0 || eol>=zEnd ){ |
| 1004 | 1033 | fossil_fatal("svn-dump data format broken"); |
| 1005 | 1034 | } |
| 1006 | 1035 | zLine = eol+1; |
| 1007 | - if( propLen<0 || propLen>=zEnd-zLine ){ | |
| 1036 | + if( propLen>=zEnd-zLine ){ | |
| 1008 | 1037 | fossil_fatal("svn-dump data format broken"); |
| 1009 | 1038 | } |
| 1010 | 1039 | eol = zLine+propLen; |
| 1011 | 1040 | if( *eol!='\n' ){ |
| 1012 | 1041 | fossil_fatal("svn-dump data format broken"); |
| @@ -1026,11 +1055,11 @@ | ||
| 1026 | 1055 | svn_read_props(pIn, rec); |
| 1027 | 1056 | blob_zero(&rec->content); |
| 1028 | 1057 | zLen = svn_find_header(*rec, "Text-content-length"); |
| 1029 | 1058 | if( zLen ){ |
| 1030 | 1059 | rec->contentFlag = 1; |
| 1031 | - nLen = atoi(zLen); | |
| 1060 | + nLen = svn_number(zLen, 0); | |
| 1032 | 1061 | blob_read_from_channel(&rec->content, pIn, nLen); |
| 1033 | 1062 | if( (int)blob_size(&rec->content)!=nLen ){ |
| 1034 | 1063 | fossil_fatal("short read: got %d of %d bytes", |
| 1035 | 1064 | blob_size(&rec->content), nLen |
| 1036 | 1065 | ); |
| @@ -1203,17 +1232,17 @@ | ||
| 1203 | 1232 | int rid = content_put(&manifest); |
| 1204 | 1233 | db_bind_int(&setRid, ":branch", branchId); |
| 1205 | 1234 | db_bind_int(&setRid, ":rid", rid); |
| 1206 | 1235 | db_step(&setRid); |
| 1207 | 1236 | db_reset(&setRid); |
| 1208 | - }else if( branchType==SVN_TAG ){ | |
| 1237 | + }else if( branchType==SVN_TAG && parentRid>0 ){ | |
| 1209 | 1238 | content_put(&manifest); |
| 1210 | 1239 | db_bind_int(&setRid, ":branch", branchId); |
| 1211 | 1240 | db_bind_int(&setRid, ":rid", parentRid); |
| 1212 | 1241 | db_step(&setRid); |
| 1213 | 1242 | db_reset(&setRid); |
| 1214 | - }else if( mergeRid==MAX_INT_32 ){ | |
| 1243 | + }else if( mergeRid==MAX_INT_32 && parentRid>0 ){ | |
| 1215 | 1244 | content_put(&manifest); |
| 1216 | 1245 | db_multi_exec("DELETE FROM xrevisions WHERE tbranch=%d AND trev=%d", |
| 1217 | 1246 | branchId, gsvn.rev); |
| 1218 | 1247 | }else{ |
| 1219 | 1248 | db_multi_exec("DELETE FROM xrevisions WHERE tbranch=%d AND trev=%d", |
| @@ -1434,11 +1463,11 @@ | ||
| 1434 | 1463 | Stmt revSrc; |
| 1435 | 1464 | |
| 1436 | 1465 | /* version */ |
| 1437 | 1466 | if( svn_read_rec(pIn, &rec) |
| 1438 | 1467 | && (zTemp = svn_find_header(rec, "SVN-fs-dump-format-version")) ){ |
| 1439 | - ver = atoi(zTemp); | |
| 1468 | + ver = svn_number(zTemp, 0); | |
| 1440 | 1469 | if( ver!=2 && ver!=3 ){ |
| 1441 | 1470 | fossil_fatal("Unknown svn-dump format version: %d", ver); |
| 1442 | 1471 | } |
| 1443 | 1472 | }else{ |
| 1444 | 1473 | fossil_fatal("Input is not an svn-dump!"); |
| @@ -1495,11 +1524,11 @@ | ||
| 1495 | 1524 | fossil_free(gsvn.zComment); |
| 1496 | 1525 | fossil_free(gsvn.zDate); |
| 1497 | 1526 | bag_clear(&gsvn.newBranches); |
| 1498 | 1527 | } |
| 1499 | 1528 | /* start new revision */ |
| 1500 | - gsvn.rev = atoi(zTemp); | |
| 1529 | + gsvn.rev = svn_number(zTemp, 0); | |
| 1501 | 1530 | gsvn.zUser = fossil_strdup(svn_find_prop(rec, "svn:author")); |
| 1502 | 1531 | gsvn.zComment = fossil_strdup(svn_find_prop(rec, "svn:log")); |
| 1503 | 1532 | zDate = svn_find_prop(rec, "svn:date"); |
| 1504 | 1533 | if( zDate ){ |
| 1505 | 1534 | gsvn.zDate = date_in_standard_format(zDate); |
| @@ -1524,10 +1553,21 @@ | ||
| 1524 | 1553 | } |
| 1525 | 1554 | if( branchId==0 ){ |
| 1526 | 1555 | svn_free_rec(&rec); |
| 1527 | 1556 | continue; |
| 1528 | 1557 | } |
| 1558 | + if( zAction==0 || gsvn.rev<0 ){ | |
| 1559 | + fossil_fatal("svn-dump data format broken"); | |
| 1560 | + } | |
| 1561 | + if( zFile[0]==0 ){ | |
| 1562 | + if( zKind!=0 && strncmp(zKind, "dir", 3)!=0 ){ | |
| 1563 | + svn_free_rec(&rec); | |
| 1564 | + continue; | |
| 1565 | + } | |
| 1566 | + }else if( !file_is_simple_pathname_nonstrict(zFile) ){ | |
| 1567 | + fossil_fatal("svn path is not a valid file name: %s", zFile); | |
| 1568 | + } | |
| 1529 | 1569 | if( (zTemp = svn_find_header(rec, "Text-delta")) ){ |
| 1530 | 1570 | deltaFlag = strncmp(zTemp, "true", 4)==0; |
| 1531 | 1571 | } |
| 1532 | 1572 | if( strncmp(zAction, "delete", 6)==0 |
| 1533 | 1573 | || strncmp(zAction, "replace", 7)==0 ) |
| @@ -1557,11 +1597,11 @@ | ||
| 1557 | 1597 | int srcRid = 0; |
| 1558 | 1598 | if( zSrcPath ){ |
| 1559 | 1599 | int srcBranch; |
| 1560 | 1600 | zTemp = svn_find_header(rec, "Node-copyfrom-rev"); |
| 1561 | 1601 | if( zTemp ){ |
| 1562 | - srcRev = atoi(zTemp); | |
| 1602 | + srcRev = svn_number(zTemp, 0); | |
| 1563 | 1603 | }else{ |
| 1564 | 1604 | fossil_fatal("Missing copyfrom-rev"); |
| 1565 | 1605 | } |
| 1566 | 1606 | srcBranch = svn_parse_path(zSrcPath, &zSrcFile, &branchType); |
| 1567 | 1607 | if( srcBranch==0 ){ |
| @@ -1568,14 +1608,16 @@ | ||
| 1568 | 1608 | fossil_fatal("Copy from path outside the import paths"); |
| 1569 | 1609 | } |
| 1570 | 1610 | srcRid = db_int(0, "SELECT trid, max(trev) FROM xrevisions" |
| 1571 | 1611 | " WHERE trev<=%d AND tbranch=%d", |
| 1572 | 1612 | srcRev, srcBranch); |
| 1573 | - if( srcRid>0 && srcBranch!=branchId ){ | |
| 1613 | + if( srcRid>0 ){ | |
| 1574 | 1614 | db_bind_int(&addRev, ":branch", branchId); |
| 1575 | 1615 | db_step(&addRev); |
| 1576 | 1616 | db_reset(&addRev); |
| 1617 | + } | |
| 1618 | + if( srcRid>0 && (srcBranch!=branchId || zFile[0]==0) ){ | |
| 1577 | 1619 | db_bind_int(&revSrc, ":parent", srcRid); |
| 1578 | 1620 | db_bind_int(&revSrc, ":rev", gsvn.rev); |
| 1579 | 1621 | db_bind_int(&revSrc, ":branch", branchId); |
| 1580 | 1622 | db_step(&revSrc); |
| 1581 | 1623 | db_reset(&revSrc); |
| @@ -1621,10 +1663,23 @@ | ||
| 1621 | 1663 | rid = db_int(0, "SELECT rid FROM blob WHERE uuid=(" |
| 1622 | 1664 | " SELECT uuid FROM xfoci" |
| 1623 | 1665 | " WHERE checkinID=%d AND filename=%Q" |
| 1624 | 1666 | ")", |
| 1625 | 1667 | srcRid, zSrcFile); |
| 1668 | + zTemp = svn_find_header(rec, "Prop-delta"); | |
| 1669 | + if( zPerm==0 | |
| 1670 | + && (svn_find_header(rec, "Prop-content-length")==0 | |
| 1671 | + || (zTemp && strncmp(zTemp, "true", 4)==0)) ){ | |
| 1672 | + zPerm = db_text(0, "SELECT perm FROM xfoci" | |
| 1673 | + " WHERE checkinID=%d AND filename=%Q" | |
| 1674 | + " AND perm<>''", | |
| 1675 | + srcRid, zSrcFile); | |
| 1676 | + if( zPerm && rec.deletesExec && strcmp(zPerm, "x")==0 ){ | |
| 1677 | + fossil_free(zPerm); | |
| 1678 | + zPerm = 0; | |
| 1679 | + } | |
| 1680 | + } | |
| 1626 | 1681 | } |
| 1627 | 1682 | if( deltaFlag ){ |
| 1628 | 1683 | Blob deltaSrc; |
| 1629 | 1684 | Blob target; |
| 1630 | 1685 | if( rid!=0 ){ |
| @@ -1636,16 +1691,13 @@ | ||
| 1636 | 1691 | rid = svn_handle_symlinks(zPerm, &target); |
| 1637 | 1692 | blob_reset(&deltaSrc); |
| 1638 | 1693 | blob_reset(&target); |
| 1639 | 1694 | }else if( rec.contentFlag ){ |
| 1640 | 1695 | rid = svn_handle_symlinks(zPerm, &rec.content); |
| 1641 | - }else if( zSrcPath ){ | |
| 1642 | - if ( zPerm==0 ){ | |
| 1643 | - zPerm = db_text(0, "SELECT tperm FROM xfiles" | |
| 1644 | - " WHERE tpath=%Q AND tbranch=%d" | |
| 1645 | - "", zSrcPath, branchId); | |
| 1646 | - } | |
| 1696 | + } | |
| 1697 | + if( rid==0 ){ | |
| 1698 | + fossil_fatal("svn file has no content and no source: %s", zFile); | |
| 1647 | 1699 | } |
| 1648 | 1700 | db_bind_text(&addFile, ":path", zFile); |
| 1649 | 1701 | db_bind_int(&addFile, ":branch", branchId); |
| 1650 | 1702 | db_bind_int(&addFile, ":rid", rid); |
| 1651 | 1703 | db_bind_text(&addFile, ":perm", zPerm); |
| @@ -1793,11 +1845,10 @@ | ||
| 1793 | 1845 | char *zPassword; |
| 1794 | 1846 | FILE *pIn; |
| 1795 | 1847 | Stmt q; |
| 1796 | 1848 | int forceFlag = find_option("force", "f", 0)!=0; |
| 1797 | 1849 | int svnFlag = find_option("svn", 0, 0)!=0; |
| 1798 | - int gitFlag = find_option("git", 0, 0)!=0; | |
| 1799 | 1850 | int omitRebuild = find_option("no-rebuild",0,0)!=0; |
| 1800 | 1851 | int omitVacuum = find_option("no-vacuum",0,0)!=0; |
| 1801 | 1852 | const char *zDefaultUser = find_option("admin-user","A",1); |
| 1802 | 1853 | |
| 1803 | 1854 | /* Options common to all input formats */ |
| @@ -1843,10 +1894,11 @@ | ||
| 1843 | 1894 | } |
| 1844 | 1895 | if( !(gimport.zTrunkName = find_option("rename-trunk", 0, 1)) ){ |
| 1845 | 1896 | gimport.zTrunkName = fossil_strdup(db_main_branch()); |
| 1846 | 1897 | } |
| 1847 | 1898 | |
| 1899 | + find_option("git", 0, 0); | |
| 1848 | 1900 | if( svnFlag ){ |
| 1849 | 1901 | /* Get --svn related options here, so verify_all_options() fails when |
| 1850 | 1902 | * svn-only options are specified with --git |
| 1851 | 1903 | */ |
| 1852 | 1904 | const char *zIgnTree; |
| @@ -1864,11 +1916,11 @@ | ||
| 1864 | 1916 | gsvn.zTrunk = find_option("trunk", 0, 1); |
| 1865 | 1917 | gsvn.zBranches = find_option("branches", 0, 1); |
| 1866 | 1918 | gsvn.zTags = find_option("tags", 0, 1); |
| 1867 | 1919 | gsvn.revFlag = find_option("rev-tags", 0, 0) |
| 1868 | 1920 | || (incrFlag && !find_option("no-rev-tags", 0, 0)); |
| 1869 | - }else if( gitFlag ){ | |
| 1921 | + }else{ | |
| 1870 | 1922 | const char *zGitUser; |
| 1871 | 1923 | markfile_in = find_option("import-marks", 0, 1); |
| 1872 | 1924 | markfile_out = find_option("export-marks", 0, 1); |
| 1873 | 1925 | if( !(ggit.zMasterName = find_option("rename-master", 0, 1)) ){ |
| 1874 | 1926 | ggit.zMasterName = "master"; |
| @@ -1900,11 +1952,16 @@ | ||
| 1900 | 1952 | }else{ |
| 1901 | 1953 | pIn = stdin; |
| 1902 | 1954 | fossil_binary_mode(pIn); |
| 1903 | 1955 | } |
| 1904 | 1956 | if( !incrFlag ){ |
| 1905 | - if( forceFlag ) file_delete(g.argv[2]); | |
| 1957 | + if( forceFlag ){ | |
| 1958 | + file_delete(g.argv[2]); | |
| 1959 | + }else if( -1 != file_size(g.argv[2], ExtFILE) ){ | |
| 1960 | + fossil_fatal("file already exists: %s (use --force to replace it)", | |
| 1961 | + g.argv[2]); | |
| 1962 | + } | |
| 1906 | 1963 | db_create_repository(g.argv[2]); |
| 1907 | 1964 | } |
| 1908 | 1965 | db_open_repository(g.argv[2]); |
| 1909 | 1966 | db_open_config(0, 0); |
| 1910 | 1967 | db_unprotect(PROTECT_ALL); |
| @@ -1954,10 +2011,14 @@ | ||
| 1954 | 2011 | gsvn.zBranches = mprintf("%s%s", zBase, gsvn.zBranches); |
| 1955 | 2012 | gsvn.zTags = mprintf("%s%s", zBase, gsvn.zTags); |
| 1956 | 2013 | gsvn.lenTrunk = strlen(gsvn.zTrunk); |
| 1957 | 2014 | gsvn.lenBranches = strlen(gsvn.zBranches); |
| 1958 | 2015 | gsvn.lenTags = strlen(gsvn.zTags); |
| 2016 | + if( gsvn.lenTrunk==0 || gsvn.lenBranches==0 || gsvn.lenTags==0 ){ | |
| 2017 | + fossil_fatal("--trunk, --branches and --tags may be empty only " | |
| 2018 | + "with a non-empty --base"); | |
| 2019 | + } | |
| 1959 | 2020 | if( gsvn.zTrunk[gsvn.lenTrunk-1]!='/' ){ |
| 1960 | 2021 | gsvn.zTrunk = mprintf("%s/", gsvn.zTrunk); |
| 1961 | 2022 | gsvn.lenTrunk++; |
| 1962 | 2023 | } |
| 1963 | 2024 | if( gsvn.zBranches[gsvn.lenBranches-1]!='/' ){ |
| 1964 | 2025 |
| --- src/import.c | |
| +++ src/import.c | |
| @@ -569,10 +569,11 @@ | |
| 569 | gg.xFinish(); |
| 570 | gg.xFinish = finish_blob; |
| 571 | }else |
| 572 | if( strncmp(zLine, "commit ", 7)==0 ){ |
| 573 | const char *zRefName; |
| 574 | gg.xFinish(); |
| 575 | gg.xFinish = finish_commit; |
| 576 | trim_newline(&zLine[7]); |
| 577 | zRefName = &zLine[7]; |
| 578 | |
| @@ -592,13 +593,15 @@ | |
| 592 | ** last commit that holds that tag. |
| 593 | ** |
| 594 | ** None of the above is explained in the git-fast-export |
| 595 | ** documentation. We had to figure it out via trial and error. |
| 596 | */ |
| 597 | for(i=5; i<(int)strlen(zRefName) && zRefName[i]!='/'; i++){} |
| 598 | gg.tagCommit = strncmp(&zRefName[5], "tags", 4)==0; /* pattern B */ |
| 599 | if( zRefName[i+1]!=0 ) zRefName += i+1; |
| 600 | if( fossil_strcmp(zRefName, "master")==0 ) zRefName = ggit.zMasterName; |
| 601 | gg.zBranch = fossil_strdup(zRefName); |
| 602 | gg.fromLoaded = 0; |
| 603 | }else |
| 604 | if( strncmp(zLine, "tag ", 4)==0 ){ |
| @@ -625,10 +628,13 @@ | |
| 625 | fossil_print("%s\n", &zLine[9]); |
| 626 | fflush(stdout); |
| 627 | }else |
| 628 | if( strncmp(zLine, "data ", 5)==0 ){ |
| 629 | fossil_free(gg.aData); gg.aData = 0; |
| 630 | gg.nData = atoi(&zLine[5]); |
| 631 | if( gg.nData ){ |
| 632 | int got; |
| 633 | gg.aData = fossil_malloc( gg.nData+1 ); |
| 634 | got = fread(gg.aData, 1, gg.nData, pIn); |
| @@ -666,10 +672,11 @@ | |
| 666 | || strncmp(zLine, "committer ",10)==0 ){ |
| 667 | sqlite3_int64 secSince1970; |
| 668 | z = strchr(zLine, ' '); |
| 669 | while( fossil_isspace(*z) ) z++; |
| 670 | if( (zTo=strchr(z, '>'))==NULL ) goto malformed_line; |
| 671 | *(++zTo) = '\0'; |
| 672 | /* |
| 673 | ** If --attribute requested, lookup user in fx_ table by email address, |
| 674 | ** otherwise lookup Git {author,committer} contact info in user table. If |
| 675 | ** no matches, use email address as username for check-in attribution. |
| @@ -688,14 +695,16 @@ | |
| 688 | gg.zUser = db_text(gg.zUser, |
| 689 | "SELECT user FROM fx_git WHERE email=%Q", z); |
| 690 | } |
| 691 | secSince1970 = 0; |
| 692 | for(zTo++; fossil_isdigit(*zTo); zTo++){ |
| 693 | secSince1970 = secSince1970*10 + *zTo - '0'; |
| 694 | } |
| 695 | fossil_free(gg.zDate); |
| 696 | gg.zDate = db_text(0, "SELECT datetime(%lld, 'unixepoch')",secSince1970); |
| 697 | gg.zDate[10] = 'T'; |
| 698 | }else |
| 699 | if( strncmp(zLine, "from ", 5)==0 ){ |
| 700 | trim_newline(&zLine[5]); |
| 701 | fossil_free(gg.zFromMark); |
| @@ -860,10 +869,11 @@ | |
| 860 | KeyVal *aHeaders; |
| 861 | int nHeaders; |
| 862 | char *pRawProps; |
| 863 | KeyVal *aProps; |
| 864 | int nProps; |
| 865 | Blob content; |
| 866 | int contentFlag; |
| 867 | } SvnRecord; |
| 868 | |
| 869 | #define svn_find_header(rec, zHeader) \ |
| @@ -892,20 +902,35 @@ | |
| 892 | fossil_free(rec->aHeaders); |
| 893 | fossil_free(rec->aProps); |
| 894 | fossil_free(rec->pRawProps); |
| 895 | blob_reset(&rec->content); |
| 896 | } |
| 897 | |
| 898 | static int svn_read_headers(FILE *pIn, SvnRecord *rec){ |
| 899 | char zLine[1000]; |
| 900 | |
| 901 | rec->aHeaders = 0; |
| 902 | rec->nHeaders = 0; |
| 903 | while( fgets(zLine, sizeof(zLine), pIn) ){ |
| 904 | if( zLine[0]!='\n' ) break; |
| 905 | } |
| 906 | if( feof(pIn) ) return 0; |
| 907 | do{ |
| 908 | char *sep; |
| 909 | if( zLine[0]=='\n' ) break; |
| 910 | rec->nHeaders += 1; |
| 911 | rec->aHeaders = fossil_realloc(rec->aHeaders, |
| @@ -917,10 +942,13 @@ | |
| 917 | fossil_fatal("bad header line: [%s]", zLine); |
| 918 | } |
| 919 | *sep = 0; |
| 920 | rec->aHeaders[rec->nHeaders-1].zVal = sep+1; |
| 921 | sep = strchr(rec->aHeaders[rec->nHeaders-1].zVal, '\n'); |
| 922 | *sep = 0; |
| 923 | while(rec->aHeaders[rec->nHeaders-1].zVal |
| 924 | && fossil_isspace(*(rec->aHeaders[rec->nHeaders-1].zVal)) ) |
| 925 | { |
| 926 | rec->aHeaders[rec->nHeaders-1].zVal++; |
| @@ -939,16 +967,14 @@ | |
| 939 | const char *zLen; |
| 940 | |
| 941 | rec->pRawProps = 0; |
| 942 | rec->aProps = 0; |
| 943 | rec->nProps = 0; |
| 944 | zLen = svn_find_header(*rec, "Prop-content-length"); |
| 945 | if( zLen ){ |
| 946 | nRawProps = atoi(zLen); |
| 947 | if( nRawProps<0 ){ |
| 948 | fossil_fatal("svn-dump data format broken"); |
| 949 | } |
| 950 | } |
| 951 | if( nRawProps ){ |
| 952 | int got; |
| 953 | char *zLine; |
| 954 | char *zEnd; /* Start of the PROPS-END marker */ |
| @@ -964,27 +990,30 @@ | |
| 964 | zEnd = pRawProps+nRawProps-10; |
| 965 | while( zLine<zEnd ){ |
| 966 | char *eol; |
| 967 | int propLen; |
| 968 | if( zLine[0]=='D' ){ |
| 969 | propLen = atoi(&zLine[2]); |
| 970 | eol = strchr(zLine, '\n'); |
| 971 | if( eol==0 || eol>=zEnd || propLen<0 || propLen>zEnd-eol ){ |
| 972 | fossil_fatal("svn-dump data format broken"); |
| 973 | } |
| 974 | zLine = eol+1+propLen+1; |
| 975 | }else{ |
| 976 | if( zLine[0]!='K' ){ |
| 977 | fossil_fatal("svn-dump data format broken"); |
| 978 | } |
| 979 | propLen = atoi(&zLine[2]); |
| 980 | eol = strchr(zLine, '\n'); |
| 981 | if( eol==0 || eol>=zEnd ){ |
| 982 | fossil_fatal("svn-dump data format broken"); |
| 983 | } |
| 984 | zLine = eol+1; |
| 985 | if( propLen<0 || propLen>=zEnd-zLine ){ |
| 986 | fossil_fatal("svn-dump data format broken"); |
| 987 | } |
| 988 | eol = zLine+propLen; |
| 989 | if( *eol!='\n' ){ |
| 990 | fossil_fatal("svn-dump data format broken"); |
| @@ -996,17 +1025,17 @@ | |
| 996 | rec->aProps[rec->nProps-1].zKey = zLine; |
| 997 | zLine = eol+1; |
| 998 | if( zLine[0]!='V' ){ |
| 999 | fossil_fatal("svn-dump data format broken"); |
| 1000 | } |
| 1001 | propLen = atoi(&zLine[2]); |
| 1002 | eol = strchr(zLine, '\n'); |
| 1003 | if( eol==0 || eol>=zEnd ){ |
| 1004 | fossil_fatal("svn-dump data format broken"); |
| 1005 | } |
| 1006 | zLine = eol+1; |
| 1007 | if( propLen<0 || propLen>=zEnd-zLine ){ |
| 1008 | fossil_fatal("svn-dump data format broken"); |
| 1009 | } |
| 1010 | eol = zLine+propLen; |
| 1011 | if( *eol!='\n' ){ |
| 1012 | fossil_fatal("svn-dump data format broken"); |
| @@ -1026,11 +1055,11 @@ | |
| 1026 | svn_read_props(pIn, rec); |
| 1027 | blob_zero(&rec->content); |
| 1028 | zLen = svn_find_header(*rec, "Text-content-length"); |
| 1029 | if( zLen ){ |
| 1030 | rec->contentFlag = 1; |
| 1031 | nLen = atoi(zLen); |
| 1032 | blob_read_from_channel(&rec->content, pIn, nLen); |
| 1033 | if( (int)blob_size(&rec->content)!=nLen ){ |
| 1034 | fossil_fatal("short read: got %d of %d bytes", |
| 1035 | blob_size(&rec->content), nLen |
| 1036 | ); |
| @@ -1203,17 +1232,17 @@ | |
| 1203 | int rid = content_put(&manifest); |
| 1204 | db_bind_int(&setRid, ":branch", branchId); |
| 1205 | db_bind_int(&setRid, ":rid", rid); |
| 1206 | db_step(&setRid); |
| 1207 | db_reset(&setRid); |
| 1208 | }else if( branchType==SVN_TAG ){ |
| 1209 | content_put(&manifest); |
| 1210 | db_bind_int(&setRid, ":branch", branchId); |
| 1211 | db_bind_int(&setRid, ":rid", parentRid); |
| 1212 | db_step(&setRid); |
| 1213 | db_reset(&setRid); |
| 1214 | }else if( mergeRid==MAX_INT_32 ){ |
| 1215 | content_put(&manifest); |
| 1216 | db_multi_exec("DELETE FROM xrevisions WHERE tbranch=%d AND trev=%d", |
| 1217 | branchId, gsvn.rev); |
| 1218 | }else{ |
| 1219 | db_multi_exec("DELETE FROM xrevisions WHERE tbranch=%d AND trev=%d", |
| @@ -1434,11 +1463,11 @@ | |
| 1434 | Stmt revSrc; |
| 1435 | |
| 1436 | /* version */ |
| 1437 | if( svn_read_rec(pIn, &rec) |
| 1438 | && (zTemp = svn_find_header(rec, "SVN-fs-dump-format-version")) ){ |
| 1439 | ver = atoi(zTemp); |
| 1440 | if( ver!=2 && ver!=3 ){ |
| 1441 | fossil_fatal("Unknown svn-dump format version: %d", ver); |
| 1442 | } |
| 1443 | }else{ |
| 1444 | fossil_fatal("Input is not an svn-dump!"); |
| @@ -1495,11 +1524,11 @@ | |
| 1495 | fossil_free(gsvn.zComment); |
| 1496 | fossil_free(gsvn.zDate); |
| 1497 | bag_clear(&gsvn.newBranches); |
| 1498 | } |
| 1499 | /* start new revision */ |
| 1500 | gsvn.rev = atoi(zTemp); |
| 1501 | gsvn.zUser = fossil_strdup(svn_find_prop(rec, "svn:author")); |
| 1502 | gsvn.zComment = fossil_strdup(svn_find_prop(rec, "svn:log")); |
| 1503 | zDate = svn_find_prop(rec, "svn:date"); |
| 1504 | if( zDate ){ |
| 1505 | gsvn.zDate = date_in_standard_format(zDate); |
| @@ -1524,10 +1553,21 @@ | |
| 1524 | } |
| 1525 | if( branchId==0 ){ |
| 1526 | svn_free_rec(&rec); |
| 1527 | continue; |
| 1528 | } |
| 1529 | if( (zTemp = svn_find_header(rec, "Text-delta")) ){ |
| 1530 | deltaFlag = strncmp(zTemp, "true", 4)==0; |
| 1531 | } |
| 1532 | if( strncmp(zAction, "delete", 6)==0 |
| 1533 | || strncmp(zAction, "replace", 7)==0 ) |
| @@ -1557,11 +1597,11 @@ | |
| 1557 | int srcRid = 0; |
| 1558 | if( zSrcPath ){ |
| 1559 | int srcBranch; |
| 1560 | zTemp = svn_find_header(rec, "Node-copyfrom-rev"); |
| 1561 | if( zTemp ){ |
| 1562 | srcRev = atoi(zTemp); |
| 1563 | }else{ |
| 1564 | fossil_fatal("Missing copyfrom-rev"); |
| 1565 | } |
| 1566 | srcBranch = svn_parse_path(zSrcPath, &zSrcFile, &branchType); |
| 1567 | if( srcBranch==0 ){ |
| @@ -1568,14 +1608,16 @@ | |
| 1568 | fossil_fatal("Copy from path outside the import paths"); |
| 1569 | } |
| 1570 | srcRid = db_int(0, "SELECT trid, max(trev) FROM xrevisions" |
| 1571 | " WHERE trev<=%d AND tbranch=%d", |
| 1572 | srcRev, srcBranch); |
| 1573 | if( srcRid>0 && srcBranch!=branchId ){ |
| 1574 | db_bind_int(&addRev, ":branch", branchId); |
| 1575 | db_step(&addRev); |
| 1576 | db_reset(&addRev); |
| 1577 | db_bind_int(&revSrc, ":parent", srcRid); |
| 1578 | db_bind_int(&revSrc, ":rev", gsvn.rev); |
| 1579 | db_bind_int(&revSrc, ":branch", branchId); |
| 1580 | db_step(&revSrc); |
| 1581 | db_reset(&revSrc); |
| @@ -1621,10 +1663,23 @@ | |
| 1621 | rid = db_int(0, "SELECT rid FROM blob WHERE uuid=(" |
| 1622 | " SELECT uuid FROM xfoci" |
| 1623 | " WHERE checkinID=%d AND filename=%Q" |
| 1624 | ")", |
| 1625 | srcRid, zSrcFile); |
| 1626 | } |
| 1627 | if( deltaFlag ){ |
| 1628 | Blob deltaSrc; |
| 1629 | Blob target; |
| 1630 | if( rid!=0 ){ |
| @@ -1636,16 +1691,13 @@ | |
| 1636 | rid = svn_handle_symlinks(zPerm, &target); |
| 1637 | blob_reset(&deltaSrc); |
| 1638 | blob_reset(&target); |
| 1639 | }else if( rec.contentFlag ){ |
| 1640 | rid = svn_handle_symlinks(zPerm, &rec.content); |
| 1641 | }else if( zSrcPath ){ |
| 1642 | if ( zPerm==0 ){ |
| 1643 | zPerm = db_text(0, "SELECT tperm FROM xfiles" |
| 1644 | " WHERE tpath=%Q AND tbranch=%d" |
| 1645 | "", zSrcPath, branchId); |
| 1646 | } |
| 1647 | } |
| 1648 | db_bind_text(&addFile, ":path", zFile); |
| 1649 | db_bind_int(&addFile, ":branch", branchId); |
| 1650 | db_bind_int(&addFile, ":rid", rid); |
| 1651 | db_bind_text(&addFile, ":perm", zPerm); |
| @@ -1793,11 +1845,10 @@ | |
| 1793 | char *zPassword; |
| 1794 | FILE *pIn; |
| 1795 | Stmt q; |
| 1796 | int forceFlag = find_option("force", "f", 0)!=0; |
| 1797 | int svnFlag = find_option("svn", 0, 0)!=0; |
| 1798 | int gitFlag = find_option("git", 0, 0)!=0; |
| 1799 | int omitRebuild = find_option("no-rebuild",0,0)!=0; |
| 1800 | int omitVacuum = find_option("no-vacuum",0,0)!=0; |
| 1801 | const char *zDefaultUser = find_option("admin-user","A",1); |
| 1802 | |
| 1803 | /* Options common to all input formats */ |
| @@ -1843,10 +1894,11 @@ | |
| 1843 | } |
| 1844 | if( !(gimport.zTrunkName = find_option("rename-trunk", 0, 1)) ){ |
| 1845 | gimport.zTrunkName = fossil_strdup(db_main_branch()); |
| 1846 | } |
| 1847 | |
| 1848 | if( svnFlag ){ |
| 1849 | /* Get --svn related options here, so verify_all_options() fails when |
| 1850 | * svn-only options are specified with --git |
| 1851 | */ |
| 1852 | const char *zIgnTree; |
| @@ -1864,11 +1916,11 @@ | |
| 1864 | gsvn.zTrunk = find_option("trunk", 0, 1); |
| 1865 | gsvn.zBranches = find_option("branches", 0, 1); |
| 1866 | gsvn.zTags = find_option("tags", 0, 1); |
| 1867 | gsvn.revFlag = find_option("rev-tags", 0, 0) |
| 1868 | || (incrFlag && !find_option("no-rev-tags", 0, 0)); |
| 1869 | }else if( gitFlag ){ |
| 1870 | const char *zGitUser; |
| 1871 | markfile_in = find_option("import-marks", 0, 1); |
| 1872 | markfile_out = find_option("export-marks", 0, 1); |
| 1873 | if( !(ggit.zMasterName = find_option("rename-master", 0, 1)) ){ |
| 1874 | ggit.zMasterName = "master"; |
| @@ -1900,11 +1952,16 @@ | |
| 1900 | }else{ |
| 1901 | pIn = stdin; |
| 1902 | fossil_binary_mode(pIn); |
| 1903 | } |
| 1904 | if( !incrFlag ){ |
| 1905 | if( forceFlag ) file_delete(g.argv[2]); |
| 1906 | db_create_repository(g.argv[2]); |
| 1907 | } |
| 1908 | db_open_repository(g.argv[2]); |
| 1909 | db_open_config(0, 0); |
| 1910 | db_unprotect(PROTECT_ALL); |
| @@ -1954,10 +2011,14 @@ | |
| 1954 | gsvn.zBranches = mprintf("%s%s", zBase, gsvn.zBranches); |
| 1955 | gsvn.zTags = mprintf("%s%s", zBase, gsvn.zTags); |
| 1956 | gsvn.lenTrunk = strlen(gsvn.zTrunk); |
| 1957 | gsvn.lenBranches = strlen(gsvn.zBranches); |
| 1958 | gsvn.lenTags = strlen(gsvn.zTags); |
| 1959 | if( gsvn.zTrunk[gsvn.lenTrunk-1]!='/' ){ |
| 1960 | gsvn.zTrunk = mprintf("%s/", gsvn.zTrunk); |
| 1961 | gsvn.lenTrunk++; |
| 1962 | } |
| 1963 | if( gsvn.zBranches[gsvn.lenBranches-1]!='/' ){ |
| 1964 |
| --- src/import.c | |
| +++ src/import.c | |
| @@ -569,10 +569,11 @@ | |
| 569 | gg.xFinish(); |
| 570 | gg.xFinish = finish_blob; |
| 571 | }else |
| 572 | if( strncmp(zLine, "commit ", 7)==0 ){ |
| 573 | const char *zRefName; |
| 574 | int nRef; |
| 575 | gg.xFinish(); |
| 576 | gg.xFinish = finish_commit; |
| 577 | trim_newline(&zLine[7]); |
| 578 | zRefName = &zLine[7]; |
| 579 | |
| @@ -592,13 +593,15 @@ | |
| 593 | ** last commit that holds that tag. |
| 594 | ** |
| 595 | ** None of the above is explained in the git-fast-export |
| 596 | ** documentation. We had to figure it out via trial and error. |
| 597 | */ |
| 598 | nRef = (int)strlen(zRefName); |
| 599 | for(i=5; i<nRef && zRefName[i]!='/'; i++){} |
| 600 | gg.tagCommit = nRef>=9 |
| 601 | && strncmp(&zRefName[5], "tags", 4)==0; /* pattern B */ |
| 602 | if( i<nRef && zRefName[i+1]!=0 ) zRefName += i+1; |
| 603 | if( fossil_strcmp(zRefName, "master")==0 ) zRefName = ggit.zMasterName; |
| 604 | gg.zBranch = fossil_strdup(zRefName); |
| 605 | gg.fromLoaded = 0; |
| 606 | }else |
| 607 | if( strncmp(zLine, "tag ", 4)==0 ){ |
| @@ -625,10 +628,13 @@ | |
| 628 | fossil_print("%s\n", &zLine[9]); |
| 629 | fflush(stdout); |
| 630 | }else |
| 631 | if( strncmp(zLine, "data ", 5)==0 ){ |
| 632 | fossil_free(gg.aData); gg.aData = 0; |
| 633 | if( !fossil_isdigit(zLine[5]) || strtoll(&zLine[5], 0, 10)>=0x7fffffff ){ |
| 634 | goto malformed_line; |
| 635 | } |
| 636 | gg.nData = atoi(&zLine[5]); |
| 637 | if( gg.nData ){ |
| 638 | int got; |
| 639 | gg.aData = fossil_malloc( gg.nData+1 ); |
| 640 | got = fread(gg.aData, 1, gg.nData, pIn); |
| @@ -666,10 +672,11 @@ | |
| 672 | || strncmp(zLine, "committer ",10)==0 ){ |
| 673 | sqlite3_int64 secSince1970; |
| 674 | z = strchr(zLine, ' '); |
| 675 | while( fossil_isspace(*z) ) z++; |
| 676 | if( (zTo=strchr(z, '>'))==NULL ) goto malformed_line; |
| 677 | if( zTo[1]!=' ' ) goto malformed_line; |
| 678 | *(++zTo) = '\0'; |
| 679 | /* |
| 680 | ** If --attribute requested, lookup user in fx_ table by email address, |
| 681 | ** otherwise lookup Git {author,committer} contact info in user table. If |
| 682 | ** no matches, use email address as username for check-in attribution. |
| @@ -688,14 +695,16 @@ | |
| 695 | gg.zUser = db_text(gg.zUser, |
| 696 | "SELECT user FROM fx_git WHERE email=%Q", z); |
| 697 | } |
| 698 | secSince1970 = 0; |
| 699 | for(zTo++; fossil_isdigit(*zTo); zTo++){ |
| 700 | if( secSince1970>=100000000000LL ) goto malformed_line; |
| 701 | secSince1970 = secSince1970*10 + *zTo - '0'; |
| 702 | } |
| 703 | fossil_free(gg.zDate); |
| 704 | gg.zDate = db_text(0, "SELECT datetime(%lld, 'unixepoch')",secSince1970); |
| 705 | if( gg.zDate==0 || strlen(gg.zDate)<19 ) goto malformed_line; |
| 706 | gg.zDate[10] = 'T'; |
| 707 | }else |
| 708 | if( strncmp(zLine, "from ", 5)==0 ){ |
| 709 | trim_newline(&zLine[5]); |
| 710 | fossil_free(gg.zFromMark); |
| @@ -860,10 +869,11 @@ | |
| 869 | KeyVal *aHeaders; |
| 870 | int nHeaders; |
| 871 | char *pRawProps; |
| 872 | KeyVal *aProps; |
| 873 | int nProps; |
| 874 | int deletesExec; /* A property delta deletes svn:executable */ |
| 875 | Blob content; |
| 876 | int contentFlag; |
| 877 | } SvnRecord; |
| 878 | |
| 879 | #define svn_find_header(rec, zHeader) \ |
| @@ -892,20 +902,35 @@ | |
| 902 | fossil_free(rec->aHeaders); |
| 903 | fossil_free(rec->aProps); |
| 904 | fossil_free(rec->pRawProps); |
| 905 | blob_reset(&rec->content); |
| 906 | } |
| 907 | |
| 908 | /* |
| 909 | ** Return the decimal number at z. It must be all digits up to the byte |
| 910 | ** cEnd and no more than 2147483647, or else the dump is broken. |
| 911 | */ |
| 912 | static int svn_number(const char *z, char cEnd){ |
| 913 | i64 v = 0; |
| 914 | int i; |
| 915 | for(i=0; fossil_isdigit(z[i]) && v<=0x7fffffff; i++){ |
| 916 | v = v*10 + z[i] - '0'; |
| 917 | } |
| 918 | if( i==0 || z[i]!=cEnd || v>0x7fffffff ){ |
| 919 | fossil_fatal("svn-dump data format broken"); |
| 920 | } |
| 921 | return (int)v; |
| 922 | } |
| 923 | |
| 924 | static int svn_read_headers(FILE *pIn, SvnRecord *rec){ |
| 925 | char zLine[1000]; |
| 926 | char *z; |
| 927 | |
| 928 | rec->aHeaders = 0; |
| 929 | rec->nHeaders = 0; |
| 930 | while( (z = fgets(zLine, sizeof(zLine), pIn))!=0 && zLine[0]=='\n' ){} |
| 931 | if( z==0 ) return 0; |
| 932 | do{ |
| 933 | char *sep; |
| 934 | if( zLine[0]=='\n' ) break; |
| 935 | rec->nHeaders += 1; |
| 936 | rec->aHeaders = fossil_realloc(rec->aHeaders, |
| @@ -917,10 +942,13 @@ | |
| 942 | fossil_fatal("bad header line: [%s]", zLine); |
| 943 | } |
| 944 | *sep = 0; |
| 945 | rec->aHeaders[rec->nHeaders-1].zVal = sep+1; |
| 946 | sep = strchr(rec->aHeaders[rec->nHeaders-1].zVal, '\n'); |
| 947 | if( !sep ){ |
| 948 | fossil_fatal("svn-dump data format broken"); |
| 949 | } |
| 950 | *sep = 0; |
| 951 | while(rec->aHeaders[rec->nHeaders-1].zVal |
| 952 | && fossil_isspace(*(rec->aHeaders[rec->nHeaders-1].zVal)) ) |
| 953 | { |
| 954 | rec->aHeaders[rec->nHeaders-1].zVal++; |
| @@ -939,16 +967,14 @@ | |
| 967 | const char *zLen; |
| 968 | |
| 969 | rec->pRawProps = 0; |
| 970 | rec->aProps = 0; |
| 971 | rec->nProps = 0; |
| 972 | rec->deletesExec = 0; |
| 973 | zLen = svn_find_header(*rec, "Prop-content-length"); |
| 974 | if( zLen ){ |
| 975 | nRawProps = svn_number(zLen, 0); |
| 976 | } |
| 977 | if( nRawProps ){ |
| 978 | int got; |
| 979 | char *zLine; |
| 980 | char *zEnd; /* Start of the PROPS-END marker */ |
| @@ -964,27 +990,30 @@ | |
| 990 | zEnd = pRawProps+nRawProps-10; |
| 991 | while( zLine<zEnd ){ |
| 992 | char *eol; |
| 993 | int propLen; |
| 994 | if( zLine[0]=='D' ){ |
| 995 | propLen = svn_number(&zLine[2], '\n'); |
| 996 | eol = strchr(zLine, '\n'); |
| 997 | if( eol==0 || eol>=zEnd || propLen>zEnd-eol ){ |
| 998 | fossil_fatal("svn-dump data format broken"); |
| 999 | } |
| 1000 | if( propLen==14 && strncmp(eol+1, "svn:executable", 14)==0 ){ |
| 1001 | rec->deletesExec = 1; |
| 1002 | } |
| 1003 | zLine = eol+1+propLen+1; |
| 1004 | }else{ |
| 1005 | if( zLine[0]!='K' ){ |
| 1006 | fossil_fatal("svn-dump data format broken"); |
| 1007 | } |
| 1008 | propLen = svn_number(&zLine[2], '\n'); |
| 1009 | eol = strchr(zLine, '\n'); |
| 1010 | if( eol==0 || eol>=zEnd ){ |
| 1011 | fossil_fatal("svn-dump data format broken"); |
| 1012 | } |
| 1013 | zLine = eol+1; |
| 1014 | if( propLen>=zEnd-zLine ){ |
| 1015 | fossil_fatal("svn-dump data format broken"); |
| 1016 | } |
| 1017 | eol = zLine+propLen; |
| 1018 | if( *eol!='\n' ){ |
| 1019 | fossil_fatal("svn-dump data format broken"); |
| @@ -996,17 +1025,17 @@ | |
| 1025 | rec->aProps[rec->nProps-1].zKey = zLine; |
| 1026 | zLine = eol+1; |
| 1027 | if( zLine[0]!='V' ){ |
| 1028 | fossil_fatal("svn-dump data format broken"); |
| 1029 | } |
| 1030 | propLen = svn_number(&zLine[2], '\n'); |
| 1031 | eol = strchr(zLine, '\n'); |
| 1032 | if( eol==0 || eol>=zEnd ){ |
| 1033 | fossil_fatal("svn-dump data format broken"); |
| 1034 | } |
| 1035 | zLine = eol+1; |
| 1036 | if( propLen>=zEnd-zLine ){ |
| 1037 | fossil_fatal("svn-dump data format broken"); |
| 1038 | } |
| 1039 | eol = zLine+propLen; |
| 1040 | if( *eol!='\n' ){ |
| 1041 | fossil_fatal("svn-dump data format broken"); |
| @@ -1026,11 +1055,11 @@ | |
| 1055 | svn_read_props(pIn, rec); |
| 1056 | blob_zero(&rec->content); |
| 1057 | zLen = svn_find_header(*rec, "Text-content-length"); |
| 1058 | if( zLen ){ |
| 1059 | rec->contentFlag = 1; |
| 1060 | nLen = svn_number(zLen, 0); |
| 1061 | blob_read_from_channel(&rec->content, pIn, nLen); |
| 1062 | if( (int)blob_size(&rec->content)!=nLen ){ |
| 1063 | fossil_fatal("short read: got %d of %d bytes", |
| 1064 | blob_size(&rec->content), nLen |
| 1065 | ); |
| @@ -1203,17 +1232,17 @@ | |
| 1232 | int rid = content_put(&manifest); |
| 1233 | db_bind_int(&setRid, ":branch", branchId); |
| 1234 | db_bind_int(&setRid, ":rid", rid); |
| 1235 | db_step(&setRid); |
| 1236 | db_reset(&setRid); |
| 1237 | }else if( branchType==SVN_TAG && parentRid>0 ){ |
| 1238 | content_put(&manifest); |
| 1239 | db_bind_int(&setRid, ":branch", branchId); |
| 1240 | db_bind_int(&setRid, ":rid", parentRid); |
| 1241 | db_step(&setRid); |
| 1242 | db_reset(&setRid); |
| 1243 | }else if( mergeRid==MAX_INT_32 && parentRid>0 ){ |
| 1244 | content_put(&manifest); |
| 1245 | db_multi_exec("DELETE FROM xrevisions WHERE tbranch=%d AND trev=%d", |
| 1246 | branchId, gsvn.rev); |
| 1247 | }else{ |
| 1248 | db_multi_exec("DELETE FROM xrevisions WHERE tbranch=%d AND trev=%d", |
| @@ -1434,11 +1463,11 @@ | |
| 1463 | Stmt revSrc; |
| 1464 | |
| 1465 | /* version */ |
| 1466 | if( svn_read_rec(pIn, &rec) |
| 1467 | && (zTemp = svn_find_header(rec, "SVN-fs-dump-format-version")) ){ |
| 1468 | ver = svn_number(zTemp, 0); |
| 1469 | if( ver!=2 && ver!=3 ){ |
| 1470 | fossil_fatal("Unknown svn-dump format version: %d", ver); |
| 1471 | } |
| 1472 | }else{ |
| 1473 | fossil_fatal("Input is not an svn-dump!"); |
| @@ -1495,11 +1524,11 @@ | |
| 1524 | fossil_free(gsvn.zComment); |
| 1525 | fossil_free(gsvn.zDate); |
| 1526 | bag_clear(&gsvn.newBranches); |
| 1527 | } |
| 1528 | /* start new revision */ |
| 1529 | gsvn.rev = svn_number(zTemp, 0); |
| 1530 | gsvn.zUser = fossil_strdup(svn_find_prop(rec, "svn:author")); |
| 1531 | gsvn.zComment = fossil_strdup(svn_find_prop(rec, "svn:log")); |
| 1532 | zDate = svn_find_prop(rec, "svn:date"); |
| 1533 | if( zDate ){ |
| 1534 | gsvn.zDate = date_in_standard_format(zDate); |
| @@ -1524,10 +1553,21 @@ | |
| 1553 | } |
| 1554 | if( branchId==0 ){ |
| 1555 | svn_free_rec(&rec); |
| 1556 | continue; |
| 1557 | } |
| 1558 | if( zAction==0 || gsvn.rev<0 ){ |
| 1559 | fossil_fatal("svn-dump data format broken"); |
| 1560 | } |
| 1561 | if( zFile[0]==0 ){ |
| 1562 | if( zKind!=0 && strncmp(zKind, "dir", 3)!=0 ){ |
| 1563 | svn_free_rec(&rec); |
| 1564 | continue; |
| 1565 | } |
| 1566 | }else if( !file_is_simple_pathname_nonstrict(zFile) ){ |
| 1567 | fossil_fatal("svn path is not a valid file name: %s", zFile); |
| 1568 | } |
| 1569 | if( (zTemp = svn_find_header(rec, "Text-delta")) ){ |
| 1570 | deltaFlag = strncmp(zTemp, "true", 4)==0; |
| 1571 | } |
| 1572 | if( strncmp(zAction, "delete", 6)==0 |
| 1573 | || strncmp(zAction, "replace", 7)==0 ) |
| @@ -1557,11 +1597,11 @@ | |
| 1597 | int srcRid = 0; |
| 1598 | if( zSrcPath ){ |
| 1599 | int srcBranch; |
| 1600 | zTemp = svn_find_header(rec, "Node-copyfrom-rev"); |
| 1601 | if( zTemp ){ |
| 1602 | srcRev = svn_number(zTemp, 0); |
| 1603 | }else{ |
| 1604 | fossil_fatal("Missing copyfrom-rev"); |
| 1605 | } |
| 1606 | srcBranch = svn_parse_path(zSrcPath, &zSrcFile, &branchType); |
| 1607 | if( srcBranch==0 ){ |
| @@ -1568,14 +1608,16 @@ | |
| 1608 | fossil_fatal("Copy from path outside the import paths"); |
| 1609 | } |
| 1610 | srcRid = db_int(0, "SELECT trid, max(trev) FROM xrevisions" |
| 1611 | " WHERE trev<=%d AND tbranch=%d", |
| 1612 | srcRev, srcBranch); |
| 1613 | if( srcRid>0 ){ |
| 1614 | db_bind_int(&addRev, ":branch", branchId); |
| 1615 | db_step(&addRev); |
| 1616 | db_reset(&addRev); |
| 1617 | } |
| 1618 | if( srcRid>0 && (srcBranch!=branchId || zFile[0]==0) ){ |
| 1619 | db_bind_int(&revSrc, ":parent", srcRid); |
| 1620 | db_bind_int(&revSrc, ":rev", gsvn.rev); |
| 1621 | db_bind_int(&revSrc, ":branch", branchId); |
| 1622 | db_step(&revSrc); |
| 1623 | db_reset(&revSrc); |
| @@ -1621,10 +1663,23 @@ | |
| 1663 | rid = db_int(0, "SELECT rid FROM blob WHERE uuid=(" |
| 1664 | " SELECT uuid FROM xfoci" |
| 1665 | " WHERE checkinID=%d AND filename=%Q" |
| 1666 | ")", |
| 1667 | srcRid, zSrcFile); |
| 1668 | zTemp = svn_find_header(rec, "Prop-delta"); |
| 1669 | if( zPerm==0 |
| 1670 | && (svn_find_header(rec, "Prop-content-length")==0 |
| 1671 | || (zTemp && strncmp(zTemp, "true", 4)==0)) ){ |
| 1672 | zPerm = db_text(0, "SELECT perm FROM xfoci" |
| 1673 | " WHERE checkinID=%d AND filename=%Q" |
| 1674 | " AND perm<>''", |
| 1675 | srcRid, zSrcFile); |
| 1676 | if( zPerm && rec.deletesExec && strcmp(zPerm, "x")==0 ){ |
| 1677 | fossil_free(zPerm); |
| 1678 | zPerm = 0; |
| 1679 | } |
| 1680 | } |
| 1681 | } |
| 1682 | if( deltaFlag ){ |
| 1683 | Blob deltaSrc; |
| 1684 | Blob target; |
| 1685 | if( rid!=0 ){ |
| @@ -1636,16 +1691,13 @@ | |
| 1691 | rid = svn_handle_symlinks(zPerm, &target); |
| 1692 | blob_reset(&deltaSrc); |
| 1693 | blob_reset(&target); |
| 1694 | }else if( rec.contentFlag ){ |
| 1695 | rid = svn_handle_symlinks(zPerm, &rec.content); |
| 1696 | } |
| 1697 | if( rid==0 ){ |
| 1698 | fossil_fatal("svn file has no content and no source: %s", zFile); |
| 1699 | } |
| 1700 | db_bind_text(&addFile, ":path", zFile); |
| 1701 | db_bind_int(&addFile, ":branch", branchId); |
| 1702 | db_bind_int(&addFile, ":rid", rid); |
| 1703 | db_bind_text(&addFile, ":perm", zPerm); |
| @@ -1793,11 +1845,10 @@ | |
| 1845 | char *zPassword; |
| 1846 | FILE *pIn; |
| 1847 | Stmt q; |
| 1848 | int forceFlag = find_option("force", "f", 0)!=0; |
| 1849 | int svnFlag = find_option("svn", 0, 0)!=0; |
| 1850 | int omitRebuild = find_option("no-rebuild",0,0)!=0; |
| 1851 | int omitVacuum = find_option("no-vacuum",0,0)!=0; |
| 1852 | const char *zDefaultUser = find_option("admin-user","A",1); |
| 1853 | |
| 1854 | /* Options common to all input formats */ |
| @@ -1843,10 +1894,11 @@ | |
| 1894 | } |
| 1895 | if( !(gimport.zTrunkName = find_option("rename-trunk", 0, 1)) ){ |
| 1896 | gimport.zTrunkName = fossil_strdup(db_main_branch()); |
| 1897 | } |
| 1898 | |
| 1899 | find_option("git", 0, 0); |
| 1900 | if( svnFlag ){ |
| 1901 | /* Get --svn related options here, so verify_all_options() fails when |
| 1902 | * svn-only options are specified with --git |
| 1903 | */ |
| 1904 | const char *zIgnTree; |
| @@ -1864,11 +1916,11 @@ | |
| 1916 | gsvn.zTrunk = find_option("trunk", 0, 1); |
| 1917 | gsvn.zBranches = find_option("branches", 0, 1); |
| 1918 | gsvn.zTags = find_option("tags", 0, 1); |
| 1919 | gsvn.revFlag = find_option("rev-tags", 0, 0) |
| 1920 | || (incrFlag && !find_option("no-rev-tags", 0, 0)); |
| 1921 | }else{ |
| 1922 | const char *zGitUser; |
| 1923 | markfile_in = find_option("import-marks", 0, 1); |
| 1924 | markfile_out = find_option("export-marks", 0, 1); |
| 1925 | if( !(ggit.zMasterName = find_option("rename-master", 0, 1)) ){ |
| 1926 | ggit.zMasterName = "master"; |
| @@ -1900,11 +1952,16 @@ | |
| 1952 | }else{ |
| 1953 | pIn = stdin; |
| 1954 | fossil_binary_mode(pIn); |
| 1955 | } |
| 1956 | if( !incrFlag ){ |
| 1957 | if( forceFlag ){ |
| 1958 | file_delete(g.argv[2]); |
| 1959 | }else if( -1 != file_size(g.argv[2], ExtFILE) ){ |
| 1960 | fossil_fatal("file already exists: %s (use --force to replace it)", |
| 1961 | g.argv[2]); |
| 1962 | } |
| 1963 | db_create_repository(g.argv[2]); |
| 1964 | } |
| 1965 | db_open_repository(g.argv[2]); |
| 1966 | db_open_config(0, 0); |
| 1967 | db_unprotect(PROTECT_ALL); |
| @@ -1954,10 +2011,14 @@ | |
| 2011 | gsvn.zBranches = mprintf("%s%s", zBase, gsvn.zBranches); |
| 2012 | gsvn.zTags = mprintf("%s%s", zBase, gsvn.zTags); |
| 2013 | gsvn.lenTrunk = strlen(gsvn.zTrunk); |
| 2014 | gsvn.lenBranches = strlen(gsvn.zBranches); |
| 2015 | gsvn.lenTags = strlen(gsvn.zTags); |
| 2016 | if( gsvn.lenTrunk==0 || gsvn.lenBranches==0 || gsvn.lenTags==0 ){ |
| 2017 | fossil_fatal("--trunk, --branches and --tags may be empty only " |
| 2018 | "with a non-empty --base"); |
| 2019 | } |
| 2020 | if( gsvn.zTrunk[gsvn.lenTrunk-1]!='/' ){ |
| 2021 | gsvn.zTrunk = mprintf("%s/", gsvn.zTrunk); |
| 2022 | gsvn.lenTrunk++; |
| 2023 | } |
| 2024 | if( gsvn.zBranches[gsvn.lenBranches-1]!='/' ){ |
| 2025 |
+2
| --- src/info.c | ||
| +++ src/info.c | ||
| @@ -3302,10 +3302,12 @@ | ||
| 3302 | 3302 | int badRid = 0; |
| 3303 | 3303 | int rcvid; |
| 3304 | 3304 | int hashClr = PB("hclr"); |
| 3305 | 3305 | const char *zDate; |
| 3306 | 3306 | |
| 3307 | + login_check_credentials(); | |
| 3308 | + if( !g.perm.Read ){ login_needed(g.anon.Read); return; } | |
| 3307 | 3309 | pCluster = manifest_get(rid, CFTYPE_CLUSTER, 0); |
| 3308 | 3310 | if( pCluster==0 ){ |
| 3309 | 3311 | artifact_page(); |
| 3310 | 3312 | return; |
| 3311 | 3313 | } |
| 3312 | 3314 |
| --- src/info.c | |
| +++ src/info.c | |
| @@ -3302,10 +3302,12 @@ | |
| 3302 | int badRid = 0; |
| 3303 | int rcvid; |
| 3304 | int hashClr = PB("hclr"); |
| 3305 | const char *zDate; |
| 3306 | |
| 3307 | pCluster = manifest_get(rid, CFTYPE_CLUSTER, 0); |
| 3308 | if( pCluster==0 ){ |
| 3309 | artifact_page(); |
| 3310 | return; |
| 3311 | } |
| 3312 |
| --- src/info.c | |
| +++ src/info.c | |
| @@ -3302,10 +3302,12 @@ | |
| 3302 | int badRid = 0; |
| 3303 | int rcvid; |
| 3304 | int hashClr = PB("hclr"); |
| 3305 | const char *zDate; |
| 3306 | |
| 3307 | login_check_credentials(); |
| 3308 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| 3309 | pCluster = manifest_get(rid, CFTYPE_CLUSTER, 0); |
| 3310 | if( pCluster==0 ){ |
| 3311 | artifact_page(); |
| 3312 | return; |
| 3313 | } |
| 3314 |
+9
-1
| --- src/login.c | ||
| +++ src/login.c | ||
| @@ -122,12 +122,19 @@ | ||
| 122 | 122 | NORETURN void login_redirect_to_g(void){ |
| 123 | 123 | const char *zGoto = P("g"); |
| 124 | 124 | if( zGoto ){ |
| 125 | 125 | cgi_redirectf("%R/%s",zGoto); |
| 126 | 126 | }else if( (zGoto = P("fossil-goto"))!=0 && zGoto[0]!=0 ){ |
| 127 | + int n = g.zBaseURL ? (int)strlen(g.zBaseURL) : 0; | |
| 127 | 128 | cgi_set_cookie("fossil-goto","",0,1); |
| 128 | - cgi_redirect(zGoto); | |
| 129 | + if( (fossil_strncmp(zGoto,"http:",5)!=0 | |
| 130 | + && fossil_strncmp(zGoto,"https:",6)!=0) | |
| 131 | + || (n>0 && strncmp(zGoto, g.zBaseURL, n)==0 | |
| 132 | + && (zGoto[n]==0 || zGoto[n]=='/')) ){ | |
| 133 | + cgi_redirect(zGoto); | |
| 134 | + } | |
| 135 | + fossil_redirect_home(); | |
| 129 | 136 | }else{ |
| 130 | 137 | fossil_redirect_home(); |
| 131 | 138 | } |
| 132 | 139 | } |
| 133 | 140 | |
| @@ -1437,10 +1444,11 @@ | ||
| 1437 | 1444 | char *zUser = 0; |
| 1438 | 1445 | int i, c; |
| 1439 | 1446 | for(i=0; (c = zHash[i])!=0; i++){ |
| 1440 | 1447 | if( c=='/' ){ |
| 1441 | 1448 | zHash[i++] = 0; |
| 1449 | + if( zHash[i]==0 ) break; | |
| 1442 | 1450 | if( zArg==0 ){ |
| 1443 | 1451 | zArg = &zHash[i]; |
| 1444 | 1452 | }else{ |
| 1445 | 1453 | zUser = &zHash[i]; |
| 1446 | 1454 | break; |
| 1447 | 1455 |
| --- src/login.c | |
| +++ src/login.c | |
| @@ -122,12 +122,19 @@ | |
| 122 | NORETURN void login_redirect_to_g(void){ |
| 123 | const char *zGoto = P("g"); |
| 124 | if( zGoto ){ |
| 125 | cgi_redirectf("%R/%s",zGoto); |
| 126 | }else if( (zGoto = P("fossil-goto"))!=0 && zGoto[0]!=0 ){ |
| 127 | cgi_set_cookie("fossil-goto","",0,1); |
| 128 | cgi_redirect(zGoto); |
| 129 | }else{ |
| 130 | fossil_redirect_home(); |
| 131 | } |
| 132 | } |
| 133 | |
| @@ -1437,10 +1444,11 @@ | |
| 1437 | char *zUser = 0; |
| 1438 | int i, c; |
| 1439 | for(i=0; (c = zHash[i])!=0; i++){ |
| 1440 | if( c=='/' ){ |
| 1441 | zHash[i++] = 0; |
| 1442 | if( zArg==0 ){ |
| 1443 | zArg = &zHash[i]; |
| 1444 | }else{ |
| 1445 | zUser = &zHash[i]; |
| 1446 | break; |
| 1447 |
| --- src/login.c | |
| +++ src/login.c | |
| @@ -122,12 +122,19 @@ | |
| 122 | NORETURN void login_redirect_to_g(void){ |
| 123 | const char *zGoto = P("g"); |
| 124 | if( zGoto ){ |
| 125 | cgi_redirectf("%R/%s",zGoto); |
| 126 | }else if( (zGoto = P("fossil-goto"))!=0 && zGoto[0]!=0 ){ |
| 127 | int n = g.zBaseURL ? (int)strlen(g.zBaseURL) : 0; |
| 128 | cgi_set_cookie("fossil-goto","",0,1); |
| 129 | if( (fossil_strncmp(zGoto,"http:",5)!=0 |
| 130 | && fossil_strncmp(zGoto,"https:",6)!=0) |
| 131 | || (n>0 && strncmp(zGoto, g.zBaseURL, n)==0 |
| 132 | && (zGoto[n]==0 || zGoto[n]=='/')) ){ |
| 133 | cgi_redirect(zGoto); |
| 134 | } |
| 135 | fossil_redirect_home(); |
| 136 | }else{ |
| 137 | fossil_redirect_home(); |
| 138 | } |
| 139 | } |
| 140 | |
| @@ -1437,10 +1444,11 @@ | |
| 1444 | char *zUser = 0; |
| 1445 | int i, c; |
| 1446 | for(i=0; (c = zHash[i])!=0; i++){ |
| 1447 | if( c=='/' ){ |
| 1448 | zHash[i++] = 0; |
| 1449 | if( zHash[i]==0 ) break; |
| 1450 | if( zArg==0 ){ |
| 1451 | zArg = &zHash[i]; |
| 1452 | }else{ |
| 1453 | zUser = &zHash[i]; |
| 1454 | break; |
| 1455 |
+1
-1
| --- src/main.c | ||
| +++ src/main.c | ||
| @@ -1455,11 +1455,11 @@ | ||
| 1455 | 1455 | if( n==2 ) g.zTop = ""; |
| 1456 | 1456 | if( g.zTop==g.zBaseURL ){ |
| 1457 | 1457 | fossil_fatal("argument to --baseurl should be 'http://host/path'" |
| 1458 | 1458 | " or 'https://host/path'"); |
| 1459 | 1459 | } |
| 1460 | - if( g.zTop[1]==0 ) g.zTop++; | |
| 1460 | + if( g.zTop[0] && g.zTop[1]==0 ) g.zTop++; | |
| 1461 | 1461 | }else{ |
| 1462 | 1462 | char *z; |
| 1463 | 1463 | zMode = PD("HTTPS","off"); |
| 1464 | 1464 | zHost = PD("HTTP_HOST",""); |
| 1465 | 1465 | z = fossil_strdup(zHost); |
| 1466 | 1466 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -1455,11 +1455,11 @@ | |
| 1455 | if( n==2 ) g.zTop = ""; |
| 1456 | if( g.zTop==g.zBaseURL ){ |
| 1457 | fossil_fatal("argument to --baseurl should be 'http://host/path'" |
| 1458 | " or 'https://host/path'"); |
| 1459 | } |
| 1460 | if( g.zTop[1]==0 ) g.zTop++; |
| 1461 | }else{ |
| 1462 | char *z; |
| 1463 | zMode = PD("HTTPS","off"); |
| 1464 | zHost = PD("HTTP_HOST",""); |
| 1465 | z = fossil_strdup(zHost); |
| 1466 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -1455,11 +1455,11 @@ | |
| 1455 | if( n==2 ) g.zTop = ""; |
| 1456 | if( g.zTop==g.zBaseURL ){ |
| 1457 | fossil_fatal("argument to --baseurl should be 'http://host/path'" |
| 1458 | " or 'https://host/path'"); |
| 1459 | } |
| 1460 | if( g.zTop[0] && g.zTop[1]==0 ) g.zTop++; |
| 1461 | }else{ |
| 1462 | char *z; |
| 1463 | zMode = PD("HTTPS","off"); |
| 1464 | zHost = PD("HTTP_HOST",""); |
| 1465 | z = fossil_strdup(zHost); |
| 1466 |
+3
-3
| --- src/manifest.c | ||
| +++ src/manifest.c | ||
| @@ -1957,14 +1957,14 @@ | ||
| 1957 | 1957 | if( mxParent<1 ) return; |
| 1958 | 1958 | zCopy = fossil_strdup(zValue); |
| 1959 | 1959 | azParent = fossil_malloc( sizeof(azParent[0])*mxParent ); |
| 1960 | 1960 | for(nParent=0, i=0; zCopy[i]; i++){ |
| 1961 | 1961 | char *z = &zCopy[i]; |
| 1962 | - azParent[nParent++] = z; | |
| 1963 | - if( nParent>mxParent ) goto reparent_abort; | |
| 1964 | - for(j=HNAME_MIN; z[j]>' '; j++){} | |
| 1962 | + if( nParent>=mxParent ) goto reparent_abort; | |
| 1963 | + for(j=0; z[j]>' '; j++){} | |
| 1965 | 1964 | if( !hname_validate(z, j) ) goto reparent_abort; |
| 1965 | + azParent[nParent++] = z; | |
| 1966 | 1966 | if( z[j]==0 ) break; |
| 1967 | 1967 | z[j] = 0; |
| 1968 | 1968 | i += j; |
| 1969 | 1969 | } |
| 1970 | 1970 | p = manifest_get(rid, CFTYPE_MANIFEST, 0); |
| 1971 | 1971 |
| --- src/manifest.c | |
| +++ src/manifest.c | |
| @@ -1957,14 +1957,14 @@ | |
| 1957 | if( mxParent<1 ) return; |
| 1958 | zCopy = fossil_strdup(zValue); |
| 1959 | azParent = fossil_malloc( sizeof(azParent[0])*mxParent ); |
| 1960 | for(nParent=0, i=0; zCopy[i]; i++){ |
| 1961 | char *z = &zCopy[i]; |
| 1962 | azParent[nParent++] = z; |
| 1963 | if( nParent>mxParent ) goto reparent_abort; |
| 1964 | for(j=HNAME_MIN; z[j]>' '; j++){} |
| 1965 | if( !hname_validate(z, j) ) goto reparent_abort; |
| 1966 | if( z[j]==0 ) break; |
| 1967 | z[j] = 0; |
| 1968 | i += j; |
| 1969 | } |
| 1970 | p = manifest_get(rid, CFTYPE_MANIFEST, 0); |
| 1971 |
| --- src/manifest.c | |
| +++ src/manifest.c | |
| @@ -1957,14 +1957,14 @@ | |
| 1957 | if( mxParent<1 ) return; |
| 1958 | zCopy = fossil_strdup(zValue); |
| 1959 | azParent = fossil_malloc( sizeof(azParent[0])*mxParent ); |
| 1960 | for(nParent=0, i=0; zCopy[i]; i++){ |
| 1961 | char *z = &zCopy[i]; |
| 1962 | if( nParent>=mxParent ) goto reparent_abort; |
| 1963 | for(j=0; z[j]>' '; j++){} |
| 1964 | if( !hname_validate(z, j) ) goto reparent_abort; |
| 1965 | azParent[nParent++] = z; |
| 1966 | if( z[j]==0 ) break; |
| 1967 | z[j] = 0; |
| 1968 | i += j; |
| 1969 | } |
| 1970 | p = manifest_get(rid, CFTYPE_MANIFEST, 0); |
| 1971 |
+59
-49
| --- src/name.c | ||
| +++ src/name.c | ||
| @@ -78,11 +78,11 @@ | ||
| 78 | 78 | ** the input string is a hash prefix and NULL is returned if it is. If the |
| 79 | 79 | ** bVerifyNotAHash flag is false, then the result is determined by syntax |
| 80 | 80 | ** of the input string only, without reference to the artifact table. |
| 81 | 81 | */ |
| 82 | 82 | char *fossil_expand_datetime(const char *zIn,int bVerifyNotAHash,int bRoundUp){ |
| 83 | - static char zEDate[24]; | |
| 83 | + static char zEDate[25]; | |
| 84 | 84 | static const char aPunct[] = { 0, 0, '-', '-', ' ', ':', ':' }; |
| 85 | 85 | int n = (int)strlen(zIn); |
| 86 | 86 | int i, j; |
| 87 | 87 | int addZulu = 0; |
| 88 | 88 | |
| @@ -701,13 +701,14 @@ | ||
| 701 | 701 | |
| 702 | 702 | /* Undocumented: numeric tags get translated directly into the RID */ |
| 703 | 703 | if( strncmp(zTag, "rid:", 4)==0 ){ |
| 704 | 704 | zTag += 4; |
| 705 | 705 | for(i=0; fossil_isdigit(zTag[i]); i++){} |
| 706 | - if( zTag[i]==0 ){ | |
| 706 | + if( i>0 && zTag[i]==0 ){ | |
| 707 | 707 | if( strcmp(zType,"*")==0 ){ |
| 708 | - rid = atoi(zTag); | |
| 708 | + rid = db_int(0, "SELECT rid FROM blob WHERE rid=%s", | |
| 709 | + zTag /*safe-for-%s*/); | |
| 709 | 710 | }else{ |
| 710 | 711 | rid = db_int(0, |
| 711 | 712 | "SELECT event.objid" |
| 712 | 713 | " FROM event" |
| 713 | 714 | " WHERE event.objid=%s" |
| @@ -1000,10 +1001,12 @@ | ||
| 1000 | 1001 | Stmt q; |
| 1001 | 1002 | const char *zName = P("name"); |
| 1002 | 1003 | const char *zSrc = PD("src","info"); |
| 1003 | 1004 | char *z; |
| 1004 | 1005 | |
| 1006 | + login_check_credentials(); | |
| 1007 | + if( !g.perm.Read ){ login_needed(g.anon.Read); return; } | |
| 1005 | 1008 | if( zName==0 || zName[0]==0 || zSrc==0 || zSrc[0]==0 ){ |
| 1006 | 1009 | fossil_redirect_home(); |
| 1007 | 1010 | } |
| 1008 | 1011 | style_header("Ambiguous Artifact ID"); |
| 1009 | 1012 | @ <p>The artifact hash prefix <b>%h(zName)</b> is ambiguous and might |
| @@ -1019,50 +1022,54 @@ | ||
| 1019 | 1022 | @ %s(zUuid)</a> - |
| 1020 | 1023 | object_description(rid, 0, 0, 0); |
| 1021 | 1024 | @ </p></li> |
| 1022 | 1025 | } |
| 1023 | 1026 | db_finalize(&q); |
| 1024 | - db_prepare(&q, | |
| 1025 | - " SELECT tkt_rid, tkt_uuid, title" | |
| 1026 | - " FROM ticket, ticketchng" | |
| 1027 | - " WHERE ticket.tkt_id = ticketchng.tkt_id" | |
| 1028 | - " AND tkt_uuid GLOB '%q*'" | |
| 1029 | - " GROUP BY tkt_uuid" | |
| 1030 | - " ORDER BY tkt_ctime DESC", z); | |
| 1031 | - while( db_step(&q)==SQLITE_ROW ){ | |
| 1032 | - int rid = db_column_int(&q, 0); | |
| 1033 | - const char *zUuid = db_column_text(&q, 1); | |
| 1034 | - const char *zTitle = db_column_text(&q, 2); | |
| 1035 | - @ <li><p><a href="%R/%T(zSrc)/%!S(zUuid)"> | |
| 1036 | - @ %s(zUuid)</a> - | |
| 1037 | - @ <ul></ul> | |
| 1038 | - @ Ticket | |
| 1039 | - hyperlink_to_version(zUuid); | |
| 1040 | - @ - %h(zTitle). | |
| 1041 | - @ <ul><li> | |
| 1042 | - object_description(rid, 0, 0, 0); | |
| 1043 | - @ </li></ul> | |
| 1044 | - @ </p></li> | |
| 1045 | - } | |
| 1046 | - db_finalize(&q); | |
| 1047 | - db_prepare(&q, | |
| 1048 | - "SELECT rid, uuid FROM" | |
| 1049 | - " (SELECT tagxref.rid AS rid, substr(tagname, 7) AS uuid" | |
| 1050 | - " FROM tagxref, tag WHERE tagxref.tagid = tag.tagid" | |
| 1051 | - " AND tagname GLOB 'event-%q*') GROUP BY uuid", z); | |
| 1052 | - while( db_step(&q)==SQLITE_ROW ){ | |
| 1053 | - int rid = db_column_int(&q, 0); | |
| 1054 | - const char* zUuid = db_column_text(&q, 1); | |
| 1055 | - @ <li><p><a href="%R/%T(zSrc)/%!S(zUuid)"> | |
| 1056 | - @ %s(zUuid)</a> - | |
| 1057 | - @ <ul><li> | |
| 1058 | - object_description(rid, 0, 0, 0); | |
| 1059 | - @ </li></ul> | |
| 1060 | - @ </p></li> | |
| 1027 | + if( g.perm.RdTkt ){ | |
| 1028 | + db_prepare(&q, | |
| 1029 | + " SELECT tkt_rid, tkt_uuid, title" | |
| 1030 | + " FROM ticket, ticketchng" | |
| 1031 | + " WHERE ticket.tkt_id = ticketchng.tkt_id" | |
| 1032 | + " AND tkt_uuid GLOB '%q*'" | |
| 1033 | + " GROUP BY tkt_uuid" | |
| 1034 | + " ORDER BY tkt_ctime DESC", z); | |
| 1035 | + while( db_step(&q)==SQLITE_ROW ){ | |
| 1036 | + int rid = db_column_int(&q, 0); | |
| 1037 | + const char *zUuid = db_column_text(&q, 1); | |
| 1038 | + const char *zTitle = db_column_text(&q, 2); | |
| 1039 | + @ <li><p><a href="%R/%T(zSrc)/%!S(zUuid)"> | |
| 1040 | + @ %s(zUuid)</a> - | |
| 1041 | + @ <ul></ul> | |
| 1042 | + @ Ticket | |
| 1043 | + hyperlink_to_version(zUuid); | |
| 1044 | + @ - %h(zTitle). | |
| 1045 | + @ <ul><li> | |
| 1046 | + object_description(rid, 0, 0, 0); | |
| 1047 | + @ </li></ul> | |
| 1048 | + @ </p></li> | |
| 1049 | + } | |
| 1050 | + db_finalize(&q); | |
| 1051 | + } | |
| 1052 | + if( g.perm.RdWiki ){ | |
| 1053 | + db_prepare(&q, | |
| 1054 | + "SELECT rid, uuid FROM" | |
| 1055 | + " (SELECT tagxref.rid AS rid, substr(tagname, 7) AS uuid" | |
| 1056 | + " FROM tagxref, tag WHERE tagxref.tagid = tag.tagid" | |
| 1057 | + " AND tagname GLOB 'event-%q*') GROUP BY uuid", z); | |
| 1058 | + while( db_step(&q)==SQLITE_ROW ){ | |
| 1059 | + int rid = db_column_int(&q, 0); | |
| 1060 | + const char* zUuid = db_column_text(&q, 1); | |
| 1061 | + @ <li><p><a href="%R/%T(zSrc)/%!S(zUuid)"> | |
| 1062 | + @ %s(zUuid)</a> - | |
| 1063 | + @ <ul><li> | |
| 1064 | + object_description(rid, 0, 0, 0); | |
| 1065 | + @ </li></ul> | |
| 1066 | + @ </p></li> | |
| 1067 | + } | |
| 1068 | + db_finalize(&q); | |
| 1061 | 1069 | } |
| 1062 | 1070 | @ </ol> |
| 1063 | - db_finalize(&q); | |
| 1064 | 1071 | style_finish_page(); |
| 1065 | 1072 | } |
| 1066 | 1073 | |
| 1067 | 1074 | /* |
| 1068 | 1075 | ** Convert the name in CGI parameter zParamName into a rid and return that |
| @@ -1239,11 +1246,11 @@ | ||
| 1239 | 1246 | ); |
| 1240 | 1247 | cnt = 0; |
| 1241 | 1248 | while( db_step(&q)==SQLITE_ROW ){ |
| 1242 | 1249 | const char *zTag = (const char*)db_column_text(&q,0); |
| 1243 | 1250 | if( pOut ){ |
| 1244 | - const char *zSep = cnt==0 ? ",tags:[" : ","; | |
| 1251 | + const char *zSep = cnt==0 ? ",\"tags\":[" : ","; | |
| 1245 | 1252 | sqlite3_str_appendf(pOut, "%s%J", zSep, zTag); |
| 1246 | 1253 | }else{ |
| 1247 | 1254 | const char *zPrefix = cnt ? ", " : "tags: "; |
| 1248 | 1255 | fossil_print("%s%s", zPrefix, db_column_text(&q,0)); |
| 1249 | 1256 | } |
| @@ -1494,14 +1501,16 @@ | ||
| 1494 | 1501 | " ORDER BY mtime LIMIT 1)" |
| 1495 | 1502 | " FROM tag WHERE tagname GLOB 'tkt-%q*'", |
| 1496 | 1503 | zC |
| 1497 | 1504 | ); |
| 1498 | 1505 | while( db_step(&q)==SQLITE_ROW ){ |
| 1499 | - if( pOut ){ | |
| 1500 | - sqlite3_str_append(pOut, ",", 1); | |
| 1501 | - }else{ | |
| 1502 | - fossil_print("%12s---- meaning #%d ----\n", " ", cnt); | |
| 1506 | + if( cnt++ ){ | |
| 1507 | + if( pOut ){ | |
| 1508 | + sqlite3_str_append(pOut, ",", 1); | |
| 1509 | + }else{ | |
| 1510 | + fossil_print("%12s---- meaning #%d ----\n", " ", cnt); | |
| 1511 | + } | |
| 1503 | 1512 | } |
| 1504 | 1513 | whatis_rid(db_column_int(&q, 0), mFlags, pOut); |
| 1505 | 1514 | } |
| 1506 | 1515 | db_finalize(&q); |
| 1507 | 1516 | } |
| @@ -2036,10 +2045,11 @@ | ||
| 2036 | 2045 | char *zSha3Bg; |
| 2037 | 2046 | |
| 2038 | 2047 | login_check_credentials(); |
| 2039 | 2048 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| 2040 | 2049 | cgi_check_for_malice(); |
| 2050 | + if( n<1 ) n = 1; | |
| 2041 | 2051 | style_header("List Of Artifacts"); |
| 2042 | 2052 | style_submenu_element("250 Largest", "bigbloblist"); |
| 2043 | 2053 | if( bRecent==0 || n!=250 ){ |
| 2044 | 2054 | style_submenu_element("Recent","bloblist?n=250&recent"); |
| 2045 | 2055 | } |
| @@ -2089,14 +2099,14 @@ | ||
| 2089 | 2099 | }else if( bUnclst ){ |
| 2090 | 2100 | @ <h2>Unclustered Artifacts</h2> |
| 2091 | 2101 | zRange = mprintf("IN unclustered"); |
| 2092 | 2102 | }else if( bRecent ){ |
| 2093 | 2103 | @ <h2>%d(n) Most Recent Artifacts</h2> |
| 2094 | - zRange = mprintf(">=(SELECT rid FROM blob" | |
| 2095 | - " ORDER BY rid DESC LIMIT 1 OFFSET %d)",n); | |
| 2104 | + zRange = mprintf("IN (SELECT rid FROM blob" | |
| 2105 | + " ORDER BY rid DESC LIMIT %d)",n); | |
| 2096 | 2106 | }else{ |
| 2097 | - zRange = mprintf("BETWEEN %d AND %d", s, s+n-1); | |
| 2107 | + zRange = mprintf("BETWEEN %d AND %lld", s, (i64)s+n-1); | |
| 2098 | 2108 | } |
| 2099 | 2109 | describe_artifacts(zRange); |
| 2100 | 2110 | fossil_free(zRange); |
| 2101 | 2111 | db_prepare(&q, |
| 2102 | 2112 | /* 0 1 2 3 4 5 6 */ |
| 2103 | 2113 |
| --- src/name.c | |
| +++ src/name.c | |
| @@ -78,11 +78,11 @@ | |
| 78 | ** the input string is a hash prefix and NULL is returned if it is. If the |
| 79 | ** bVerifyNotAHash flag is false, then the result is determined by syntax |
| 80 | ** of the input string only, without reference to the artifact table. |
| 81 | */ |
| 82 | char *fossil_expand_datetime(const char *zIn,int bVerifyNotAHash,int bRoundUp){ |
| 83 | static char zEDate[24]; |
| 84 | static const char aPunct[] = { 0, 0, '-', '-', ' ', ':', ':' }; |
| 85 | int n = (int)strlen(zIn); |
| 86 | int i, j; |
| 87 | int addZulu = 0; |
| 88 | |
| @@ -701,13 +701,14 @@ | |
| 701 | |
| 702 | /* Undocumented: numeric tags get translated directly into the RID */ |
| 703 | if( strncmp(zTag, "rid:", 4)==0 ){ |
| 704 | zTag += 4; |
| 705 | for(i=0; fossil_isdigit(zTag[i]); i++){} |
| 706 | if( zTag[i]==0 ){ |
| 707 | if( strcmp(zType,"*")==0 ){ |
| 708 | rid = atoi(zTag); |
| 709 | }else{ |
| 710 | rid = db_int(0, |
| 711 | "SELECT event.objid" |
| 712 | " FROM event" |
| 713 | " WHERE event.objid=%s" |
| @@ -1000,10 +1001,12 @@ | |
| 1000 | Stmt q; |
| 1001 | const char *zName = P("name"); |
| 1002 | const char *zSrc = PD("src","info"); |
| 1003 | char *z; |
| 1004 | |
| 1005 | if( zName==0 || zName[0]==0 || zSrc==0 || zSrc[0]==0 ){ |
| 1006 | fossil_redirect_home(); |
| 1007 | } |
| 1008 | style_header("Ambiguous Artifact ID"); |
| 1009 | @ <p>The artifact hash prefix <b>%h(zName)</b> is ambiguous and might |
| @@ -1019,50 +1022,54 @@ | |
| 1019 | @ %s(zUuid)</a> - |
| 1020 | object_description(rid, 0, 0, 0); |
| 1021 | @ </p></li> |
| 1022 | } |
| 1023 | db_finalize(&q); |
| 1024 | db_prepare(&q, |
| 1025 | " SELECT tkt_rid, tkt_uuid, title" |
| 1026 | " FROM ticket, ticketchng" |
| 1027 | " WHERE ticket.tkt_id = ticketchng.tkt_id" |
| 1028 | " AND tkt_uuid GLOB '%q*'" |
| 1029 | " GROUP BY tkt_uuid" |
| 1030 | " ORDER BY tkt_ctime DESC", z); |
| 1031 | while( db_step(&q)==SQLITE_ROW ){ |
| 1032 | int rid = db_column_int(&q, 0); |
| 1033 | const char *zUuid = db_column_text(&q, 1); |
| 1034 | const char *zTitle = db_column_text(&q, 2); |
| 1035 | @ <li><p><a href="%R/%T(zSrc)/%!S(zUuid)"> |
| 1036 | @ %s(zUuid)</a> - |
| 1037 | @ <ul></ul> |
| 1038 | @ Ticket |
| 1039 | hyperlink_to_version(zUuid); |
| 1040 | @ - %h(zTitle). |
| 1041 | @ <ul><li> |
| 1042 | object_description(rid, 0, 0, 0); |
| 1043 | @ </li></ul> |
| 1044 | @ </p></li> |
| 1045 | } |
| 1046 | db_finalize(&q); |
| 1047 | db_prepare(&q, |
| 1048 | "SELECT rid, uuid FROM" |
| 1049 | " (SELECT tagxref.rid AS rid, substr(tagname, 7) AS uuid" |
| 1050 | " FROM tagxref, tag WHERE tagxref.tagid = tag.tagid" |
| 1051 | " AND tagname GLOB 'event-%q*') GROUP BY uuid", z); |
| 1052 | while( db_step(&q)==SQLITE_ROW ){ |
| 1053 | int rid = db_column_int(&q, 0); |
| 1054 | const char* zUuid = db_column_text(&q, 1); |
| 1055 | @ <li><p><a href="%R/%T(zSrc)/%!S(zUuid)"> |
| 1056 | @ %s(zUuid)</a> - |
| 1057 | @ <ul><li> |
| 1058 | object_description(rid, 0, 0, 0); |
| 1059 | @ </li></ul> |
| 1060 | @ </p></li> |
| 1061 | } |
| 1062 | @ </ol> |
| 1063 | db_finalize(&q); |
| 1064 | style_finish_page(); |
| 1065 | } |
| 1066 | |
| 1067 | /* |
| 1068 | ** Convert the name in CGI parameter zParamName into a rid and return that |
| @@ -1239,11 +1246,11 @@ | |
| 1239 | ); |
| 1240 | cnt = 0; |
| 1241 | while( db_step(&q)==SQLITE_ROW ){ |
| 1242 | const char *zTag = (const char*)db_column_text(&q,0); |
| 1243 | if( pOut ){ |
| 1244 | const char *zSep = cnt==0 ? ",tags:[" : ","; |
| 1245 | sqlite3_str_appendf(pOut, "%s%J", zSep, zTag); |
| 1246 | }else{ |
| 1247 | const char *zPrefix = cnt ? ", " : "tags: "; |
| 1248 | fossil_print("%s%s", zPrefix, db_column_text(&q,0)); |
| 1249 | } |
| @@ -1494,14 +1501,16 @@ | |
| 1494 | " ORDER BY mtime LIMIT 1)" |
| 1495 | " FROM tag WHERE tagname GLOB 'tkt-%q*'", |
| 1496 | zC |
| 1497 | ); |
| 1498 | while( db_step(&q)==SQLITE_ROW ){ |
| 1499 | if( pOut ){ |
| 1500 | sqlite3_str_append(pOut, ",", 1); |
| 1501 | }else{ |
| 1502 | fossil_print("%12s---- meaning #%d ----\n", " ", cnt); |
| 1503 | } |
| 1504 | whatis_rid(db_column_int(&q, 0), mFlags, pOut); |
| 1505 | } |
| 1506 | db_finalize(&q); |
| 1507 | } |
| @@ -2036,10 +2045,11 @@ | |
| 2036 | char *zSha3Bg; |
| 2037 | |
| 2038 | login_check_credentials(); |
| 2039 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| 2040 | cgi_check_for_malice(); |
| 2041 | style_header("List Of Artifacts"); |
| 2042 | style_submenu_element("250 Largest", "bigbloblist"); |
| 2043 | if( bRecent==0 || n!=250 ){ |
| 2044 | style_submenu_element("Recent","bloblist?n=250&recent"); |
| 2045 | } |
| @@ -2089,14 +2099,14 @@ | |
| 2089 | }else if( bUnclst ){ |
| 2090 | @ <h2>Unclustered Artifacts</h2> |
| 2091 | zRange = mprintf("IN unclustered"); |
| 2092 | }else if( bRecent ){ |
| 2093 | @ <h2>%d(n) Most Recent Artifacts</h2> |
| 2094 | zRange = mprintf(">=(SELECT rid FROM blob" |
| 2095 | " ORDER BY rid DESC LIMIT 1 OFFSET %d)",n); |
| 2096 | }else{ |
| 2097 | zRange = mprintf("BETWEEN %d AND %d", s, s+n-1); |
| 2098 | } |
| 2099 | describe_artifacts(zRange); |
| 2100 | fossil_free(zRange); |
| 2101 | db_prepare(&q, |
| 2102 | /* 0 1 2 3 4 5 6 */ |
| 2103 |
| --- src/name.c | |
| +++ src/name.c | |
| @@ -78,11 +78,11 @@ | |
| 78 | ** the input string is a hash prefix and NULL is returned if it is. If the |
| 79 | ** bVerifyNotAHash flag is false, then the result is determined by syntax |
| 80 | ** of the input string only, without reference to the artifact table. |
| 81 | */ |
| 82 | char *fossil_expand_datetime(const char *zIn,int bVerifyNotAHash,int bRoundUp){ |
| 83 | static char zEDate[25]; |
| 84 | static const char aPunct[] = { 0, 0, '-', '-', ' ', ':', ':' }; |
| 85 | int n = (int)strlen(zIn); |
| 86 | int i, j; |
| 87 | int addZulu = 0; |
| 88 | |
| @@ -701,13 +701,14 @@ | |
| 701 | |
| 702 | /* Undocumented: numeric tags get translated directly into the RID */ |
| 703 | if( strncmp(zTag, "rid:", 4)==0 ){ |
| 704 | zTag += 4; |
| 705 | for(i=0; fossil_isdigit(zTag[i]); i++){} |
| 706 | if( i>0 && zTag[i]==0 ){ |
| 707 | if( strcmp(zType,"*")==0 ){ |
| 708 | rid = db_int(0, "SELECT rid FROM blob WHERE rid=%s", |
| 709 | zTag /*safe-for-%s*/); |
| 710 | }else{ |
| 711 | rid = db_int(0, |
| 712 | "SELECT event.objid" |
| 713 | " FROM event" |
| 714 | " WHERE event.objid=%s" |
| @@ -1000,10 +1001,12 @@ | |
| 1001 | Stmt q; |
| 1002 | const char *zName = P("name"); |
| 1003 | const char *zSrc = PD("src","info"); |
| 1004 | char *z; |
| 1005 | |
| 1006 | login_check_credentials(); |
| 1007 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| 1008 | if( zName==0 || zName[0]==0 || zSrc==0 || zSrc[0]==0 ){ |
| 1009 | fossil_redirect_home(); |
| 1010 | } |
| 1011 | style_header("Ambiguous Artifact ID"); |
| 1012 | @ <p>The artifact hash prefix <b>%h(zName)</b> is ambiguous and might |
| @@ -1019,50 +1022,54 @@ | |
| 1022 | @ %s(zUuid)</a> - |
| 1023 | object_description(rid, 0, 0, 0); |
| 1024 | @ </p></li> |
| 1025 | } |
| 1026 | db_finalize(&q); |
| 1027 | if( g.perm.RdTkt ){ |
| 1028 | db_prepare(&q, |
| 1029 | " SELECT tkt_rid, tkt_uuid, title" |
| 1030 | " FROM ticket, ticketchng" |
| 1031 | " WHERE ticket.tkt_id = ticketchng.tkt_id" |
| 1032 | " AND tkt_uuid GLOB '%q*'" |
| 1033 | " GROUP BY tkt_uuid" |
| 1034 | " ORDER BY tkt_ctime DESC", z); |
| 1035 | while( db_step(&q)==SQLITE_ROW ){ |
| 1036 | int rid = db_column_int(&q, 0); |
| 1037 | const char *zUuid = db_column_text(&q, 1); |
| 1038 | const char *zTitle = db_column_text(&q, 2); |
| 1039 | @ <li><p><a href="%R/%T(zSrc)/%!S(zUuid)"> |
| 1040 | @ %s(zUuid)</a> - |
| 1041 | @ <ul></ul> |
| 1042 | @ Ticket |
| 1043 | hyperlink_to_version(zUuid); |
| 1044 | @ - %h(zTitle). |
| 1045 | @ <ul><li> |
| 1046 | object_description(rid, 0, 0, 0); |
| 1047 | @ </li></ul> |
| 1048 | @ </p></li> |
| 1049 | } |
| 1050 | db_finalize(&q); |
| 1051 | } |
| 1052 | if( g.perm.RdWiki ){ |
| 1053 | db_prepare(&q, |
| 1054 | "SELECT rid, uuid FROM" |
| 1055 | " (SELECT tagxref.rid AS rid, substr(tagname, 7) AS uuid" |
| 1056 | " FROM tagxref, tag WHERE tagxref.tagid = tag.tagid" |
| 1057 | " AND tagname GLOB 'event-%q*') GROUP BY uuid", z); |
| 1058 | while( db_step(&q)==SQLITE_ROW ){ |
| 1059 | int rid = db_column_int(&q, 0); |
| 1060 | const char* zUuid = db_column_text(&q, 1); |
| 1061 | @ <li><p><a href="%R/%T(zSrc)/%!S(zUuid)"> |
| 1062 | @ %s(zUuid)</a> - |
| 1063 | @ <ul><li> |
| 1064 | object_description(rid, 0, 0, 0); |
| 1065 | @ </li></ul> |
| 1066 | @ </p></li> |
| 1067 | } |
| 1068 | db_finalize(&q); |
| 1069 | } |
| 1070 | @ </ol> |
| 1071 | style_finish_page(); |
| 1072 | } |
| 1073 | |
| 1074 | /* |
| 1075 | ** Convert the name in CGI parameter zParamName into a rid and return that |
| @@ -1239,11 +1246,11 @@ | |
| 1246 | ); |
| 1247 | cnt = 0; |
| 1248 | while( db_step(&q)==SQLITE_ROW ){ |
| 1249 | const char *zTag = (const char*)db_column_text(&q,0); |
| 1250 | if( pOut ){ |
| 1251 | const char *zSep = cnt==0 ? ",\"tags\":[" : ","; |
| 1252 | sqlite3_str_appendf(pOut, "%s%J", zSep, zTag); |
| 1253 | }else{ |
| 1254 | const char *zPrefix = cnt ? ", " : "tags: "; |
| 1255 | fossil_print("%s%s", zPrefix, db_column_text(&q,0)); |
| 1256 | } |
| @@ -1494,14 +1501,16 @@ | |
| 1501 | " ORDER BY mtime LIMIT 1)" |
| 1502 | " FROM tag WHERE tagname GLOB 'tkt-%q*'", |
| 1503 | zC |
| 1504 | ); |
| 1505 | while( db_step(&q)==SQLITE_ROW ){ |
| 1506 | if( cnt++ ){ |
| 1507 | if( pOut ){ |
| 1508 | sqlite3_str_append(pOut, ",", 1); |
| 1509 | }else{ |
| 1510 | fossil_print("%12s---- meaning #%d ----\n", " ", cnt); |
| 1511 | } |
| 1512 | } |
| 1513 | whatis_rid(db_column_int(&q, 0), mFlags, pOut); |
| 1514 | } |
| 1515 | db_finalize(&q); |
| 1516 | } |
| @@ -2036,10 +2045,11 @@ | |
| 2045 | char *zSha3Bg; |
| 2046 | |
| 2047 | login_check_credentials(); |
| 2048 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| 2049 | cgi_check_for_malice(); |
| 2050 | if( n<1 ) n = 1; |
| 2051 | style_header("List Of Artifacts"); |
| 2052 | style_submenu_element("250 Largest", "bigbloblist"); |
| 2053 | if( bRecent==0 || n!=250 ){ |
| 2054 | style_submenu_element("Recent","bloblist?n=250&recent"); |
| 2055 | } |
| @@ -2089,14 +2099,14 @@ | |
| 2099 | }else if( bUnclst ){ |
| 2100 | @ <h2>Unclustered Artifacts</h2> |
| 2101 | zRange = mprintf("IN unclustered"); |
| 2102 | }else if( bRecent ){ |
| 2103 | @ <h2>%d(n) Most Recent Artifacts</h2> |
| 2104 | zRange = mprintf("IN (SELECT rid FROM blob" |
| 2105 | " ORDER BY rid DESC LIMIT %d)",n); |
| 2106 | }else{ |
| 2107 | zRange = mprintf("BETWEEN %d AND %lld", s, (i64)s+n-1); |
| 2108 | } |
| 2109 | describe_artifacts(zRange); |
| 2110 | fossil_free(zRange); |
| 2111 | db_prepare(&q, |
| 2112 | /* 0 1 2 3 4 5 6 */ |
| 2113 |
+4
-1
| --- src/purge.c | ||
| +++ src/purge.c | ||
| @@ -356,11 +356,14 @@ | ||
| 356 | 356 | " WHERE piid=%d", piid); |
| 357 | 357 | if( db_step(&q)!=SQLITE_ROW ){ |
| 358 | 358 | db_finalize(&q); |
| 359 | 359 | fossil_fatal("missing purge-item %d", piid); |
| 360 | 360 | } |
| 361 | - if( bag_find(&busy, piid) ) return 1; | |
| 361 | + if( bag_find(&busy, piid) ){ | |
| 362 | + db_finalize(&q); | |
| 363 | + fossil_fatal("purge-item %d is part of a delta cycle", piid); | |
| 364 | + } | |
| 362 | 365 | srcid = db_column_int(&q, 1); |
| 363 | 366 | blob_zero(pOut); |
| 364 | 367 | blob_zero(&x); |
| 365 | 368 | db_column_blob(&q, 2, &x); |
| 366 | 369 | blob_uncompress(&x, pOut); |
| 367 | 370 |
| --- src/purge.c | |
| +++ src/purge.c | |
| @@ -356,11 +356,14 @@ | |
| 356 | " WHERE piid=%d", piid); |
| 357 | if( db_step(&q)!=SQLITE_ROW ){ |
| 358 | db_finalize(&q); |
| 359 | fossil_fatal("missing purge-item %d", piid); |
| 360 | } |
| 361 | if( bag_find(&busy, piid) ) return 1; |
| 362 | srcid = db_column_int(&q, 1); |
| 363 | blob_zero(pOut); |
| 364 | blob_zero(&x); |
| 365 | db_column_blob(&q, 2, &x); |
| 366 | blob_uncompress(&x, pOut); |
| 367 |
| --- src/purge.c | |
| +++ src/purge.c | |
| @@ -356,11 +356,14 @@ | |
| 356 | " WHERE piid=%d", piid); |
| 357 | if( db_step(&q)!=SQLITE_ROW ){ |
| 358 | db_finalize(&q); |
| 359 | fossil_fatal("missing purge-item %d", piid); |
| 360 | } |
| 361 | if( bag_find(&busy, piid) ){ |
| 362 | db_finalize(&q); |
| 363 | fossil_fatal("purge-item %d is part of a delta cycle", piid); |
| 364 | } |
| 365 | srcid = db_column_int(&q, 1); |
| 366 | blob_zero(pOut); |
| 367 | blob_zero(&x); |
| 368 | db_column_blob(&q, 2, &x); |
| 369 | blob_uncompress(&x, pOut); |
| 370 |
+3
-2
| --- src/rebuild.c | ||
| +++ src/rebuild.c | ||
| @@ -747,12 +747,12 @@ | ||
| 747 | 747 | /* We should be done with options.. */ |
| 748 | 748 | verify_all_options(); |
| 749 | 749 | |
| 750 | 750 | db_begin_transaction(); |
| 751 | 751 | db_unprotect(PROTECT_ALL); |
| 752 | + if( !compressOnlyFlag || runReindex ) search_drop_index(); | |
| 752 | 753 | if( !compressOnlyFlag ){ |
| 753 | - search_drop_index(); | |
| 754 | 754 | ttyOutput = 1; |
| 755 | 755 | errCnt = rebuild_db(1, doClustering); |
| 756 | 756 | reconstruct_private_table(); |
| 757 | 757 | } |
| 758 | 758 | db_multi_exec( |
| @@ -1408,10 +1408,11 @@ | ||
| 1408 | 1408 | /* Newer method: Import the list of private artifacts to the PRIVATE table. */ |
| 1409 | 1409 | if( fKeepPrivate ){ |
| 1410 | 1410 | char *zFnDotPrivate = mprintf("%s/.private", g.argv[3]); |
| 1411 | 1411 | private_import(zFnDotPrivate); |
| 1412 | 1412 | free(zFnDotPrivate); |
| 1413 | + fix_private_blob_dependencies(0); | |
| 1413 | 1414 | } |
| 1414 | 1415 | |
| 1415 | 1416 | /* Skip the verify_before_commit() step on a reconstruct. Most artifacts |
| 1416 | 1417 | ** will have been changed and verification therefore takes a really, really |
| 1417 | 1418 | ** long time. |
| @@ -1478,11 +1479,11 @@ | ||
| 1478 | 1479 | if( g.argc!=3 ){ |
| 1479 | 1480 | usage ("?OPTIONS? DESTINATION"); |
| 1480 | 1481 | } |
| 1481 | 1482 | /* get and check argument destination directory */ |
| 1482 | 1483 | zDestDir = g.argv[g.argc-1]; |
| 1483 | - if( !*zDestDir || !file_isdir(zDestDir, ExtFILE)) { | |
| 1484 | + if( !*zDestDir || file_isdir(zDestDir, ExtFILE)!=1) { | |
| 1484 | 1485 | fossil_fatal("DESTINATION(%s) is not a directory!",zDestDir); |
| 1485 | 1486 | } |
| 1486 | 1487 | #ifndef _WIN32 |
| 1487 | 1488 | if( file_access(zDestDir, W_OK) ){ |
| 1488 | 1489 | fossil_fatal("DESTINATION(%s) is not writeable!",zDestDir); |
| 1489 | 1490 |
| --- src/rebuild.c | |
| +++ src/rebuild.c | |
| @@ -747,12 +747,12 @@ | |
| 747 | /* We should be done with options.. */ |
| 748 | verify_all_options(); |
| 749 | |
| 750 | db_begin_transaction(); |
| 751 | db_unprotect(PROTECT_ALL); |
| 752 | if( !compressOnlyFlag ){ |
| 753 | search_drop_index(); |
| 754 | ttyOutput = 1; |
| 755 | errCnt = rebuild_db(1, doClustering); |
| 756 | reconstruct_private_table(); |
| 757 | } |
| 758 | db_multi_exec( |
| @@ -1408,10 +1408,11 @@ | |
| 1408 | /* Newer method: Import the list of private artifacts to the PRIVATE table. */ |
| 1409 | if( fKeepPrivate ){ |
| 1410 | char *zFnDotPrivate = mprintf("%s/.private", g.argv[3]); |
| 1411 | private_import(zFnDotPrivate); |
| 1412 | free(zFnDotPrivate); |
| 1413 | } |
| 1414 | |
| 1415 | /* Skip the verify_before_commit() step on a reconstruct. Most artifacts |
| 1416 | ** will have been changed and verification therefore takes a really, really |
| 1417 | ** long time. |
| @@ -1478,11 +1479,11 @@ | |
| 1478 | if( g.argc!=3 ){ |
| 1479 | usage ("?OPTIONS? DESTINATION"); |
| 1480 | } |
| 1481 | /* get and check argument destination directory */ |
| 1482 | zDestDir = g.argv[g.argc-1]; |
| 1483 | if( !*zDestDir || !file_isdir(zDestDir, ExtFILE)) { |
| 1484 | fossil_fatal("DESTINATION(%s) is not a directory!",zDestDir); |
| 1485 | } |
| 1486 | #ifndef _WIN32 |
| 1487 | if( file_access(zDestDir, W_OK) ){ |
| 1488 | fossil_fatal("DESTINATION(%s) is not writeable!",zDestDir); |
| 1489 |
| --- src/rebuild.c | |
| +++ src/rebuild.c | |
| @@ -747,12 +747,12 @@ | |
| 747 | /* We should be done with options.. */ |
| 748 | verify_all_options(); |
| 749 | |
| 750 | db_begin_transaction(); |
| 751 | db_unprotect(PROTECT_ALL); |
| 752 | if( !compressOnlyFlag || runReindex ) search_drop_index(); |
| 753 | if( !compressOnlyFlag ){ |
| 754 | ttyOutput = 1; |
| 755 | errCnt = rebuild_db(1, doClustering); |
| 756 | reconstruct_private_table(); |
| 757 | } |
| 758 | db_multi_exec( |
| @@ -1408,10 +1408,11 @@ | |
| 1408 | /* Newer method: Import the list of private artifacts to the PRIVATE table. */ |
| 1409 | if( fKeepPrivate ){ |
| 1410 | char *zFnDotPrivate = mprintf("%s/.private", g.argv[3]); |
| 1411 | private_import(zFnDotPrivate); |
| 1412 | free(zFnDotPrivate); |
| 1413 | fix_private_blob_dependencies(0); |
| 1414 | } |
| 1415 | |
| 1416 | /* Skip the verify_before_commit() step on a reconstruct. Most artifacts |
| 1417 | ** will have been changed and verification therefore takes a really, really |
| 1418 | ** long time. |
| @@ -1478,11 +1479,11 @@ | |
| 1479 | if( g.argc!=3 ){ |
| 1480 | usage ("?OPTIONS? DESTINATION"); |
| 1481 | } |
| 1482 | /* get and check argument destination directory */ |
| 1483 | zDestDir = g.argv[g.argc-1]; |
| 1484 | if( !*zDestDir || file_isdir(zDestDir, ExtFILE)!=1) { |
| 1485 | fossil_fatal("DESTINATION(%s) is not a directory!",zDestDir); |
| 1486 | } |
| 1487 | #ifndef _WIN32 |
| 1488 | if( file_access(zDestDir, W_OK) ){ |
| 1489 | fossil_fatal("DESTINATION(%s) is not writeable!",zDestDir); |
| 1490 |
+1
-1
| --- src/setupuser.c | ||
| +++ src/setupuser.c | ||
| @@ -518,11 +518,11 @@ | ||
| 518 | 518 | |
| 519 | 519 | /* If we have all the necessary information, write the new or |
| 520 | 520 | ** modified user record. After writing the user record, redirect |
| 521 | 521 | ** to the page that displays a list of users. |
| 522 | 522 | */ |
| 523 | - if( !cgi_all("login","info","pw","apply") ){ | |
| 523 | + if( !cgi_all("login","info","pw","apply",(char*)0) ){ | |
| 524 | 524 | /* need all of the above properties to make a change. Since one or |
| 525 | 525 | ** more are missing, no-op */ |
| 526 | 526 | }else if( higherUser ){ |
| 527 | 527 | /* An Admin (a) user cannot edit a Superuser (s) */ |
| 528 | 528 | }else if( zDeleteVerify!=0 ){ |
| 529 | 529 |
| --- src/setupuser.c | |
| +++ src/setupuser.c | |
| @@ -518,11 +518,11 @@ | |
| 518 | |
| 519 | /* If we have all the necessary information, write the new or |
| 520 | ** modified user record. After writing the user record, redirect |
| 521 | ** to the page that displays a list of users. |
| 522 | */ |
| 523 | if( !cgi_all("login","info","pw","apply") ){ |
| 524 | /* need all of the above properties to make a change. Since one or |
| 525 | ** more are missing, no-op */ |
| 526 | }else if( higherUser ){ |
| 527 | /* An Admin (a) user cannot edit a Superuser (s) */ |
| 528 | }else if( zDeleteVerify!=0 ){ |
| 529 |
| --- src/setupuser.c | |
| +++ src/setupuser.c | |
| @@ -518,11 +518,11 @@ | |
| 518 | |
| 519 | /* If we have all the necessary information, write the new or |
| 520 | ** modified user record. After writing the user record, redirect |
| 521 | ** to the page that displays a list of users. |
| 522 | */ |
| 523 | if( !cgi_all("login","info","pw","apply",(char*)0) ){ |
| 524 | /* need all of the above properties to make a change. Since one or |
| 525 | ** more are missing, no-op */ |
| 526 | }else if( higherUser ){ |
| 527 | /* An Admin (a) user cannot edit a Superuser (s) */ |
| 528 | }else if( zDeleteVerify!=0 ){ |
| 529 |
+2
| --- src/sync.c | ||
| +++ src/sync.c | ||
| @@ -876,15 +876,17 @@ | ||
| 876 | 876 | || sqlite3_strlike("https://%",zArg,0)==0 |
| 877 | 877 | || sqlite3_strlike("ssh:%",zArg,0)==0 |
| 878 | 878 | || sqlite3_strlike("file:%",zArg,0)==0 |
| 879 | 879 | || db_exists("SELECT 1 FROM config WHERE name='sync-url:%q'",zArg) |
| 880 | 880 | ){ |
| 881 | + db_begin_transaction(); | |
| 881 | 882 | db_unset("last-sync-url", 0); |
| 882 | 883 | db_unset("last-sync-pw", 0); |
| 883 | 884 | url_parse(g.argv[2], URL_REMEMBER|URL_PROMPT_PW| |
| 884 | 885 | URL_USE_CONFIG|URL_ASK_REMEMBER_PW); |
| 885 | 886 | url_remember(); |
| 887 | + db_commit_transaction(); | |
| 886 | 888 | return; |
| 887 | 889 | } |
| 888 | 890 | fossil_fatal("unknown command \"%s\" - should be a URL or one of: " |
| 889 | 891 | "add delete hyperlink list off scrub", zArg); |
| 890 | 892 | } |
| 891 | 893 |
| --- src/sync.c | |
| +++ src/sync.c | |
| @@ -876,15 +876,17 @@ | |
| 876 | || sqlite3_strlike("https://%",zArg,0)==0 |
| 877 | || sqlite3_strlike("ssh:%",zArg,0)==0 |
| 878 | || sqlite3_strlike("file:%",zArg,0)==0 |
| 879 | || db_exists("SELECT 1 FROM config WHERE name='sync-url:%q'",zArg) |
| 880 | ){ |
| 881 | db_unset("last-sync-url", 0); |
| 882 | db_unset("last-sync-pw", 0); |
| 883 | url_parse(g.argv[2], URL_REMEMBER|URL_PROMPT_PW| |
| 884 | URL_USE_CONFIG|URL_ASK_REMEMBER_PW); |
| 885 | url_remember(); |
| 886 | return; |
| 887 | } |
| 888 | fossil_fatal("unknown command \"%s\" - should be a URL or one of: " |
| 889 | "add delete hyperlink list off scrub", zArg); |
| 890 | } |
| 891 |
| --- src/sync.c | |
| +++ src/sync.c | |
| @@ -876,15 +876,17 @@ | |
| 876 | || sqlite3_strlike("https://%",zArg,0)==0 |
| 877 | || sqlite3_strlike("ssh:%",zArg,0)==0 |
| 878 | || sqlite3_strlike("file:%",zArg,0)==0 |
| 879 | || db_exists("SELECT 1 FROM config WHERE name='sync-url:%q'",zArg) |
| 880 | ){ |
| 881 | db_begin_transaction(); |
| 882 | db_unset("last-sync-url", 0); |
| 883 | db_unset("last-sync-pw", 0); |
| 884 | url_parse(g.argv[2], URL_REMEMBER|URL_PROMPT_PW| |
| 885 | URL_USE_CONFIG|URL_ASK_REMEMBER_PW); |
| 886 | url_remember(); |
| 887 | db_commit_transaction(); |
| 888 | return; |
| 889 | } |
| 890 | fossil_fatal("unknown command \"%s\" - should be a URL or one of: " |
| 891 | "add delete hyperlink list off scrub", zArg); |
| 892 | } |
| 893 |
+52
-21
| --- src/th_main.c | ||
| +++ src/th_main.c | ||
| @@ -427,10 +427,11 @@ | ||
| 427 | 427 | if( zFilename==0 ){ |
| 428 | 428 | Th_SetResult(interp, "invalid file name", -1); |
| 429 | 429 | return 0; |
| 430 | 430 | } |
| 431 | 431 | cirid = th1_name_to_typed_rid(interp, zCI, "*"); |
| 432 | + if( cirid<0 ) return 0; | |
| 432 | 433 | blob_zero(&err); |
| 433 | 434 | pManifest = manifest_get(cirid, CFTYPE_MANIFEST, &err); |
| 434 | 435 | if( pManifest==0 ){ |
| 435 | 436 | if( blob_size(&err)>0 ){ |
| 436 | 437 | Th_SetResult(interp, blob_str(&err), blob_size(&err)); |
| @@ -520,10 +521,18 @@ | ||
| 520 | 521 | ){ |
| 521 | 522 | int withMethod = 0; |
| 522 | 523 | if( argc!=2 && argc!=3 ){ |
| 523 | 524 | return Th_WrongNumArgs(interp, "redirect URL ?withMethod?"); |
| 524 | 525 | } |
| 526 | + if( g.httpOut==0 | |
| 527 | + || (g.zBaseURL==0 && fossil_strncmp(argv[1],"http:",5)!=0 | |
| 528 | + && fossil_strncmp(argv[1],"https:",6)!=0) | |
| 529 | + ){ | |
| 530 | + Th_ErrorMessage(interp, "redirect is only allowed in a web request", | |
| 531 | + 0, 0); | |
| 532 | + return TH_ERROR; | |
| 533 | + } | |
| 525 | 534 | if( argc==3 ){ |
| 526 | 535 | if( Th_ToInt(interp, argv[2], argl[2], &withMethod) ){ |
| 527 | 536 | return TH_ERROR; |
| 528 | 537 | } |
| 529 | 538 | } |
| @@ -1124,11 +1133,14 @@ | ||
| 1124 | 1133 | int *aszElem; |
| 1125 | 1134 | char **azElem; |
| 1126 | 1135 | int i; |
| 1127 | 1136 | |
| 1128 | 1137 | if( Th_ToInt(interp, argv[3], argl[3], &height) ) return TH_ERROR; |
| 1129 | - Th_SplitList(interp, argv[2], TH1_LEN(argl[2]), &azElem, &aszElem, &nElem); | |
| 1138 | + if( Th_SplitList(interp, argv[2], TH1_LEN(argl[2]), | |
| 1139 | + &azElem, &aszElem, &nElem) ){ | |
| 1140 | + return TH_ERROR; | |
| 1141 | + } | |
| 1130 | 1142 | blob_init(&name, (char*)argv[1], TH1_LEN(argl[1])); |
| 1131 | 1143 | zValue = Th_Fetch(blob_str(&name), &nValue); |
| 1132 | 1144 | nValue = TH1_LEN(nValue); |
| 1133 | 1145 | zH = htmlize(blob_buffer(&name), blob_size(&name)); |
| 1134 | 1146 | z = mprintf("<select id=\"%s\" name=\"%s\" size=\"%d\">", zH, zH, height); |
| @@ -1643,11 +1655,19 @@ | ||
| 1643 | 1655 | int *argl |
| 1644 | 1656 | ){ |
| 1645 | 1657 | if( argc!=2 ){ |
| 1646 | 1658 | return Th_WrongNumArgs(interp, "builtin_request_js NAME"); |
| 1647 | 1659 | } |
| 1648 | - builtin_request_js(argv[1]); | |
| 1660 | + switch( builtin_try_request_js(argv[1]) ){ | |
| 1661 | + case 1: | |
| 1662 | + Th_ErrorMessage(interp, "unknown javascript file:", | |
| 1663 | + argv[1], TH1_LEN(argl[1])); | |
| 1664 | + return TH_ERROR; | |
| 1665 | + case 2: | |
| 1666 | + Th_ErrorMessage(interp, "too many javascript files requested", 0, 0); | |
| 1667 | + return TH_ERROR; | |
| 1668 | + } | |
| 1649 | 1669 | return TH_OK; |
| 1650 | 1670 | } |
| 1651 | 1671 | |
| 1652 | 1672 | /* |
| 1653 | 1673 | ** TH1 command: artifact ID ?FILENAME? |
| @@ -1672,11 +1692,11 @@ | ||
| 1672 | 1692 | if( argc==3 ){ |
| 1673 | 1693 | rid = th1_artifact_from_ci_and_filename(interp, argv[1], argv[2]); |
| 1674 | 1694 | }else{ |
| 1675 | 1695 | rid = th1_name_to_typed_rid(interp, argv[1], "*"); |
| 1676 | 1696 | } |
| 1677 | - if( rid!=0 && content_get(rid, &content) ){ | |
| 1697 | + if( rid>0 && content_get(rid, &content) ){ | |
| 1678 | 1698 | Th_SetResult(interp, blob_str(&content), blob_size(&content)); |
| 1679 | 1699 | blob_reset(&content); |
| 1680 | 1700 | return TH_OK; |
| 1681 | 1701 | }else{ |
| 1682 | 1702 | return TH_ERROR; |
| @@ -1723,11 +1743,13 @@ | ||
| 1723 | 1743 | if( argc!=3 ){ |
| 1724 | 1744 | return Th_WrongNumArgs(interp, "unversioned content FILENAME"); |
| 1725 | 1745 | } |
| 1726 | 1746 | if( Th_IsRepositoryOpen() ){ |
| 1727 | 1747 | Blob content; |
| 1728 | - if( unversioned_content(argv[2], &content)!=0 ){ | |
| 1748 | + if( db_table_exists("repository", "unversioned") | |
| 1749 | + && unversioned_content(argv[2], &content)!=0 | |
| 1750 | + ){ | |
| 1729 | 1751 | Th_SetResult(interp, blob_str(&content), blob_size(&content)); |
| 1730 | 1752 | blob_reset(&content); |
| 1731 | 1753 | return TH_OK; |
| 1732 | 1754 | }else{ |
| 1733 | 1755 | return TH_ERROR; |
| @@ -1756,16 +1778,18 @@ | ||
| 1756 | 1778 | } |
| 1757 | 1779 | if( Th_IsRepositoryOpen() ){ |
| 1758 | 1780 | Stmt q; |
| 1759 | 1781 | char *zList = 0; |
| 1760 | 1782 | int nList = 0; |
| 1761 | - db_prepare(&q, "SELECT name FROM unversioned WHERE hash IS NOT NULL" | |
| 1762 | - " ORDER BY name"); | |
| 1763 | - while( db_step(&q)==SQLITE_ROW ){ | |
| 1764 | - Th_ListAppend(interp, &zList, &nList, db_column_text(&q,0), -1); | |
| 1783 | + if( db_table_exists("repository", "unversioned") ){ | |
| 1784 | + db_prepare(&q, "SELECT name FROM unversioned WHERE hash IS NOT NULL" | |
| 1785 | + " ORDER BY name"); | |
| 1786 | + while( db_step(&q)==SQLITE_ROW ){ | |
| 1787 | + Th_ListAppend(interp, &zList, &nList, db_column_text(&q,0), -1); | |
| 1788 | + } | |
| 1789 | + db_finalize(&q); | |
| 1765 | 1790 | } |
| 1766 | - db_finalize(&q); | |
| 1767 | 1791 | Th_SetResult(interp, zList, nList); |
| 1768 | 1792 | Th_Free(interp, zList); |
| 1769 | 1793 | return TH_OK; |
| 1770 | 1794 | }else{ |
| 1771 | 1795 | Th_SetResult(interp, "repository unavailable", -1); |
| @@ -1882,13 +1906,13 @@ | ||
| 1882 | 1906 | const char **argv, |
| 1883 | 1907 | int *argl |
| 1884 | 1908 | ){ |
| 1885 | 1909 | int n; |
| 1886 | 1910 | unsigned char aRand[50]; |
| 1887 | - unsigned char zOut[100]; | |
| 1911 | + unsigned char zOut[sizeof(aRand)*2+1]; | |
| 1888 | 1912 | if( argc!=1 && argc!=2 ){ |
| 1889 | - return Th_WrongNumArgs(interp, "repository ?BOOLEAN?"); | |
| 1913 | + return Th_WrongNumArgs(interp, "randhex ?N?"); | |
| 1890 | 1914 | } |
| 1891 | 1915 | if( argc==2 ){ |
| 1892 | 1916 | if( Th_ToInt(interp, argv[1], argl[1], &n) ){ |
| 1893 | 1917 | return TH_ERROR; |
| 1894 | 1918 | } |
| @@ -1970,11 +1994,11 @@ | ||
| 1970 | 1994 | |
| 1971 | 1995 | while( res==TH_OK && nSql>0 ){ |
| 1972 | 1996 | zErr = 0; |
| 1973 | 1997 | report_restrict_sql(&zErr); |
| 1974 | 1998 | g.dbIgnoreErrors++; |
| 1975 | - rc = sqlite3_prepare_v2(g.db, argv[1], TH1_LEN(argl[1]), &pStmt, &zTail); | |
| 1999 | + rc = sqlite3_prepare_v2(g.db, zSql, nSql, &pStmt, &zTail); | |
| 1976 | 2000 | g.dbIgnoreErrors--; |
| 1977 | 2001 | report_unrestrict_sql(); |
| 1978 | 2002 | if( rc!=0 || zErr!=0 ){ |
| 1979 | 2003 | if( noComplain ) return TH_OK; |
| 1980 | 2004 | Th_ErrorMessage(interp, "SQL error: ", |
| @@ -1982,11 +2006,14 @@ | ||
| 1982 | 2006 | return TH_ERROR; |
| 1983 | 2007 | } |
| 1984 | 2008 | n = (int)(zTail - zSql); |
| 1985 | 2009 | zSql += n; |
| 1986 | 2010 | nSql -= n; |
| 1987 | - if( pStmt==0 ) continue; | |
| 2011 | + if( pStmt==0 ){ | |
| 2012 | + if( n==0 ) break; | |
| 2013 | + continue; | |
| 2014 | + } | |
| 1988 | 2015 | nVar = sqlite3_bind_parameter_count(pStmt); |
| 1989 | 2016 | for(i=1; i<=nVar; i++){ |
| 1990 | 2017 | const char *zVar = sqlite3_bind_parameter_name(pStmt, i); |
| 1991 | 2018 | int szVar = zVar ? th_strlen(zVar) : 0; |
| 1992 | 2019 | if( szVar>1 && zVar[0]=='$' |
| @@ -2048,11 +2075,11 @@ | ||
| 2048 | 2075 | return Th_WrongNumArgs(interp, SETTING_WRONGNUMARGS); |
| 2049 | 2076 | } |
| 2050 | 2077 | if( fossil_strcmp(argv[nArg], "-strict")==0 ){ |
| 2051 | 2078 | strict = 1; nArg++; |
| 2052 | 2079 | } |
| 2053 | - if( fossil_strcmp(argv[nArg], "--")==0 ) nArg++; | |
| 2080 | + if( nArg<argc && fossil_strcmp(argv[nArg], "--")==0 ) nArg++; | |
| 2054 | 2081 | if( nArg+1!=argc ){ |
| 2055 | 2082 | return Th_WrongNumArgs(interp, SETTING_WRONGNUMARGS); |
| 2056 | 2083 | } |
| 2057 | 2084 | zValue = db_get(argv[nArg], 0); |
| 2058 | 2085 | if( zValue!=0 ){ |
| @@ -2187,23 +2214,27 @@ | ||
| 2187 | 2214 | UrlData urlData; |
| 2188 | 2215 | |
| 2189 | 2216 | if( argc<2 || argc>5 ){ |
| 2190 | 2217 | return Th_WrongNumArgs(interp, HTTP_WRONGNUMARGS); |
| 2191 | 2218 | } |
| 2192 | - if( fossil_strnicmp(argv[nArg], "-asynchronous", TH1_LEN(argl[nArg]))==0 ){ | |
| 2219 | + if( TH1_LEN(argl[nArg])>0 | |
| 2220 | + && fossil_strnicmp(argv[nArg], "-asynchronous", TH1_LEN(argl[nArg]))==0 | |
| 2221 | + ){ | |
| 2193 | 2222 | fAsynchronous = 1; nArg++; |
| 2194 | 2223 | } |
| 2195 | - if( fossil_strcmp(argv[nArg], "--")==0 ) nArg++; | |
| 2224 | + if( nArg<argc && fossil_strcmp(argv[nArg], "--")==0 ) nArg++; | |
| 2196 | 2225 | if( nArg+1!=argc && nArg+2!=argc ){ |
| 2197 | - return Th_WrongNumArgs(interp, REGEXP_WRONGNUMARGS); | |
| 2226 | + return Th_WrongNumArgs(interp, HTTP_WRONGNUMARGS); | |
| 2198 | 2227 | } |
| 2199 | - memset(&urlData, '\0', sizeof(urlData)); | |
| 2200 | - url_parse_local(argv[nArg], 0, &urlData); | |
| 2201 | - if( urlData.isSsh || urlData.isFile ){ | |
| 2228 | + if( fossil_strnicmp(argv[nArg], "http://", 7)!=0 | |
| 2229 | + && fossil_strnicmp(argv[nArg], "https://", 8)!=0 | |
| 2230 | + ){ | |
| 2202 | 2231 | Th_ErrorMessage(interp, "url must be http:// or https://", 0, 0); |
| 2203 | 2232 | return TH_ERROR; |
| 2204 | 2233 | } |
| 2234 | + memset(&urlData, '\0', sizeof(urlData)); | |
| 2235 | + url_parse_local(argv[nArg], 0, &urlData); | |
| 2205 | 2236 | zRegexp = db_get("th1-uri-regexp", 0); |
| 2206 | 2237 | if( zRegexp && zRegexp[0] ){ |
| 2207 | 2238 | const char *zErr = fossil_re_compile(&pRe, zRegexp, 0); |
| 2208 | 2239 | if( zErr ){ |
| 2209 | 2240 | Th_SetResult(interp, zErr, -1); |
| @@ -2971,11 +3002,11 @@ | ||
| 2971 | 3002 | } |
| 2972 | 3003 | } |
| 2973 | 3004 | if( rc==TH_ERROR ){ |
| 2974 | 3005 | zResult = (char*)Th_GetResult(g.interp, &n); |
| 2975 | 3006 | sendError(pOut,zResult, n, 1); |
| 2976 | - }else{ | |
| 3007 | + }else if( rc==TH_OK ){ | |
| 2977 | 3008 | sendText(pOut,z, i, 0); |
| 2978 | 3009 | } |
| 2979 | 3010 | Th_SetOutputBlob(origOut); |
| 2980 | 3011 | return rc; |
| 2981 | 3012 | } |
| 2982 | 3013 |
| --- src/th_main.c | |
| +++ src/th_main.c | |
| @@ -427,10 +427,11 @@ | |
| 427 | if( zFilename==0 ){ |
| 428 | Th_SetResult(interp, "invalid file name", -1); |
| 429 | return 0; |
| 430 | } |
| 431 | cirid = th1_name_to_typed_rid(interp, zCI, "*"); |
| 432 | blob_zero(&err); |
| 433 | pManifest = manifest_get(cirid, CFTYPE_MANIFEST, &err); |
| 434 | if( pManifest==0 ){ |
| 435 | if( blob_size(&err)>0 ){ |
| 436 | Th_SetResult(interp, blob_str(&err), blob_size(&err)); |
| @@ -520,10 +521,18 @@ | |
| 520 | ){ |
| 521 | int withMethod = 0; |
| 522 | if( argc!=2 && argc!=3 ){ |
| 523 | return Th_WrongNumArgs(interp, "redirect URL ?withMethod?"); |
| 524 | } |
| 525 | if( argc==3 ){ |
| 526 | if( Th_ToInt(interp, argv[2], argl[2], &withMethod) ){ |
| 527 | return TH_ERROR; |
| 528 | } |
| 529 | } |
| @@ -1124,11 +1133,14 @@ | |
| 1124 | int *aszElem; |
| 1125 | char **azElem; |
| 1126 | int i; |
| 1127 | |
| 1128 | if( Th_ToInt(interp, argv[3], argl[3], &height) ) return TH_ERROR; |
| 1129 | Th_SplitList(interp, argv[2], TH1_LEN(argl[2]), &azElem, &aszElem, &nElem); |
| 1130 | blob_init(&name, (char*)argv[1], TH1_LEN(argl[1])); |
| 1131 | zValue = Th_Fetch(blob_str(&name), &nValue); |
| 1132 | nValue = TH1_LEN(nValue); |
| 1133 | zH = htmlize(blob_buffer(&name), blob_size(&name)); |
| 1134 | z = mprintf("<select id=\"%s\" name=\"%s\" size=\"%d\">", zH, zH, height); |
| @@ -1643,11 +1655,19 @@ | |
| 1643 | int *argl |
| 1644 | ){ |
| 1645 | if( argc!=2 ){ |
| 1646 | return Th_WrongNumArgs(interp, "builtin_request_js NAME"); |
| 1647 | } |
| 1648 | builtin_request_js(argv[1]); |
| 1649 | return TH_OK; |
| 1650 | } |
| 1651 | |
| 1652 | /* |
| 1653 | ** TH1 command: artifact ID ?FILENAME? |
| @@ -1672,11 +1692,11 @@ | |
| 1672 | if( argc==3 ){ |
| 1673 | rid = th1_artifact_from_ci_and_filename(interp, argv[1], argv[2]); |
| 1674 | }else{ |
| 1675 | rid = th1_name_to_typed_rid(interp, argv[1], "*"); |
| 1676 | } |
| 1677 | if( rid!=0 && content_get(rid, &content) ){ |
| 1678 | Th_SetResult(interp, blob_str(&content), blob_size(&content)); |
| 1679 | blob_reset(&content); |
| 1680 | return TH_OK; |
| 1681 | }else{ |
| 1682 | return TH_ERROR; |
| @@ -1723,11 +1743,13 @@ | |
| 1723 | if( argc!=3 ){ |
| 1724 | return Th_WrongNumArgs(interp, "unversioned content FILENAME"); |
| 1725 | } |
| 1726 | if( Th_IsRepositoryOpen() ){ |
| 1727 | Blob content; |
| 1728 | if( unversioned_content(argv[2], &content)!=0 ){ |
| 1729 | Th_SetResult(interp, blob_str(&content), blob_size(&content)); |
| 1730 | blob_reset(&content); |
| 1731 | return TH_OK; |
| 1732 | }else{ |
| 1733 | return TH_ERROR; |
| @@ -1756,16 +1778,18 @@ | |
| 1756 | } |
| 1757 | if( Th_IsRepositoryOpen() ){ |
| 1758 | Stmt q; |
| 1759 | char *zList = 0; |
| 1760 | int nList = 0; |
| 1761 | db_prepare(&q, "SELECT name FROM unversioned WHERE hash IS NOT NULL" |
| 1762 | " ORDER BY name"); |
| 1763 | while( db_step(&q)==SQLITE_ROW ){ |
| 1764 | Th_ListAppend(interp, &zList, &nList, db_column_text(&q,0), -1); |
| 1765 | } |
| 1766 | db_finalize(&q); |
| 1767 | Th_SetResult(interp, zList, nList); |
| 1768 | Th_Free(interp, zList); |
| 1769 | return TH_OK; |
| 1770 | }else{ |
| 1771 | Th_SetResult(interp, "repository unavailable", -1); |
| @@ -1882,13 +1906,13 @@ | |
| 1882 | const char **argv, |
| 1883 | int *argl |
| 1884 | ){ |
| 1885 | int n; |
| 1886 | unsigned char aRand[50]; |
| 1887 | unsigned char zOut[100]; |
| 1888 | if( argc!=1 && argc!=2 ){ |
| 1889 | return Th_WrongNumArgs(interp, "repository ?BOOLEAN?"); |
| 1890 | } |
| 1891 | if( argc==2 ){ |
| 1892 | if( Th_ToInt(interp, argv[1], argl[1], &n) ){ |
| 1893 | return TH_ERROR; |
| 1894 | } |
| @@ -1970,11 +1994,11 @@ | |
| 1970 | |
| 1971 | while( res==TH_OK && nSql>0 ){ |
| 1972 | zErr = 0; |
| 1973 | report_restrict_sql(&zErr); |
| 1974 | g.dbIgnoreErrors++; |
| 1975 | rc = sqlite3_prepare_v2(g.db, argv[1], TH1_LEN(argl[1]), &pStmt, &zTail); |
| 1976 | g.dbIgnoreErrors--; |
| 1977 | report_unrestrict_sql(); |
| 1978 | if( rc!=0 || zErr!=0 ){ |
| 1979 | if( noComplain ) return TH_OK; |
| 1980 | Th_ErrorMessage(interp, "SQL error: ", |
| @@ -1982,11 +2006,14 @@ | |
| 1982 | return TH_ERROR; |
| 1983 | } |
| 1984 | n = (int)(zTail - zSql); |
| 1985 | zSql += n; |
| 1986 | nSql -= n; |
| 1987 | if( pStmt==0 ) continue; |
| 1988 | nVar = sqlite3_bind_parameter_count(pStmt); |
| 1989 | for(i=1; i<=nVar; i++){ |
| 1990 | const char *zVar = sqlite3_bind_parameter_name(pStmt, i); |
| 1991 | int szVar = zVar ? th_strlen(zVar) : 0; |
| 1992 | if( szVar>1 && zVar[0]=='$' |
| @@ -2048,11 +2075,11 @@ | |
| 2048 | return Th_WrongNumArgs(interp, SETTING_WRONGNUMARGS); |
| 2049 | } |
| 2050 | if( fossil_strcmp(argv[nArg], "-strict")==0 ){ |
| 2051 | strict = 1; nArg++; |
| 2052 | } |
| 2053 | if( fossil_strcmp(argv[nArg], "--")==0 ) nArg++; |
| 2054 | if( nArg+1!=argc ){ |
| 2055 | return Th_WrongNumArgs(interp, SETTING_WRONGNUMARGS); |
| 2056 | } |
| 2057 | zValue = db_get(argv[nArg], 0); |
| 2058 | if( zValue!=0 ){ |
| @@ -2187,23 +2214,27 @@ | |
| 2187 | UrlData urlData; |
| 2188 | |
| 2189 | if( argc<2 || argc>5 ){ |
| 2190 | return Th_WrongNumArgs(interp, HTTP_WRONGNUMARGS); |
| 2191 | } |
| 2192 | if( fossil_strnicmp(argv[nArg], "-asynchronous", TH1_LEN(argl[nArg]))==0 ){ |
| 2193 | fAsynchronous = 1; nArg++; |
| 2194 | } |
| 2195 | if( fossil_strcmp(argv[nArg], "--")==0 ) nArg++; |
| 2196 | if( nArg+1!=argc && nArg+2!=argc ){ |
| 2197 | return Th_WrongNumArgs(interp, REGEXP_WRONGNUMARGS); |
| 2198 | } |
| 2199 | memset(&urlData, '\0', sizeof(urlData)); |
| 2200 | url_parse_local(argv[nArg], 0, &urlData); |
| 2201 | if( urlData.isSsh || urlData.isFile ){ |
| 2202 | Th_ErrorMessage(interp, "url must be http:// or https://", 0, 0); |
| 2203 | return TH_ERROR; |
| 2204 | } |
| 2205 | zRegexp = db_get("th1-uri-regexp", 0); |
| 2206 | if( zRegexp && zRegexp[0] ){ |
| 2207 | const char *zErr = fossil_re_compile(&pRe, zRegexp, 0); |
| 2208 | if( zErr ){ |
| 2209 | Th_SetResult(interp, zErr, -1); |
| @@ -2971,11 +3002,11 @@ | |
| 2971 | } |
| 2972 | } |
| 2973 | if( rc==TH_ERROR ){ |
| 2974 | zResult = (char*)Th_GetResult(g.interp, &n); |
| 2975 | sendError(pOut,zResult, n, 1); |
| 2976 | }else{ |
| 2977 | sendText(pOut,z, i, 0); |
| 2978 | } |
| 2979 | Th_SetOutputBlob(origOut); |
| 2980 | return rc; |
| 2981 | } |
| 2982 |
| --- src/th_main.c | |
| +++ src/th_main.c | |
| @@ -427,10 +427,11 @@ | |
| 427 | if( zFilename==0 ){ |
| 428 | Th_SetResult(interp, "invalid file name", -1); |
| 429 | return 0; |
| 430 | } |
| 431 | cirid = th1_name_to_typed_rid(interp, zCI, "*"); |
| 432 | if( cirid<0 ) return 0; |
| 433 | blob_zero(&err); |
| 434 | pManifest = manifest_get(cirid, CFTYPE_MANIFEST, &err); |
| 435 | if( pManifest==0 ){ |
| 436 | if( blob_size(&err)>0 ){ |
| 437 | Th_SetResult(interp, blob_str(&err), blob_size(&err)); |
| @@ -520,10 +521,18 @@ | |
| 521 | ){ |
| 522 | int withMethod = 0; |
| 523 | if( argc!=2 && argc!=3 ){ |
| 524 | return Th_WrongNumArgs(interp, "redirect URL ?withMethod?"); |
| 525 | } |
| 526 | if( g.httpOut==0 |
| 527 | || (g.zBaseURL==0 && fossil_strncmp(argv[1],"http:",5)!=0 |
| 528 | && fossil_strncmp(argv[1],"https:",6)!=0) |
| 529 | ){ |
| 530 | Th_ErrorMessage(interp, "redirect is only allowed in a web request", |
| 531 | 0, 0); |
| 532 | return TH_ERROR; |
| 533 | } |
| 534 | if( argc==3 ){ |
| 535 | if( Th_ToInt(interp, argv[2], argl[2], &withMethod) ){ |
| 536 | return TH_ERROR; |
| 537 | } |
| 538 | } |
| @@ -1124,11 +1133,14 @@ | |
| 1133 | int *aszElem; |
| 1134 | char **azElem; |
| 1135 | int i; |
| 1136 | |
| 1137 | if( Th_ToInt(interp, argv[3], argl[3], &height) ) return TH_ERROR; |
| 1138 | if( Th_SplitList(interp, argv[2], TH1_LEN(argl[2]), |
| 1139 | &azElem, &aszElem, &nElem) ){ |
| 1140 | return TH_ERROR; |
| 1141 | } |
| 1142 | blob_init(&name, (char*)argv[1], TH1_LEN(argl[1])); |
| 1143 | zValue = Th_Fetch(blob_str(&name), &nValue); |
| 1144 | nValue = TH1_LEN(nValue); |
| 1145 | zH = htmlize(blob_buffer(&name), blob_size(&name)); |
| 1146 | z = mprintf("<select id=\"%s\" name=\"%s\" size=\"%d\">", zH, zH, height); |
| @@ -1643,11 +1655,19 @@ | |
| 1655 | int *argl |
| 1656 | ){ |
| 1657 | if( argc!=2 ){ |
| 1658 | return Th_WrongNumArgs(interp, "builtin_request_js NAME"); |
| 1659 | } |
| 1660 | switch( builtin_try_request_js(argv[1]) ){ |
| 1661 | case 1: |
| 1662 | Th_ErrorMessage(interp, "unknown javascript file:", |
| 1663 | argv[1], TH1_LEN(argl[1])); |
| 1664 | return TH_ERROR; |
| 1665 | case 2: |
| 1666 | Th_ErrorMessage(interp, "too many javascript files requested", 0, 0); |
| 1667 | return TH_ERROR; |
| 1668 | } |
| 1669 | return TH_OK; |
| 1670 | } |
| 1671 | |
| 1672 | /* |
| 1673 | ** TH1 command: artifact ID ?FILENAME? |
| @@ -1672,11 +1692,11 @@ | |
| 1692 | if( argc==3 ){ |
| 1693 | rid = th1_artifact_from_ci_and_filename(interp, argv[1], argv[2]); |
| 1694 | }else{ |
| 1695 | rid = th1_name_to_typed_rid(interp, argv[1], "*"); |
| 1696 | } |
| 1697 | if( rid>0 && content_get(rid, &content) ){ |
| 1698 | Th_SetResult(interp, blob_str(&content), blob_size(&content)); |
| 1699 | blob_reset(&content); |
| 1700 | return TH_OK; |
| 1701 | }else{ |
| 1702 | return TH_ERROR; |
| @@ -1723,11 +1743,13 @@ | |
| 1743 | if( argc!=3 ){ |
| 1744 | return Th_WrongNumArgs(interp, "unversioned content FILENAME"); |
| 1745 | } |
| 1746 | if( Th_IsRepositoryOpen() ){ |
| 1747 | Blob content; |
| 1748 | if( db_table_exists("repository", "unversioned") |
| 1749 | && unversioned_content(argv[2], &content)!=0 |
| 1750 | ){ |
| 1751 | Th_SetResult(interp, blob_str(&content), blob_size(&content)); |
| 1752 | blob_reset(&content); |
| 1753 | return TH_OK; |
| 1754 | }else{ |
| 1755 | return TH_ERROR; |
| @@ -1756,16 +1778,18 @@ | |
| 1778 | } |
| 1779 | if( Th_IsRepositoryOpen() ){ |
| 1780 | Stmt q; |
| 1781 | char *zList = 0; |
| 1782 | int nList = 0; |
| 1783 | if( db_table_exists("repository", "unversioned") ){ |
| 1784 | db_prepare(&q, "SELECT name FROM unversioned WHERE hash IS NOT NULL" |
| 1785 | " ORDER BY name"); |
| 1786 | while( db_step(&q)==SQLITE_ROW ){ |
| 1787 | Th_ListAppend(interp, &zList, &nList, db_column_text(&q,0), -1); |
| 1788 | } |
| 1789 | db_finalize(&q); |
| 1790 | } |
| 1791 | Th_SetResult(interp, zList, nList); |
| 1792 | Th_Free(interp, zList); |
| 1793 | return TH_OK; |
| 1794 | }else{ |
| 1795 | Th_SetResult(interp, "repository unavailable", -1); |
| @@ -1882,13 +1906,13 @@ | |
| 1906 | const char **argv, |
| 1907 | int *argl |
| 1908 | ){ |
| 1909 | int n; |
| 1910 | unsigned char aRand[50]; |
| 1911 | unsigned char zOut[sizeof(aRand)*2+1]; |
| 1912 | if( argc!=1 && argc!=2 ){ |
| 1913 | return Th_WrongNumArgs(interp, "randhex ?N?"); |
| 1914 | } |
| 1915 | if( argc==2 ){ |
| 1916 | if( Th_ToInt(interp, argv[1], argl[1], &n) ){ |
| 1917 | return TH_ERROR; |
| 1918 | } |
| @@ -1970,11 +1994,11 @@ | |
| 1994 | |
| 1995 | while( res==TH_OK && nSql>0 ){ |
| 1996 | zErr = 0; |
| 1997 | report_restrict_sql(&zErr); |
| 1998 | g.dbIgnoreErrors++; |
| 1999 | rc = sqlite3_prepare_v2(g.db, zSql, nSql, &pStmt, &zTail); |
| 2000 | g.dbIgnoreErrors--; |
| 2001 | report_unrestrict_sql(); |
| 2002 | if( rc!=0 || zErr!=0 ){ |
| 2003 | if( noComplain ) return TH_OK; |
| 2004 | Th_ErrorMessage(interp, "SQL error: ", |
| @@ -1982,11 +2006,14 @@ | |
| 2006 | return TH_ERROR; |
| 2007 | } |
| 2008 | n = (int)(zTail - zSql); |
| 2009 | zSql += n; |
| 2010 | nSql -= n; |
| 2011 | if( pStmt==0 ){ |
| 2012 | if( n==0 ) break; |
| 2013 | continue; |
| 2014 | } |
| 2015 | nVar = sqlite3_bind_parameter_count(pStmt); |
| 2016 | for(i=1; i<=nVar; i++){ |
| 2017 | const char *zVar = sqlite3_bind_parameter_name(pStmt, i); |
| 2018 | int szVar = zVar ? th_strlen(zVar) : 0; |
| 2019 | if( szVar>1 && zVar[0]=='$' |
| @@ -2048,11 +2075,11 @@ | |
| 2075 | return Th_WrongNumArgs(interp, SETTING_WRONGNUMARGS); |
| 2076 | } |
| 2077 | if( fossil_strcmp(argv[nArg], "-strict")==0 ){ |
| 2078 | strict = 1; nArg++; |
| 2079 | } |
| 2080 | if( nArg<argc && fossil_strcmp(argv[nArg], "--")==0 ) nArg++; |
| 2081 | if( nArg+1!=argc ){ |
| 2082 | return Th_WrongNumArgs(interp, SETTING_WRONGNUMARGS); |
| 2083 | } |
| 2084 | zValue = db_get(argv[nArg], 0); |
| 2085 | if( zValue!=0 ){ |
| @@ -2187,23 +2214,27 @@ | |
| 2214 | UrlData urlData; |
| 2215 | |
| 2216 | if( argc<2 || argc>5 ){ |
| 2217 | return Th_WrongNumArgs(interp, HTTP_WRONGNUMARGS); |
| 2218 | } |
| 2219 | if( TH1_LEN(argl[nArg])>0 |
| 2220 | && fossil_strnicmp(argv[nArg], "-asynchronous", TH1_LEN(argl[nArg]))==0 |
| 2221 | ){ |
| 2222 | fAsynchronous = 1; nArg++; |
| 2223 | } |
| 2224 | if( nArg<argc && fossil_strcmp(argv[nArg], "--")==0 ) nArg++; |
| 2225 | if( nArg+1!=argc && nArg+2!=argc ){ |
| 2226 | return Th_WrongNumArgs(interp, HTTP_WRONGNUMARGS); |
| 2227 | } |
| 2228 | if( fossil_strnicmp(argv[nArg], "http://", 7)!=0 |
| 2229 | && fossil_strnicmp(argv[nArg], "https://", 8)!=0 |
| 2230 | ){ |
| 2231 | Th_ErrorMessage(interp, "url must be http:// or https://", 0, 0); |
| 2232 | return TH_ERROR; |
| 2233 | } |
| 2234 | memset(&urlData, '\0', sizeof(urlData)); |
| 2235 | url_parse_local(argv[nArg], 0, &urlData); |
| 2236 | zRegexp = db_get("th1-uri-regexp", 0); |
| 2237 | if( zRegexp && zRegexp[0] ){ |
| 2238 | const char *zErr = fossil_re_compile(&pRe, zRegexp, 0); |
| 2239 | if( zErr ){ |
| 2240 | Th_SetResult(interp, zErr, -1); |
| @@ -2971,11 +3002,11 @@ | |
| 3002 | } |
| 3003 | } |
| 3004 | if( rc==TH_ERROR ){ |
| 3005 | zResult = (char*)Th_GetResult(g.interp, &n); |
| 3006 | sendError(pOut,zResult, n, 1); |
| 3007 | }else if( rc==TH_OK ){ |
| 3008 | sendText(pOut,z, i, 0); |
| 3009 | } |
| 3010 | Th_SetOutputBlob(origOut); |
| 3011 | return rc; |
| 3012 | } |
| 3013 |
+2
-1
| --- src/timeline.c | ||
| +++ src/timeline.c | ||
| @@ -2558,11 +2558,12 @@ | ||
| 2558 | 2558 | } |
| 2559 | 2559 | if( zFwdTo ){ |
| 2560 | 2560 | double rStartDate = mtime_of_rid(d_rid, 0.0); |
| 2561 | 2561 | ridFwdTo = first_checkin_with_tag_after_date(zFwdTo, rStartDate); |
| 2562 | 2562 | if( ridFwdTo==0 ){ |
| 2563 | - ridFwdTo = name_to_typed_rid(zBackTo,"ci"); | |
| 2563 | + int rid = symbolic_name_to_rid(zFwdTo,"ci"); | |
| 2564 | + if( rid>0 && mtime_of_rid(rid, 0.0)>rStartDate ) ridFwdTo = rid; | |
| 2564 | 2565 | } |
| 2565 | 2566 | if( ridFwdTo ){ |
| 2566 | 2567 | if( !haveParameterN ) nEntry = 0; |
| 2567 | 2568 | rStopTime = mtime_of_rid(ridFwdTo, 9e99); |
| 2568 | 2569 | } |
| 2569 | 2570 |
| --- src/timeline.c | |
| +++ src/timeline.c | |
| @@ -2558,11 +2558,12 @@ | |
| 2558 | } |
| 2559 | if( zFwdTo ){ |
| 2560 | double rStartDate = mtime_of_rid(d_rid, 0.0); |
| 2561 | ridFwdTo = first_checkin_with_tag_after_date(zFwdTo, rStartDate); |
| 2562 | if( ridFwdTo==0 ){ |
| 2563 | ridFwdTo = name_to_typed_rid(zBackTo,"ci"); |
| 2564 | } |
| 2565 | if( ridFwdTo ){ |
| 2566 | if( !haveParameterN ) nEntry = 0; |
| 2567 | rStopTime = mtime_of_rid(ridFwdTo, 9e99); |
| 2568 | } |
| 2569 |
| --- src/timeline.c | |
| +++ src/timeline.c | |
| @@ -2558,11 +2558,12 @@ | |
| 2558 | } |
| 2559 | if( zFwdTo ){ |
| 2560 | double rStartDate = mtime_of_rid(d_rid, 0.0); |
| 2561 | ridFwdTo = first_checkin_with_tag_after_date(zFwdTo, rStartDate); |
| 2562 | if( ridFwdTo==0 ){ |
| 2563 | int rid = symbolic_name_to_rid(zFwdTo,"ci"); |
| 2564 | if( rid>0 && mtime_of_rid(rid, 0.0)>rStartDate ) ridFwdTo = rid; |
| 2565 | } |
| 2566 | if( ridFwdTo ){ |
| 2567 | if( !haveParameterN ) nEntry = 0; |
| 2568 | rStopTime = mtime_of_rid(ridFwdTo, 9e99); |
| 2569 | } |
| 2570 |
+16
-4
| --- src/url.c | ||
| +++ src/url.c | ||
| @@ -157,11 +157,10 @@ | ||
| 157 | 157 | || fossil_strnicmp(zUrl, "ssh://", 6)==0 |
| 158 | 158 | ){ |
| 159 | 159 | int iStart; |
| 160 | 160 | char *zLogin; |
| 161 | 161 | char *zExe; |
| 162 | - char cQuerySep = '?'; | |
| 163 | 162 | const char *zLb; /* "[" before an IPv6 address in a URL, else "" */ |
| 164 | 163 | const char *zRb; /* "]" after an IPv6 address in a URL, else "" */ |
| 165 | 164 | |
| 166 | 165 | if( zUrl[4]=='s' || zUrl[4]=='S' ){ |
| 167 | 166 | pUrlData->isHttps = 1; |
| @@ -285,16 +284,17 @@ | ||
| 285 | 284 | if( pUrlData->path[i] ){ |
| 286 | 285 | pUrlData->path[i] = 0; |
| 287 | 286 | i++; |
| 288 | 287 | } |
| 289 | 288 | if( fossil_strcmp(zName,"fossil")==0 ){ |
| 289 | + if( zExe && zExe[0] ) | |
| 290 | + fossil_fatal("more than one fossil= query parameter"); | |
| 290 | 291 | fossil_free(pUrlData->fossil); |
| 291 | 292 | pUrlData->fossil = fossil_strdup(zValue); |
| 292 | 293 | dehttpize(pUrlData->fossil); |
| 293 | 294 | fossil_free(zExe); |
| 294 | - zExe = mprintf("%cfossil=%T", cQuerySep, pUrlData->fossil); | |
| 295 | - cQuerySep = '&'; | |
| 295 | + zExe = mprintf("?fossil=%T", pUrlData->fossil); | |
| 296 | 296 | urlFlags |= URL_SSH_EXE; |
| 297 | 297 | } |
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | dehttpize(pUrlData->path); |
| @@ -309,11 +309,11 @@ | ||
| 309 | 309 | "%s://%s%s%T%s:%d%T%z", |
| 310 | 310 | pUrlData->protocol, zLogin, zLb, pUrlData->name, zRb, |
| 311 | 311 | pUrlData->port, pUrlData->path, zExe |
| 312 | 312 | ); |
| 313 | 313 | } |
| 314 | - if( pUrlData->isSsh && pUrlData->path[1] ){ | |
| 314 | + if( pUrlData->isSsh && pUrlData->path[0] && pUrlData->path[1] ){ | |
| 315 | 315 | char *zOld = pUrlData->path; |
| 316 | 316 | pUrlData->path = fossil_strdup(zOld+1); |
| 317 | 317 | fossil_free(zOld); |
| 318 | 318 | } |
| 319 | 319 | free(zLogin); |
| @@ -398,10 +398,14 @@ | ||
| 398 | 398 | blob_appendf(&x, "@"); |
| 399 | 399 | } |
| 400 | 400 | url_append_host(&x, p->name); |
| 401 | 401 | if( p->dfltPort!=p->port ){ |
| 402 | 402 | blob_appendf(&x, ":%d", p->port); |
| 403 | + } | |
| 404 | + if( p->isSsh && p->path[0] && fossil_strcmp(p->path, "/")!=0 ){ | |
| 405 | + /* The path of an ssh: URL is held without its first "/". */ | |
| 406 | + blob_append_char(&x, '/'); | |
| 403 | 407 | } |
| 404 | 408 | blob_appendf(&x, "%T", p->path); |
| 405 | 409 | (void)blob_str(&x); |
| 406 | 410 | return x.aData; |
| 407 | 411 | } |
| @@ -418,10 +422,14 @@ | ||
| 418 | 422 | } |
| 419 | 423 | blob_appendf(&x, "%s://", p->protocol); |
| 420 | 424 | url_append_host(&x, p->name); |
| 421 | 425 | if( p->dfltPort!=p->port ){ |
| 422 | 426 | blob_appendf(&x, ":%d", p->port); |
| 427 | + } | |
| 428 | + if( p->isSsh && p->path[0] && fossil_strcmp(p->path, "/")!=0 ){ | |
| 429 | + /* The path of an ssh: URL is held without its first "/". */ | |
| 430 | + blob_append_char(&x, '/'); | |
| 423 | 431 | } |
| 424 | 432 | blob_appendf(&x, "%T", p->path); |
| 425 | 433 | (void)blob_str(&x); |
| 426 | 434 | return x.aData; |
| 427 | 435 | } |
| @@ -646,10 +654,14 @@ | ||
| 646 | 654 | int iOriginalPort = g.url.port; |
| 647 | 655 | unsigned uOriginalFlags = g.url.flags; |
| 648 | 656 | g.url.user = 0; |
| 649 | 657 | g.url.passwd = ""; |
| 650 | 658 | url_parse(zProxy, 0); |
| 659 | + if( g.url.isFile || g.url.isSsh ){ | |
| 660 | + fossil_fatal("the proxy must be an http: or https: URL: %s", | |
| 661 | + g.url.canonical); | |
| 662 | + } | |
| 651 | 663 | if( zMsg ) fossil_print("%s%s\n", zMsg, g.url.canonical); |
| 652 | 664 | g.url.path = zOriginalUrl; |
| 653 | 665 | g.url.hostname = zOriginalHost; |
| 654 | 666 | if( g.url.user ){ |
| 655 | 667 | char *zCredentials1 = mprintf("%s:%s", g.url.user, g.url.passwd); |
| 656 | 668 |
| --- src/url.c | |
| +++ src/url.c | |
| @@ -157,11 +157,10 @@ | |
| 157 | || fossil_strnicmp(zUrl, "ssh://", 6)==0 |
| 158 | ){ |
| 159 | int iStart; |
| 160 | char *zLogin; |
| 161 | char *zExe; |
| 162 | char cQuerySep = '?'; |
| 163 | const char *zLb; /* "[" before an IPv6 address in a URL, else "" */ |
| 164 | const char *zRb; /* "]" after an IPv6 address in a URL, else "" */ |
| 165 | |
| 166 | if( zUrl[4]=='s' || zUrl[4]=='S' ){ |
| 167 | pUrlData->isHttps = 1; |
| @@ -285,16 +284,17 @@ | |
| 285 | if( pUrlData->path[i] ){ |
| 286 | pUrlData->path[i] = 0; |
| 287 | i++; |
| 288 | } |
| 289 | if( fossil_strcmp(zName,"fossil")==0 ){ |
| 290 | fossil_free(pUrlData->fossil); |
| 291 | pUrlData->fossil = fossil_strdup(zValue); |
| 292 | dehttpize(pUrlData->fossil); |
| 293 | fossil_free(zExe); |
| 294 | zExe = mprintf("%cfossil=%T", cQuerySep, pUrlData->fossil); |
| 295 | cQuerySep = '&'; |
| 296 | urlFlags |= URL_SSH_EXE; |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | dehttpize(pUrlData->path); |
| @@ -309,11 +309,11 @@ | |
| 309 | "%s://%s%s%T%s:%d%T%z", |
| 310 | pUrlData->protocol, zLogin, zLb, pUrlData->name, zRb, |
| 311 | pUrlData->port, pUrlData->path, zExe |
| 312 | ); |
| 313 | } |
| 314 | if( pUrlData->isSsh && pUrlData->path[1] ){ |
| 315 | char *zOld = pUrlData->path; |
| 316 | pUrlData->path = fossil_strdup(zOld+1); |
| 317 | fossil_free(zOld); |
| 318 | } |
| 319 | free(zLogin); |
| @@ -398,10 +398,14 @@ | |
| 398 | blob_appendf(&x, "@"); |
| 399 | } |
| 400 | url_append_host(&x, p->name); |
| 401 | if( p->dfltPort!=p->port ){ |
| 402 | blob_appendf(&x, ":%d", p->port); |
| 403 | } |
| 404 | blob_appendf(&x, "%T", p->path); |
| 405 | (void)blob_str(&x); |
| 406 | return x.aData; |
| 407 | } |
| @@ -418,10 +422,14 @@ | |
| 418 | } |
| 419 | blob_appendf(&x, "%s://", p->protocol); |
| 420 | url_append_host(&x, p->name); |
| 421 | if( p->dfltPort!=p->port ){ |
| 422 | blob_appendf(&x, ":%d", p->port); |
| 423 | } |
| 424 | blob_appendf(&x, "%T", p->path); |
| 425 | (void)blob_str(&x); |
| 426 | return x.aData; |
| 427 | } |
| @@ -646,10 +654,14 @@ | |
| 646 | int iOriginalPort = g.url.port; |
| 647 | unsigned uOriginalFlags = g.url.flags; |
| 648 | g.url.user = 0; |
| 649 | g.url.passwd = ""; |
| 650 | url_parse(zProxy, 0); |
| 651 | if( zMsg ) fossil_print("%s%s\n", zMsg, g.url.canonical); |
| 652 | g.url.path = zOriginalUrl; |
| 653 | g.url.hostname = zOriginalHost; |
| 654 | if( g.url.user ){ |
| 655 | char *zCredentials1 = mprintf("%s:%s", g.url.user, g.url.passwd); |
| 656 |
| --- src/url.c | |
| +++ src/url.c | |
| @@ -157,11 +157,10 @@ | |
| 157 | || fossil_strnicmp(zUrl, "ssh://", 6)==0 |
| 158 | ){ |
| 159 | int iStart; |
| 160 | char *zLogin; |
| 161 | char *zExe; |
| 162 | const char *zLb; /* "[" before an IPv6 address in a URL, else "" */ |
| 163 | const char *zRb; /* "]" after an IPv6 address in a URL, else "" */ |
| 164 | |
| 165 | if( zUrl[4]=='s' || zUrl[4]=='S' ){ |
| 166 | pUrlData->isHttps = 1; |
| @@ -285,16 +284,17 @@ | |
| 284 | if( pUrlData->path[i] ){ |
| 285 | pUrlData->path[i] = 0; |
| 286 | i++; |
| 287 | } |
| 288 | if( fossil_strcmp(zName,"fossil")==0 ){ |
| 289 | if( zExe && zExe[0] ) |
| 290 | fossil_fatal("more than one fossil= query parameter"); |
| 291 | fossil_free(pUrlData->fossil); |
| 292 | pUrlData->fossil = fossil_strdup(zValue); |
| 293 | dehttpize(pUrlData->fossil); |
| 294 | fossil_free(zExe); |
| 295 | zExe = mprintf("?fossil=%T", pUrlData->fossil); |
| 296 | urlFlags |= URL_SSH_EXE; |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | dehttpize(pUrlData->path); |
| @@ -309,11 +309,11 @@ | |
| 309 | "%s://%s%s%T%s:%d%T%z", |
| 310 | pUrlData->protocol, zLogin, zLb, pUrlData->name, zRb, |
| 311 | pUrlData->port, pUrlData->path, zExe |
| 312 | ); |
| 313 | } |
| 314 | if( pUrlData->isSsh && pUrlData->path[0] && pUrlData->path[1] ){ |
| 315 | char *zOld = pUrlData->path; |
| 316 | pUrlData->path = fossil_strdup(zOld+1); |
| 317 | fossil_free(zOld); |
| 318 | } |
| 319 | free(zLogin); |
| @@ -398,10 +398,14 @@ | |
| 398 | blob_appendf(&x, "@"); |
| 399 | } |
| 400 | url_append_host(&x, p->name); |
| 401 | if( p->dfltPort!=p->port ){ |
| 402 | blob_appendf(&x, ":%d", p->port); |
| 403 | } |
| 404 | if( p->isSsh && p->path[0] && fossil_strcmp(p->path, "/")!=0 ){ |
| 405 | /* The path of an ssh: URL is held without its first "/". */ |
| 406 | blob_append_char(&x, '/'); |
| 407 | } |
| 408 | blob_appendf(&x, "%T", p->path); |
| 409 | (void)blob_str(&x); |
| 410 | return x.aData; |
| 411 | } |
| @@ -418,10 +422,14 @@ | |
| 422 | } |
| 423 | blob_appendf(&x, "%s://", p->protocol); |
| 424 | url_append_host(&x, p->name); |
| 425 | if( p->dfltPort!=p->port ){ |
| 426 | blob_appendf(&x, ":%d", p->port); |
| 427 | } |
| 428 | if( p->isSsh && p->path[0] && fossil_strcmp(p->path, "/")!=0 ){ |
| 429 | /* The path of an ssh: URL is held without its first "/". */ |
| 430 | blob_append_char(&x, '/'); |
| 431 | } |
| 432 | blob_appendf(&x, "%T", p->path); |
| 433 | (void)blob_str(&x); |
| 434 | return x.aData; |
| 435 | } |
| @@ -646,10 +654,14 @@ | |
| 654 | int iOriginalPort = g.url.port; |
| 655 | unsigned uOriginalFlags = g.url.flags; |
| 656 | g.url.user = 0; |
| 657 | g.url.passwd = ""; |
| 658 | url_parse(zProxy, 0); |
| 659 | if( g.url.isFile || g.url.isSsh ){ |
| 660 | fossil_fatal("the proxy must be an http: or https: URL: %s", |
| 661 | g.url.canonical); |
| 662 | } |
| 663 | if( zMsg ) fossil_print("%s%s\n", zMsg, g.url.canonical); |
| 664 | g.url.path = zOriginalUrl; |
| 665 | g.url.hostname = zOriginalHost; |
| 666 | if( g.url.user ){ |
| 667 | char *zCredentials1 = mprintf("%s:%s", g.url.user, g.url.passwd); |
| 668 |