Skip to content

Commit

Permalink
HBSD: fixed broken vt behavior
Browse files Browse the repository at this point in the history
If we stay in 0. vt, and press shift+prnt_scr, then we dropped to 3.
console.

Proof:
--
 op@robot /tmp> cat foo.c
 #include <stdio.h>
 #define MOD 12U

 int
 main(int argc, char **argv)
 {
        int c=0;

        printf("not fixed: \n");
        for (int i=0; i<7; i++) {
                c = (c - 1) % MOD;
                printf("%d\n", c);
        }

        printf("fixed: \n");
        for (int i=0; i<7; i++) {
                c = (c - 1 + MOD) % MOD;
                printf("%d\n", c);
        }

        return (0);
 }
 op@robot /tmp> ./foo
 not fixed:
 3
 2
 1
 0
 3
 2
 1
 fixed:
 0
 11
 10
 9
 8
 7
 6
--

If the MOD in proof is not unsigned, then this mod leads to arr[-1]
access.

Signed-off-by: Oliver Pinter <oliver.pinter@hardenedbsd.org>
CC: Aleksandr Rybalko <ray@freebsd.org>
  • Loading branch information
opntr committed Feb 18, 2015
1 parent 9c4d8c4 commit 1805813
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion sys/dev/vt/vt_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ vt_processkey(keyboard_t *kbd, struct vt_device *vd, int c)
return (0);
case PREV:
/* Switch to previous VT. */
c = (vw->vw_number - 1) % VT_MAXWINDOWS;
c = (vw->vw_number - 1 + VT_MAXWINDOWS) % VT_MAXWINDOWS;
vw = vd->vd_windows[c];
if (vw != NULL)
vt_proc_window_switch(vw);
Expand Down

0 comments on commit 1805813

Please sign in to comment.