This is the mail archive of the
cygwin-patches
mailing list for the Cygwin project.
[Patch] Segfault on unaligned lseek() on /dev/sdX (was: [ITP] ddrescue 1.3)
- From: Christian Franke <Christian dot Franke at t-online dot de>
- To: cygwin-patches at cygwin dot com
- Date: Fri, 18 May 2007 21:02:15 +0200
- Subject: [Patch] Segfault on unaligned lseek() on /dev/sdX (was: [ITP] ddrescue 1.3)
Hi,
Cygwin 1.5.24-2 segfaults on unaligned lseek() on raw block devices with
sector size >512 bytes.
Testcases:
$ dd skip=1000 bs=2047 if=/dev/scd0 of=/dev/null
$ ddrescue -c 1 /dev/scd0 file.iso
This is due to a fixed 512 byte buffer in fhandler_dev_floppy::lseek().
It is still present in HEAD revision.
The attached patch should fix. It should work for any sector size.
(Smoke-)tested with 1.5.24-2 (too busy to test with current CVS, sorry).
2007-05-18 Christian Franke <franke@computer.org>
* fhandler_floppy.cc (fhandler_dev_floppy::lseek): Fixed segfault on
unaligned seek due to fixed size buffer.
Christian
--- cygwin-1.5.24-2.orig/winsup/cygwin/fhandler_floppy.cc 2006-07-18 14:56:37.001000000 +0200
+++ cygwin-1.5.24-2/winsup/cygwin/fhandler_floppy.cc 2007-05-18 19:53:07.468750000 +0200
@@ -12,6 +12,7 @@ details. */
#include "winsup.h"
#include <sys/termios.h>
#include <unistd.h>
+#include <stdlib.h>
#include <winioctl.h>
#include <asm/socket.h>
#include <cygwin/rdevio.h>
@@ -408,7 +409,6 @@ fhandler_dev_floppy::raw_write (const vo
_off64_t
fhandler_dev_floppy::lseek (_off64_t offset, int whence)
{
- char buf[512];
_off64_t lloffset = offset;
LARGE_INTEGER sector_aligned_offset;
_off64_t bytes_left;
@@ -454,7 +454,14 @@ fhandler_dev_floppy::lseek (_off64_t off
if (bytes_left)
{
size_t len = bytes_left;
+ char *buf = (char *) malloc (len);
+ if (!buf)
+ {
+ set_errno (ENOMEM);
+ return -1;
+ }
raw_read (buf, len);
+ free(buf);
}
return sector_aligned_offset.QuadPart + bytes_left;
}