From 9450cb725a2fa764f406facddfccda8e49ed6e97 Mon Sep 17 00:00:00 2001 From: dmiller Date: Mon, 23 May 2016 04:30:06 +0000 Subject: [PATCH] Avoid boolean tautologies of the form 'not x == y' Lua operator 'not' has higher precedence than '==', so the statement not x == "something" is equivalent to: (not x) == "something" which will always be false, since the value of 'not x' will be either 'true' or 'false' and the string "something" is not the boolean 'true' or 'false'. This is usually resolved by using the '~=' operator. --- nselib/anyconnect.lua | 2 +- nselib/bittorrent.lua | 2 +- scripts/broadcast-ping.nse | 2 +- scripts/dns-fuzz.nse | 4 ++-- scripts/lltd-discovery.nse | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/nselib/anyconnect.lua b/nselib/anyconnect.lua index 912aa6e6f..ff86abc38 100644 --- a/nselib/anyconnect.lua +++ b/nselib/anyconnect.lua @@ -86,7 +86,7 @@ Cisco = { local path = '/' local response = http.head(self.host, self.port, path, options) -- account for redirects - if not response.status == 200 then + if response.status ~= 200 then return false, "Failed to connect to SSL VPN server" elseif response.location then local u = url.parse(response.location[#response.location]) diff --git a/nselib/bittorrent.lua b/nselib/bittorrent.lua index f1708ac0a..0190b8e5c 100644 --- a/nselib/bittorrent.lua +++ b/nselib/bittorrent.lua @@ -1156,7 +1156,7 @@ Torrent = end -- the action in the response has to be 0 too - if not r_action == "00000000" then + if r_action ~= "00000000" then return false, "Wrong action field, usually caused by an erroneous request" end diff --git a/scripts/broadcast-ping.nse b/scripts/broadcast-ping.nse index 1c60d7662..5604f5033 100644 --- a/scripts/broadcast-ping.nse +++ b/scripts/broadcast-ping.nse @@ -222,7 +222,7 @@ action = function() -- single interface defined local interface = interface_opt or interface_arg local if_table = nmap.get_interface_info(interface) - if not if_table or not if_table.address or not if_table.link=="ethernet" then + if not (if_table and if_table.address and if_table.link=="ethernet") then stdnse.debug1("Interface not supported or not properly configured.") return false end diff --git a/scripts/dns-fuzz.nse b/scripts/dns-fuzz.nse index 89df0e819..d18482cce 100644 --- a/scripts/dns-fuzz.nse +++ b/scripts/dns-fuzz.nse @@ -193,7 +193,7 @@ function dropByte (dnsPacket) -- Iterate over every byte in the packet dnsPacket:gsub(".", function(c) i=i+1 - if not i==byteToDrop then + if i ~= byteToDrop then newPacket[#newPacket+1] = c end end) @@ -328,7 +328,7 @@ action = function(host, port) query = makePacket () -- induce random jitter retStr = corruptAndSend (host, port, query) - if not retStr==nil then + if retStr then return retStr end end diff --git a/scripts/lltd-discovery.nse b/scripts/lltd-discovery.nse index 25ffb06af..f36a33817 100644 --- a/scripts/lltd-discovery.nse +++ b/scripts/lltd-discovery.nse @@ -268,7 +268,7 @@ action = function() -- single interface defined local interface = interface_opt or interface_arg local if_table = nmap.get_interface_info(interface) - if not if_table or not if_table.address or not if_table.link=="ethernet" then + if not (if_table and if_table.address and if_table.link=="ethernet") then stdnse.debug1("Interface not supported or not properly configured.") return false end