View | Details | Raw Unified | Return to bug 214423
Collapse All | Expand All

(-)dosfs.c (-24 / +9 lines)
Lines 768-775 Link Here
768
fatget(DOS_FS *fs, u_int *c)
768
fatget(DOS_FS *fs, u_int *c)
769
{
769
{
770
    u_char buf[4];
770
    u_char buf[4];
771
    u_char *s;
771
    u_int x, offset, nbyte;
772
    u_int x, offset, off, n, nbyte, lsec;
773
    struct devdesc *dd = fs->fd->f_devdata;
772
    struct devdesc *dd = fs->fd->f_devdata;
774
    int err = 0;
773
    int err = 0;
775
774
Lines 782-807 Link Here
782
    } else {
781
    } else {
783
	offset = fatoff(fs->fatsz, *c);
782
	offset = fatoff(fs->fatsz, *c);
784
	nbyte = fs->fatsz != 32 ? 2 : 4;
783
	nbyte = fs->fatsz != 32 ? 2 : 4;
785
784
	if (offset + nbyte > secbyt(fat.size))
786
	s = buf;
785
	    return EINVAL;
787
	if ((off = offset & (SECSIZ - 1))) {
786
	memcpy(buf, fat.buf + offset, nbyte);
788
	    offset -= off;
789
	    lsec = bytsec(offset);
790
	    offset += SECSIZ;
791
	    if ((n = SECSIZ - off) > nbyte)
792
		n = nbyte;
793
	    memcpy(s, fat.buf + secbyt(lsec) + off, n);
794
	    s += n;
795
	    nbyte -= n;
796
	}
797
	n = nbyte & (SECSIZ - 1);
798
	if (nbyte -= n) {
799
	    memcpy(s, fat.buf + secbyt(bytsec(offset)), nbyte);
800
	    offset += nbyte;
801
	    s += nbyte;
802
	}
803
	if (n)
804
	    memcpy(s, fat.buf + secbyt(bytsec(offset)), n);
805
    }
787
    }
806
788
807
    x = fs->fatsz != 32 ? cv2(buf) : cv4(buf);
789
    x = fs->fatsz != 32 ? cv2(buf) : cv4(buf);
Lines 827-840 Link Here
827
    char *s;
809
    char *s;
828
    u_int off, n;
810
    u_int off, n;
829
    int err;
811
    int err;
812
    u_char local_buf[SECSIZ];
830
813
831
    s = buf;
814
    s = buf;
832
    if ((off = offset & (SECSIZ - 1))) {
815
    if ((off = offset & (SECSIZ - 1))) {
833
        offset -= off;
816
        offset -= off;
834
        if ((n = SECSIZ - off) > nbyte)
817
        if ((n = SECSIZ - off) > nbyte)
835
            n = nbyte;
818
            n = nbyte;
836
        if ((err = ioget(fs->fd, bytsec(offset), off, s, n)))
819
        if ((err = ioget(fs->fd, bytsec(offset), 0, local_buf, SECSIZ)))
837
            return err;
820
            return err;
821
        memcpy(s, local_buf + off, n);
838
        offset += SECSIZ;
822
        offset += SECSIZ;
839
        s += n;
823
        s += n;
840
        nbyte -= n;
824
        nbyte -= n;
Lines 847-854 Link Here
847
        s += nbyte;
831
        s += nbyte;
848
    }
832
    }
849
    if (n) {
833
    if (n) {
850
        if ((err = ioget(fs->fd, bytsec(offset), 0, s, n)))
834
        if ((err = ioget(fs->fd, bytsec(offset), 0, local_buf, SECSIZ)))
851
            return err;
835
            return err;
836
        memcpy(s, local_buf, n);
852
    }
837
    }
853
    return 0;
838
    return 0;
854
}
839
}

Return to bug 214423