diff --git a/nselib/afp.lua b/nselib/afp.lua index 16c17c5c5..81db01b6c 100644 --- a/nselib/afp.lua +++ b/nselib/afp.lua @@ -1846,15 +1846,7 @@ Util = -- @param len number containing the length of the new string -- @return str string containing the new string ZeroPad = function( str, len ) - if len < str:len() then - return - end - - for i=1, len - str:len() do - str = str .. string.char(0) - end - - return str + return str .. string.rep('\0', len - str:len()) end, --- Splits a path into two pieces, directory and file diff --git a/nselib/drda.lua b/nselib/drda.lua index f96d47cfd..5aab6e91e 100644 --- a/nselib/drda.lua +++ b/nselib/drda.lua @@ -775,13 +775,7 @@ StringUtil = -- @param len the total length of the finished string -- @return str string containing the padded string padWithChar = function( str, chr, len ) - if ( len < #str ) then - return str - end - for i=1, (len - #str) do - str = str .. chr - end - return str + return str .. string.rep(chr, len - #str) end, } diff --git a/nselib/iscsi.lua b/nselib/iscsi.lua index abb735d26..47b3f5cba 100644 --- a/nselib/iscsi.lua +++ b/nselib/iscsi.lua @@ -126,8 +126,6 @@ Packet = { local pad = 4 - ((#kvps + 48) % 4) pad = ( pad == 4 ) and 0 or pad - for i=1, pad do kvps = kvps .. "\0" end - local len = bit.lshift( self.total_ahs_len, 24 ) + self.data_seg_len local flags = bit.lshift( ( self.flags.transit or 0 ), 7 ) flags = flags + bit.lshift( ( self.flags.continue or 0 ), 6) @@ -136,12 +134,12 @@ Packet = { local opcode = self.opcode + bit.lshift((self.immediate or 0), 6) - local data = bin.pack(">CCCCICSCSSISSIILLA", opcode, + local data = bin.pack(">CCCCICSCSSISSIILLAA", opcode, flags, self.ver_max, self.ver_min, len, bit.lshift( self.isid.t, 6 ) + bit.band( self.isid.a, 0x3f), self.isid.b, self.isid.c, self.isid.d, self.tsih, self.initiator_task_tag, self.cid, reserved, self.cmdsn, - self.expstatsn, reserved, reserved, kvps ) + self.expstatsn, reserved, reserved, kvps, string.rep('\0', pad) ) return data end @@ -271,7 +269,7 @@ Packet = { flags = flags + bit.lshift( (self.flags.continue or 0), 6 ) local kvps = tostring(self.kvp) - for i=1, (#kvps % 2) do kvps = kvps .. "\0" end + kvps = kvps .. string.rep('\0', #kvps % 2) self.data_seg_len = #kvps local len = bit.lshift( self.total_ahs_len, 24 ) + self.data_seg_len diff --git a/nselib/msrpctypes.lua b/nselib/msrpctypes.lua index 72a61321e..084dede57 100644 --- a/nselib/msrpctypes.lua +++ b/nselib/msrpctypes.lua @@ -589,7 +589,6 @@ end function marshall_ascii(str, max_length) local buffer_length local result - local padding = "" buffer_length = #str + 1 @@ -597,9 +596,7 @@ function marshall_ascii(str, max_length) max_length = buffer_length end - while((#(str .. string.char(0 .. padding)) % 4) ~= 0) do - padding = padding .. string.char(0) - end + local padding = string.rep('\0', (4 - (buffer_length % 4)) % 4) result = bin.pack(" 0 ) then - for i=1, ( 4-pad ) do - function_parameters = function_parameters .. "\0" - end - end + -- FIND_FIRST2 parameters: 12 + #fname + local pad = ( 32 + 36 + 12 + #fname ) % 4 + local function_parameters = bin.pack(" 0 ) then - for i=1,(8-(#uspw % 8)) do - uspw = uspw .. "\0" - end - end + uspw = uspw .. string.rep('\0', (8 - (#uspw % 8)) % 8) local iv2 = openssl.encrypt( "DES-CBC", key, nil, uspw, false ):sub(-8) local enc = openssl.encrypt( "DES-CBC", iv2, nil, uspw, false ):sub(-8) diff --git a/nselib/vnc.lua b/nselib/vnc.lua index 2efc7f39b..650ccd5be 100644 --- a/nselib/vnc.lua +++ b/nselib/vnc.lua @@ -196,11 +196,7 @@ VNC = { -- @param password string containing the password to process -- @return password string containing the processed password createVNCDESKey = function( self, password ) - if ( #password < 8 ) then - for i=1, (8 - #password) do - password = password .. string.char(0x00) - end - end + password = password .. string.rep('\0', 8 - #password) local newpass = "" for i=1, 8 do