--------------------------------------------------------------
                      VFP 9.0 FIX - EDITBOX CONTROL ENTER AN INFINITE LOOP
                                  March 2017
                 --------------------------------------------------------------
                                     CCB



1. BUG:

     In the EditBox Control (and the VFP text editor, for example, the MODIFY COMMAND window),
     if there are some non-printable characters (for example, CHR(0)), sometimes VFP will enter an infinite loop.

     The bug occurs in vfp9, it does not occur in vfp6, vfp7 and vfp8.

     The bug only occurs in DBCS (Double-Byte Character Sets) environments.


2. CAUSE:

     There are some BUGs in the following code.


3. RESOLUTION:

     We can write some code to fix the BUG.

     Label613809 ::
             mov  eax , dword ptr [ ebp + 12 ]                               ;0x00613809 :        8b450c
             xor edx , edx                                                   ;0x0061380c :        33d2
             cmp  dword ptr [ ebp - 8 ] , edx                                ;0x0061380e :        3955f8
             mov edi , eax                                                   ;0x00613811 :        8bf8
             mov  dword ptr [ ebp - 24 ] , eax                               ;0x00613813 :        8945e8
             jle Label61387e                                                 ;0x00613816 :        7e66

     Label613818 ::
             mov  cl , byte ptr [eax]                                        ;0x00613818 :        8a08
             movzx esi , cl                                                  ;0x0061381a :        0fb6f1
             test  byte ptr [ 2 * esi + offset Data937360 ] , 040h                    ;0x0061381d :        f604756073930040
             mov  dword ptr [ ebp - 24 ] , eax                               ;0x00613825 :        8945e8
             je Label613834                                                  ;0x00613828 :        740a
             cmp cl , 0Dh                                                    ;0x0061382a :        80f90d
             je Label613834                                                  ;0x0061382d :        7405
             cmp cl , 0Ah                                                    ;0x0061382f :        80f90a
             jne Label61383d                                                 ;0x00613832 :        7509

     Label613834 ::
             test  byte ptr [ esi + offset Data937120 ] , 01h                         ;0x00613834 :        f6862071930001
             je Label61386f                                                  ;0x0061383b :        7432

     Label61383d ::
             cmp  edx , dword ptr [ ebp - 8 ]                                ;0x0061383d :        3b55f8
             mov edi , eax                                                   ;0x00613840 :        8bf8
             jnl Label61386f                                                 ;0x00613842 :        7d2b

     Label613844 ::
             mov  cl , byte ptr [eax]                                        ;0x00613844 :        8a08
             movzx edx , cl                                                  ;0x00613846 :        0fb6d1
             test  byte ptr [ 2 * edx + offset Data937360 ] , 040h                    ;0x00613849 :        f604556073930040
             je Label61386f                                                  ;0x00613851 :        741c
             cmp cl , 0Dh                                                    ;0x00613853 :        80f90d
             je Label61386f                                                  ;0x00613856 :        7417
             cmp cl , 0Ah                                                    ;0x00613858 :        80f90a
             je Label61386f                                                  ;0x0061385b :        7412
             mov  dword ptr [ ebp - 24 ] , eax                               ;0x0061385d :        8945e8
             call Fun418cec                                                  ;0x00613860 :        e88754e0ff
             mov ecx , eax                                                   ;0x00613865 :        8bc8
             sub  ecx , dword ptr [ ebp + 12 ]                               ;0x00613867 :        2b4d0c
             cmp  ecx , dword ptr [ ebp - 8 ]                                ;0x0061386a :        3b4df8
             jl Label613844                                                  ;0x0061386d :        7cd5

     Label61386f ::


     ;
     ;                 --------------------------------------------------------------
     ;                      VFP 9.0 FIX - EDITBOX CONTROL ENTER AN INFINITE LOOP
     ;                                  March 2017
     ;                 --------------------------------------------------------------
     ;                                     CCB
     ;
     ; In the EditBox Control (and the VFP text editor, for example, the MODIFY COMMAND window),
     ; if there are some non-printable characters (for example, CHR(0)), sometimes VFP will enter an infinite loop.
     ;
     ; 2017/3/22, by ccb
     ;

             cmp byte ptr [eax],00h
             jne Label613873
             inc eax
             jmp Label613874


     Label613873 ::
             call Fun418cec                                                  ;0x0061386f :        e87854e0ff

     Label613874 ::
             mov edx , eax                                                   ;0x00613874 :        8bd0
             sub  edx , dword ptr [ ebp + 12 ]                               ;0x00613876 :        2b550c
             cmp  edx , dword ptr [ ebp - 8 ]                                ;0x00613879 :        3b55f8
             jl Label613818                                                  ;0x0061387c :        7c9a

     Label61387e ::
             sub  edi , dword ptr [ ebp + 12 ]                               ;0x0061387e :        2b7d0c
             mov esi , edi                                                   ;0x00613881 :        8bf7
             cmp  esi , dword ptr [ ebp - 8 ]                                ;0x00613883 :        3b75f8
             je Label61388c                                                  ;0x00613886 :        7404
             test esi , esi                                                  ;0x00613888 :        85f6
             jne Label6138ac                                                 ;0x0061388a :        7520

     Label61388c ::
             mov  edi , dword ptr [ ebp + 12 ]                               ;0x0061388c :        8b7d0c
             mov  esi , dword ptr [ ebp - 24 ]                               ;0x0061388f :        8b75e8
             mov eax , edi                                                   ;0x00613892 :        8bc7
             sub esi , edi                                                   ;0x00613894 :        2bf7
             call Fun418cec                                                  ;0x00613896 :        e85154e0ff
             sub eax , edi                                                   ;0x0061389b :        2bc7
             cmp eax , esi                                                   ;0x0061389d :        3bc6
             jle Label6138ac                                                 ;0x0061389f :        7e0b
             mov eax , edi                                                   ;0x006138a1 :        8bc7
             call Fun418cec                                                  ;0x006138a3 :        e84454e0ff
             mov esi , eax                                                   ;0x006138a8 :        8bf0
             sub esi , edi                                                   ;0x006138aa :        2bf7

     Label6138ac ::
             mov  edi , dword ptr [ ebp - 8 ]                                ;0x006138ac :        8b7df8
             jmp Label4e69f6                                                 ;0x006138af :        e94231edff


4. APPLIES TO:

     VFP 9.0.0.2412
     VFP 9.0.0.3504 (SP1)
     VFP 9.0.0.4611 (SP2)
     VFP 9.0.0.5015 (SP2)
     VFP 9.0.0.5411 (SP2)
     VFP 9.0.0.5721 (SP2)
     VFP 9.0.0.5815 (SP2)
     VFP 9.0.0.6303 (SP2)
     VFP 9.0.0.6602 (SP2)
     VFP 9.0.0.7423 (SP2)

     The bug has been fixed in VFP Advanced.


5. REFERENCE WEBSITES:

     1, baiyujia.com:
     http://www.baiyujia.com

     2, csdn.net:
     http://bbs.csdn.net/topics/100089631

     3, tech-archive.net:
     http://www.tech-archive.net/Archive/Fox/microsoft.public.fox.programmer.exchange/2005-12/msg00493.html

     4, microsoft.com:
     https://blogs.msdn.microsoft.com/calvin_hsia/2006/11/15/heres-an-infinite-loop-that-will-hang-your-machine/

     5, sunyear.com.tw:
     http://vfp.sunyear.com.tw/viewtopic.php?t=4835


6. OTHER:

     For reference only, there is no guarantees.

     Any questions or suggestions, please e-mail to ccb2000@163.com.