Fossil SCM

Fixed a string index -1 segfault when simplifying a path ends up at the root. Repro with `./fossil test-relative-name 'a/..'`

wyoung 2026-11-20 12:55 UTC trunk
Commit 57dbf286df4e7213fbe67406218220dd80cef913084bd417c4917ef1585da1d3
1 file changed +8 -1
+8 -1
--- src/file.c
+++ src/file.c
@@ -1252,11 +1252,18 @@
12521252
}
12531253
}
12541254
if( j>=0 ) z[j] = z[i];
12551255
j++;
12561256
}
1257
- if( j==0 ) z[j++] = '/';
1257
+ if( j<0 ){
1258
+ /* backup_dir() removed everything including the first component.
1259
+ ** Absolute "/.." still has z[0]=='/'; relative "a/.." is cwd. */
1260
+ if( z[0]=='/' ){ j = 0; z[j++] = '/'; }
1261
+ else { z[0] = '.'; j = 1; }
1262
+ }else if( j==0 ){
1263
+ z[j++] = '/';
1264
+ }
12581265
z[j] = 0;
12591266
return j;
12601267
}
12611268
12621269
/*
12631270
--- src/file.c
+++ src/file.c
@@ -1252,11 +1252,18 @@
1252 }
1253 }
1254 if( j>=0 ) z[j] = z[i];
1255 j++;
1256 }
1257 if( j==0 ) z[j++] = '/';
 
 
 
 
 
 
 
1258 z[j] = 0;
1259 return j;
1260 }
1261
1262 /*
1263
--- src/file.c
+++ src/file.c
@@ -1252,11 +1252,18 @@
1252 }
1253 }
1254 if( j>=0 ) z[j] = z[i];
1255 j++;
1256 }
1257 if( j<0 ){
1258 /* backup_dir() removed everything including the first component.
1259 ** Absolute "/.." still has z[0]=='/'; relative "a/.." is cwd. */
1260 if( z[0]=='/' ){ j = 0; z[j++] = '/'; }
1261 else { z[0] = '.'; j = 1; }
1262 }else if( j==0 ){
1263 z[j++] = '/';
1264 }
1265 z[j] = 0;
1266 return j;
1267 }
1268
1269 /*
1270

Keyboard Shortcuts

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