Skip to contentSkip to conversation

erofs-utils: tar: guard slash-only header names

PATCH In review Vansh Choudhary 3 participants 3 messages Mar 30 – Mar 31 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 erofs-utils: tar: guard slash-only header names

Check that the assembled header path is non-empty before trimming trailing slashes from it.

A malformed tar header name made up only of '/' characters could otherwise drive the trim loop to read before the start of the buffer.

---
 lib/tar.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/tar.c +1 -1
index 4e97522..39e2321 100644
@@ -866,7 +866,7 @@ out_eot:
 			path[1] = '\0';
 		} else {
 			*_path = '\0';
-			while (path[j - 1] == '/')
+			while (j && path[j - 1] == '/')
 				path[--j] = '\0';
 		}
 	}
Signature · 1 line
2.43.0
#1 lore raw
Quoted 7 lines · Vansh Choudhary

Check that the assembled header path is non-empty before trimming trailing slashes from it.

A malformed tar header name made up only of '/' characters could otherwise drive the trim loop to read before the start of the buffer.

I don't think it's a valid one.

Quoted 17 lines
---
  lib/tar.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
lib/tar.c +1 -1
index 4e97522..39e2321 100644
@@ -866,7 +866,7 @@ out_eot:
  			path[1] = '\0';
  		} else {
  			*_path = '\0';
-			while (path[j - 1] == '/')
+			while (j && path[j - 1] == '/')
  				path[--j] = '\0';
  		}
  	}
#2 lore raw
In reply to Vansh Choudhary
Quoted 16 lines · Vansh Choudhary

Check that the assembled header path is non-empty before trimming trailing slashes from it.

A malformed tar header name made up only of '/' characters could otherwise drive the trim loop to read before the start of the buffer.

---
  lib/tar.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
lib/tar.c +0 -0
index 4e97522..39e2321 100644

lib/tar.c out_eot: · line 867

Quoted 2 lines
lib/tar.c +0 -0
@@ -866,7 +866,7 @@ out_eot:
  			path[1] = '\0';
  		} else {

I think this else branch has ensured j != 0.

Quoted 6 lines
lib/tar.c +1 -1
  			*_path = '\0';
-			while (path[j - 1] == '/')
+			while (j && path[j - 1] == '/')
  				path[--j] = '\0';
  		}
  	}