From ee987ca546002bcb0df97b1e542c30d6b8c09dd3 Mon Sep 17 00:00:00 2001 From: Rafal Gwozdzinski Date: Sun, 18 Jun 2023 15:08:42 +0200 Subject: [PATCH 1/3] Validate top-module input Signed-off-by: Rafal Gwozdzinski --- bin/ocaml/top.ml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bin/ocaml/top.ml b/bin/ocaml/top.ml index 5871a69dfa2..78d551906f8 100644 --- a/bin/ocaml/top.ml +++ b/bin/ocaml/top.ml @@ -100,6 +100,11 @@ module Module = struct let ctx = Super_context.context sctx in let src = Path.Build.append_source ctx.build_dir mod_ in let dir = Path.Build.parent_exn src in + let filename = Path.Build.basename src in + if Sys.file_exists filename then () + else User_error.raise [ Pp.text "file doesn't exist" ] ; + if Filename.extension filename = ".ml" then () + else User_error.raise [ Pp.text "file should have '.ml' extension" ] ; let open Memo.O in let module_name = let name = src |> Path.Build.basename |> Filename.chop_extension in From 273d40f0fd2b8ea956a701625d2632562c6bfac7 Mon Sep 17 00:00:00 2001 From: Rafal Gwozdzinski Date: Sun, 18 Jun 2023 15:28:45 +0200 Subject: [PATCH 2/3] Update changelog for #8005 Signed-off-by: Rafal Gwozdzinski --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 6e995537b3c..f7724265669 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,8 @@ Unreleased ---------- +- Validate path for `$ dune ocaml top-module`. (#8005, fixes #8004, @3Rafal) + - Include the time it takes to read/write state files when `--trace-file` is enabled (#7960, @rgrinberg) From c775d7a43fd22453b8f5e4e2f9db88f36ae60c41 Mon Sep 17 00:00:00 2001 From: Rafal Gwozdzinski Date: Wed, 21 Jun 2023 10:45:03 +0200 Subject: [PATCH 3/3] fix: Validate if file is missing an extension Signed-off-by: Rafal Gwozdzinski --- CHANGES.md | 2 +- bin/ocaml/top.ml | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index f7724265669..ed0205f35b4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,7 +1,7 @@ Unreleased ---------- -- Validate path for `$ dune ocaml top-module`. (#8005, fixes #8004, @3Rafal) +- Validate file extension for `$ dune ocaml top-module`. (#8005, fixes #8004, @3Rafal) - Include the time it takes to read/write state files when `--trace-file` is enabled (#7960, @rgrinberg) diff --git a/bin/ocaml/top.ml b/bin/ocaml/top.ml index 78d551906f8..4642da7c559 100644 --- a/bin/ocaml/top.ml +++ b/bin/ocaml/top.ml @@ -101,13 +101,11 @@ module Module = struct let src = Path.Build.append_source ctx.build_dir mod_ in let dir = Path.Build.parent_exn src in let filename = Path.Build.basename src in - if Sys.file_exists filename then () - else User_error.raise [ Pp.text "file doesn't exist" ] ; - if Filename.extension filename = ".ml" then () - else User_error.raise [ Pp.text "file should have '.ml' extension" ] ; + if Filename.extension filename = "" then + User_error.raise [ Pp.text "file is missing an extension" ]; let open Memo.O in let module_name = - let name = src |> Path.Build.basename |> Filename.chop_extension in + let name = Filename.chop_extension filename in match Dune_rules.Module_name.of_string_user_error (Loc.none, name) with | Ok s -> s | Error e -> raise (User_error.E e)