Check index ID characters before making a dir with them

This commit is contained in:
orbifx 2022-11-17 20:53:00 +00:00
parent ccec104c5e
commit 79ec24530d
1 changed files with 11 additions and 0 deletions

View File

@ -86,6 +86,13 @@ let per_text url dir filter print i id time title authors topics = match id with
|| Person.Set.exists (fun t -> List.mem (Person.to_string t) authors) filter.authors)
then pull_text url dir id
let validate_id_length s = String.length s <= 32
let validate_id_chars s = try
String.iter (function 'a'..'z'|'A'..'Z'|'0'..'9'-> () | _ -> raise (Invalid_argument "")) s;
true
with Invalid_argument _ -> false
let pull_index url authors_opt topics_opt =
let index_url = url ^ "/index.pck" in
match curl_pull index_url with
@ -95,6 +102,10 @@ let pull_index url authors_opt topics_opt =
| Error s -> Printf.printf "Error with %s: %s\n" url s; false
| Ok pk when pk.info.id = "" ->
Printf.printf "Empty ID index.pck, skipping %s\n" url; false
| Ok pk when not (validate_id_length pk.info.id) ->
Printf.printf "Index pack ID longer than 32 characters, skipping %s\n" url; false
| Ok pk when not (validate_id_chars pk.info.id) ->
Printf.printf "Index pack contains invalid ID characters, skipping %s\n" url; false
| Ok pk ->
let dir = Filename.concat Logarion.Peers.text_dir pk.info.id in
Logarion.File_store.with_dir dir;