From: Richard W.M. Jones Date: Sat, 18 Nov 2017 11:51:06 +0000 (+0000) Subject: Fixes for -safe-string. X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=HEAD;p=guestfs-browser.git Fixes for -safe-string. --- diff --git a/deviceSet.ml b/deviceSet.ml index b51391e..fe69d25 100644 --- a/deviceSet.ml +++ b/deviceSet.ml @@ -25,9 +25,9 @@ let canonical dev = (dev.[5] = 'h' || dev.[5] = 's' || dev.[5] = 'v') && dev.[6] = 'd' && dev.[7] >= 'a' && dev.[7] <= 'z' then ( - let dev = String.copy dev in - dev.[5] <- 's'; - dev + let dev = Bytes.of_string dev in + Bytes.set dev 5 's'; + Bytes.to_string dev ) else dev diff --git a/utils.ml b/utils.ml index 57faf38..b06a127 100644 --- a/utils.ml +++ b/utils.ml @@ -202,22 +202,24 @@ let file_permissions_string mode = let suid = is_suid mode in let sgid = is_sgid mode in let svtx = is_svtx mode in - if suid then str.[3] <- 's'; - if sgid then str.[6] <- 's'; - if svtx then str.[9] <- 't'; + let str = Bytes.of_string str in + if suid then Bytes.set str 3 's'; + if sgid then Bytes.set str 6 's'; + if svtx then Bytes.set str 9 't'; - str + Bytes.to_string str let tmpdir () = let chan = open_in "/dev/urandom" in - let data = String.create 16 in - really_input chan data 0 (String.length data); + let data = Bytes.create 16 in + really_input chan data 0 (Bytes.length data); close_in chan; - let data = Digest.to_hex (Digest.string data) in + let data = Digest.to_hex (Digest.bytes data) in (* Note this is secure, because if the name already exists, even as a * symlink, mkdir(2) will fail. *) - let tmpdir = Filename.temp_dir_name // sprintf "guestfsbrowser%s.tmp" data in + let tmpdir = + Filename.get_temp_dir_name () // sprintf "guestfsbrowser%s.tmp" data in Unix.mkdir tmpdir 0o700; at_exit (fun () ->