From 384a1ec525ecbd50da7375bd929417191093d694 Mon Sep 17 00:00:00 2001
From: Andy Vawer <andy@vawer.com>
Date: Sat, 18 Jan 2020 12:12:23 +0000
Subject: [PATCH] Fix zero page access looking for ptr_ sprite validation

On mouse click, check for icon type was incorrect, so trying to apply tests for 'P' validation string/ptr_write on inappropriate icons (eg. sprites), leading to invalid validation string accesses. Correct the test performed.
Also add 3 further AcceptLoosePointer checks to validation string pointers.

Version 5.69. Tagged as 'Wimp-5_69'
---
 VersionASM | 12 ++++++------
 VersionNum | 20 ++++++++++----------
 s/Wimp01   |  5 +++--
 s/Wimp03   |  9 +++++----
 s/Wimp05   | 12 +++++++-----
 5 files changed, 31 insertions(+), 27 deletions(-)

diff --git a/VersionASM b/VersionASM
index 1ade003..3a28999 100644
--- a/VersionASM
+++ b/VersionASM
@@ -9,12 +9,12 @@
                         GBLS    Module_ApplicationDate
                         GBLS    Module_HelpVersion
                         GBLS    Module_ComponentName
-Module_MajorVersion     SETS    "5.68"
-Module_Version          SETA    568
+Module_MajorVersion     SETS    "5.69"
+Module_Version          SETA    569
 Module_MinorVersion     SETS    ""
-Module_Date             SETS    "04 Jan 2020"
-Module_ApplicationDate  SETS    "04-Jan-20"
+Module_Date             SETS    "18 Jan 2020"
+Module_ApplicationDate  SETS    "18-Jan-20"
 Module_ComponentName    SETS    "Wimp"
-Module_FullVersion      SETS    "5.68"
-Module_HelpVersion      SETS    "5.68 (04 Jan 2020)"
+Module_FullVersion      SETS    "5.69"
+Module_HelpVersion      SETS    "5.69 (18 Jan 2020)"
                         END
diff --git a/VersionNum b/VersionNum
index 8f647ad..cf4e21c 100644
--- a/VersionNum
+++ b/VersionNum
@@ -1,21 +1,21 @@
-/* (5.68)
+/* (5.69)
  *
  * This file is automatically maintained by srccommit, do not edit manually.
  *
  */
-#define Module_MajorVersion_CMHG        5.68
+#define Module_MajorVersion_CMHG        5.69
 #define Module_MinorVersion_CMHG        
-#define Module_Date_CMHG                04 Jan 2020
+#define Module_Date_CMHG                18 Jan 2020
 
-#define Module_MajorVersion             "5.68"
-#define Module_Version                  568
+#define Module_MajorVersion             "5.69"
+#define Module_Version                  569
 #define Module_MinorVersion             ""
-#define Module_Date                     "04 Jan 2020"
+#define Module_Date                     "18 Jan 2020"
 
-#define Module_ApplicationDate          "04-Jan-20"
+#define Module_ApplicationDate          "18-Jan-20"
 
 #define Module_ComponentName            "Wimp"
 
-#define Module_FullVersion              "5.68"
-#define Module_HelpVersion              "5.68 (04 Jan 2020)"
-#define Module_LibraryVersionInfo       "5:68"
+#define Module_FullVersion              "5.69"
+#define Module_HelpVersion              "5.69 (18 Jan 2020)"
+#define Module_LibraryVersionInfo       "5:69"
diff --git a/s/Wimp01 b/s/Wimp01
index 2c8446c..7fdb155 100644
--- a/s/Wimp01
+++ b/s/Wimp01
@@ -6161,8 +6161,9 @@ doublewritable_on
         LDR     R0,[handle,#w_icons]
         ADD     R0,R0,R4,LSL #i_shift
         LDR     R3,[R0,#i_data+4]
-        CMP     R3,#0
-        BLE     %FT99 ; no
+        AcceptLoosePointer_NegOrZero r3,-1
+        CMP     R3,R3,ASR #31
+        BEQ     %FT99 ; no
 
  ; page in the task holding the icon
         LDR     R14,taskhandle
diff --git a/s/Wimp03 b/s/Wimp03
index 2ec378e..cb00247 100644
--- a/s/Wimp03
+++ b/s/Wimp03
@@ -2133,9 +2133,9 @@ testbutton
         MOV     R14,#1
         STRB    R14,cnp_clickcounter
         BEQ     %FT00
-        TST     R6,#ibb_writeable
-        BLNE    doubleptr_on
-        BLEQ    doublewritable_on
+        TST     R6,#ibb_cnpwriteable
+        BLNE    doublewritable_on
+        BLEQ    doubleptr_on
 00
         |
         BLNE    doubleptr_on            ; if current shape = 1, set double ptr
@@ -2206,7 +2206,8 @@ wait2clicks
 
         TST     R6,#ibb_cnpwriteable
         STREQ   R7,mouseflags
-        BLEQ    doublewritable_off
+        BLNE    doublewritable_off
+        BLEQ    doubleptr_off
         BEQ     justtellhim                 ; normal action if CC and not a writeable
 
         ; we are a cnp writeable at this point
diff --git a/s/Wimp05 b/s/Wimp05
index d125785..146c9a2 100644
--- a/s/Wimp05
+++ b/s/Wimp05
@@ -3239,8 +3239,9 @@ clipboard_abort_drag
 
 clipboard_check_disabled
         ; returns Z set if clipboard key handling is disabled; clear otherwise
-        CMP     R3,#0
-        BGT     %FT00
+        AcceptLoosePointer_NegOrZero R3,-1
+        CMP     R3,R3,ASR #31
+        BNE     %FT00
         TST     R14,R14 ; unset Z
         MOV     PC,R14
 00
@@ -3538,9 +3539,10 @@ clipboard_wpaste
         [ UTF8
         ; get max UTF8 length if applicable
         Push    "R8"
-        CMP     R3,#0
-        MOVLE   R8,#bignum
-        BLE     %FT21                   ; no validation string present
+        AcceptLoosePointer_NegOrZero R3,-1
+        CMP     R3,R3,ASR #31
+        MOVEQ   R8,#bignum
+        BEQ     %FT21                   ; no validation string present
 
         Push    "R0-R3"
         MOV     R2, #WimpValidation_CharLimit  ; find "U" command, if any
-- 
GitLab