Fossil SCM

Fix for problem reported at [https://fossil-scm.org/forum/forumpost/e4953666d6] which triggered a JSON-mode assertion when trying to access a /json path via a server running in directory-serving mode (which prefixes such paths with the repo name). Such paths are now recognized as routes into the JSON API.

stephan 2020-07-08 20:26 trunk
Commit dd490d17bec777c4cc26aecfa672d8c29a69292e7c867558023549c11322c553
1 file changed +20 -4
+20 -4
--- src/main.c
+++ src/main.c
@@ -1579,14 +1579,30 @@
15791579
** process JSON-mode POST data if we're actually in a /json
15801580
** page). This is normally set up before this routine is called, but
15811581
** it looks like the ssh_request_loop() approach to dispatching
15821582
** might bypass that.
15831583
*/
1584
- if( g.json.isJsonMode==0 && zPathInfo!=0
1585
- && 0==strncmp("/json",zPathInfo,5)
1586
- && (zPathInfo[5]==0 || zPathInfo[5]=='/')){
1587
- g.json.isJsonMode = 1;
1584
+ if( g.json.isJsonMode==0 && zPathInfo!=0 ){
1585
+ if(0==strncmp("/json",zPathInfo,5)
1586
+ && (zPathInfo[5]==0 || zPathInfo[5]=='/')){
1587
+ g.json.isJsonMode = 1;
1588
+ }else if(g.zCmdName!=0 && 0==strcmp("server",g.zCmdName)){
1589
+ /* When running in server "directory" mode, zPathInfo is
1590
+ ** prefixed with the repository's name, so in order to determine
1591
+ ** whether or not we're really running in json mode we have to
1592
+ ** try a bit harder. Problem reported here:
1593
+ ** https://fossil-scm.org/forum/forumpost/e4953666d6
1594
+ */
1595
+ ReCompiled * pReg = 0;
1596
+ const char * zErr = re_compile(&pReg, "^/[^/]+/json(/.*)?", 0);
1597
+ assert(zErr==0 && "Regex compilation failed?");
1598
+ if(zErr==0 &&
1599
+ re_match(pReg, (const unsigned char *)zPathInfo, -1)){
1600
+ g.json.isJsonMode = 1;
1601
+ }
1602
+ re_free(pReg);
1603
+ }
15881604
}
15891605
#endif
15901606
/* If the repository has not been opened already, then find the
15911607
** repository based on the first element of PATH_INFO and open it.
15921608
*/
15931609
--- src/main.c
+++ src/main.c
@@ -1579,14 +1579,30 @@
1579 ** process JSON-mode POST data if we're actually in a /json
1580 ** page). This is normally set up before this routine is called, but
1581 ** it looks like the ssh_request_loop() approach to dispatching
1582 ** might bypass that.
1583 */
1584 if( g.json.isJsonMode==0 && zPathInfo!=0
1585 && 0==strncmp("/json",zPathInfo,5)
1586 && (zPathInfo[5]==0 || zPathInfo[5]=='/')){
1587 g.json.isJsonMode = 1;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1588 }
1589 #endif
1590 /* If the repository has not been opened already, then find the
1591 ** repository based on the first element of PATH_INFO and open it.
1592 */
1593
--- src/main.c
+++ src/main.c
@@ -1579,14 +1579,30 @@
1579 ** process JSON-mode POST data if we're actually in a /json
1580 ** page). This is normally set up before this routine is called, but
1581 ** it looks like the ssh_request_loop() approach to dispatching
1582 ** might bypass that.
1583 */
1584 if( g.json.isJsonMode==0 && zPathInfo!=0 ){
1585 if(0==strncmp("/json",zPathInfo,5)
1586 && (zPathInfo[5]==0 || zPathInfo[5]=='/')){
1587 g.json.isJsonMode = 1;
1588 }else if(g.zCmdName!=0 && 0==strcmp("server",g.zCmdName)){
1589 /* When running in server "directory" mode, zPathInfo is
1590 ** prefixed with the repository's name, so in order to determine
1591 ** whether or not we're really running in json mode we have to
1592 ** try a bit harder. Problem reported here:
1593 ** https://fossil-scm.org/forum/forumpost/e4953666d6
1594 */
1595 ReCompiled * pReg = 0;
1596 const char * zErr = re_compile(&pReg, "^/[^/]+/json(/.*)?", 0);
1597 assert(zErr==0 && "Regex compilation failed?");
1598 if(zErr==0 &&
1599 re_match(pReg, (const unsigned char *)zPathInfo, -1)){
1600 g.json.isJsonMode = 1;
1601 }
1602 re_free(pReg);
1603 }
1604 }
1605 #endif
1606 /* If the repository has not been opened already, then find the
1607 ** repository based on the first element of PATH_INFO and open it.
1608 */
1609

Keyboard Shortcuts

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