Bladeren bron

Send error message if seek in file fails (instead of sending the wrong part of the file)

See also #158
bel 10 jaren geleden
bovenliggende
commit
96b2a275e2
1 gewijzigde bestanden met toevoegingen van 4 en 1 verwijderingen
  1. 4 1
      src/civetweb.c

+ 4 - 1
src/civetweb.c

@@ -5276,10 +5276,13 @@ static void send_file_data(struct mg_connection *conn,
 			       "%s: sendfile() failed: %s (now trying read+write)",
 			       __func__,
 			       strerror(ERRNO));
+            offset = (int64_t)sf_offs;
 		}
 #endif
-		if (offset > 0 && fseeko(filep->fp, offset, SEEK_SET) != 0) {
+		if ((offset > 0) && (fseeko(filep->fp, offset, SEEK_SET) != 0)) {
 			mg_cry(conn, "%s: fseeko() failed: %s", __func__, strerror(ERRNO));
+            send_http_error(
+				    conn, 500, "%s", "Error: Unable to access file at requested position.");
 		} else {
 			while (len > 0) {
 				/* Calculate how much to read from the file in the buffer */