aboutsummaryrefslogtreecommitdiffstats
path: root/com32
diff options
context:
space:
mode:
Diffstat (limited to 'com32')
-rw-r--r--com32/gfxboot/gfxboot.c3
-rw-r--r--com32/lib/memmem.c45
-rw-r--r--com32/modules/chain.c25
3 files changed, 51 insertions, 22 deletions
diff --git a/com32/gfxboot/gfxboot.c b/com32/gfxboot/gfxboot.c
index 3b09e74a..2323f8ed 100644
--- a/com32/gfxboot/gfxboot.c
+++ b/com32/gfxboot/gfxboot.c
@@ -21,6 +21,7 @@
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <minmax.h>
#include <syslinux/loadfile.h>
#include <syslinux/config.h>
@@ -770,7 +771,7 @@ void *load_one(char *file, ssize_t *file_size)
if(size) {
buf = malloc(size);
for(i = 1, cur = 0 ; cur < size && i > 0; cur += i) {
- i = save_read(fd, buf + cur, CHUNK_SIZE);
+ i = save_read(fd, buf + cur, min(CHUNK_SIZE, size - cur));
if(i == -1) break;
gfx_progress_update(i);
}
diff --git a/com32/lib/memmem.c b/com32/lib/memmem.c
index 8558a80d..7c42f1c3 100644
--- a/com32/lib/memmem.c
+++ b/com32/lib/memmem.c
@@ -18,26 +18,35 @@ void *memmem(const void *haystack, size_t n, const void *needle, size_t m)
size_t j, k, l;
- if (m > n)
- return NULL;
+ if (m > n || !m || !n)
+ return NULL;
- if (x[0] == x[1]) {
- k = 2;
- l = 1;
- } else {
- k = 1;
- l = 2;
- }
+ if (1 != m) {
+ if (x[0] == x[1]) {
+ k = 2;
+ l = 1;
+ } else {
+ k = 1;
+ l = 2;
+ }
- j = 0;
- while (j <= n - m) {
- if (x[1] != y[j + 1]) {
- j += k;
- } else {
- if (!memcmp(x + 2, y + j + 2, m - 2) && x[0] == y[j])
- return (void *)&y[j];
- j += l;
- }
+ j = 0;
+ while (j <= n - m) {
+ if (x[1] != y[j + 1]) {
+ j += k;
+ } else {
+ if (!memcmp(x + 2, y + j + 2, m - 2)
+ && x[0] == y[j])
+ return (void *)&y[j];
+ j += l;
+ }
+ }
+ } else {
+ do {
+ if (*y == *x)
+ return (void *)y;
+ y++;
+ } while (--n);
}
return NULL;
diff --git a/com32/modules/chain.c b/com32/modules/chain.c
index b93f38ed..89489d18 100644
--- a/com32/modules/chain.c
+++ b/com32/modules/chain.c
@@ -76,6 +76,10 @@
* equivalent to seg=0x70 file=<loader> sethidden,
* used with DOS' io.sys.
*
+ * drmk=<loader>
+ * Similar to msdos=<loader> but prepares the special options
+ * for the Dell Real Mode Kernel.
+ *
* grub=<loader>
* same as seg=0x800 file=<loader> & jumping to seg 0x820,
* used with GRUB Legacy stage2 files.
@@ -1707,16 +1711,31 @@ int main(int argc, char *argv[])
* We only really need 4 new, usable bytes at the end.
*/
int tsize = (data[ndata].size + 19) & 0xfffffff0;
+ const union syslinux_derivative_info *sdi;
+
+ sdi = syslinux_derivative_info();
+ /* We should lookup the Syslinux partition offset and use it */
+ fs_lba = *sdi->disk.partoffset;
+ /*
+ * fs_lba should be verified against the disk as some DRMK
+ * variants will check and fail if it does not match
+ */
+ dprintf(" fs_lba offset is %d\n", fs_lba);
+ /* DRMK only uses a DWORD */
+ if (fs_lba > 0xffffffff) {
+ error("LBA very large; Only using lower 32 bits; DRMK will probably fail\n");
+ }
regs.ss = regs.fs = regs.gs = 0; /* Used before initialized */
if (!realloc(data[ndata].data, tsize)) {
error("Failed to realloc for DRMK\n");
- goto bail;
+ goto bail; /* We'll never make it */
}
data[ndata].size = tsize;
- /* ds:[bp+28] must be 0x0000003f */
+ /* ds:bp is assumed by DRMK to be the boot sector */
+ /* offset 28 is the FAT HiddenSectors value */
regs.ds = (tsize >> 4) + (opt.seg - 2);
/* "Patch" into tail of the new space */
- *(int *)(data[ndata].data + tsize - 4) = 0x0000003f;
+ *(int *)(data[ndata].data + tsize - 4) = (int)(fs_lba & 0xffffffff);
}
ndata++;