findfs: fix LUKS and FAT detection routines; do not exit if corrupted
FAT fs makes us try to seek past volume
function old new delta
volume_id_get_buffer 301 327 +26
volume_id_probe_luks 79 82 +3
get_attr_volume_id 73 65 -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 29/-8) Total: 21 bytes
diff --git a/util-linux/volume_id/util.c b/util-linux/volume_id/util.c
index 315d75c..c4d20ba 100644
--- a/util-linux/volume_id/util.c
+++ b/util-linux/volume_id/util.c
@@ -181,7 +181,7 @@
buf[4], buf[5],
buf[6], buf[7],
buf[8], buf[9],
- buf[10], buf[11], buf[12], buf[13], buf[14],buf[15]);
+ buf[10], buf[11], buf[12], buf[13], buf[14], buf[15]);
break;
case UUID_DCE_STRING:
memcpy(id->uuid, buf, count);
@@ -190,6 +190,9 @@
}
}
+/* Do not use xlseek here. With it, single corrupted filesystem
+ * may result in attempt to seek past device -> exit.
+ * It's better to ignore such fs and continue. */
void *volume_id_get_buffer(struct volume_id *id, uint64_t off, size_t len)
{
ssize_t buf_len;
@@ -204,7 +207,10 @@
/* check if we need to read */
if ((off + len) > id->sbbuf_len) {
dbg("read sbbuf len:0x%llx", (unsigned long long) (off + len));
- xlseek(id->fd, 0, SEEK_SET);
+ if (lseek(id->fd, 0, SEEK_SET) != 0) {
+ dbg("seek(0) failed");
+ return NULL;
+ }
buf_len = full_read(id->fd, id->sbbuf, off + len);
if (buf_len < 0) {
dbg("read failed (%s)", strerror(errno));
@@ -234,7 +240,10 @@
/* check if we need to read */
if ((off < id->seekbuf_off) || ((off + len) > (id->seekbuf_off + id->seekbuf_len))) {
dbg("read seekbuf off:0x%llx len:0x%zx", (unsigned long long) off, len);
- xlseek(id->fd, off, SEEK_SET);
+ if (lseek(id->fd, off, SEEK_SET) != off) {
+ dbg("seek(0x%llx) failed", (unsigned long long) off);
+ return NULL;
+ }
buf_len = full_read(id->fd, id->seekbuf, len);
if (buf_len < 0) {
dbg("read failed (%s)", strerror(errno));