shithub: qk2

Download patch

ref: 4c66d61f63d2ca97101d7aad96c6fb412fbc6c4b
parent: e5661fc7dc225f89da46454f2545dd8574fa3073
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Fri Aug 19 14:07:55 EDT 2022

sys: use fstat and avoid unaligned data access on stack

--- a/sys.c
+++ b/sys.c
@@ -332,13 +332,14 @@
 vlong
 flen(int fd)
 {
-	uchar bs[1024];
+	Dir *d;
+	vlong sz;
 
-	if(fstat(fd, bs, sizeof bs) < 0){
-		fprint(2, "flen:fstat: %r\n");
-		return -1;
-	}
-	return *((vlong *)(bs+2+2+4+1+4+8+4+4+4));	/* length[8] */
+	sz = -1;
+	if((d = dirfstat(fd)) != nil)
+		sz = d->length;
+	free(d);
+	return sz;
 }
 
 void