Skip to content

Commit

Permalink
Fix NUL string error (#7)
Browse files Browse the repository at this point in the history
* Prevent NUL characters in strings read by `licensecheck`

* add test

* add error test

* bump version

Co-authored-by: Mosè Giordano <[email protected]>
  • Loading branch information
ericphanson and giordano authored Feb 17, 2021
1 parent d1bc603 commit 0a94bfc
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "LicenseCheck"
uuid = "726dbf0d-6eb6-41af-b36c-cd770e0f00cc"
authors = ["Eric P. Hanson"]
version = "0.2.0"
version = "0.2.1"

[deps]
licensecheck_jll = "4ecb348a-8b88-51ea-b912-4c460483ee91"
Expand Down
4 changes: 3 additions & 1 deletion src/find_licenses.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ function license_table(dir, names; validate_strings = true, validate_paths = tru
path = joinpath(dir, lic)
validate_paths && (isfile(path) || continue)
text = read(path, String)
validate_strings && (isvalid(String, text) || continue)
# In licensecheck we're going to convert the string to a `Cstring` with
# `unsafe_convert`, so the string can't have any NUL character
validate_strings && ((isvalid(String, text) && !Base.containsnul(text)) || continue)
lc = licensecheck(text)
if lc.license_file_percent_covered > 0
push!(table, (; license_filename=lic, lc...))
Expand Down
21 changes: 21 additions & 0 deletions test/nul_string_dir/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Eric P. Hanson

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Binary file added test/nul_string_dir/file_with_nul_in_the_middle.txt
Binary file not shown.
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,12 @@ dorian_gray = """
results = find_licenses_by_list(joinpath(@__DIR__, ".."))
@test fl results
end

@testset "AnalyzeRegistry#14" begin
fl = find_license("nul_string_dir")
@test fl.license_filename == "LICENSE"
@test fl.licenses_found == ["MIT"]
@test fl.license_file_percent_covered > 90
@test_throws ArgumentError LicenseCheck.license_table("nul_string_dir", ["file_with_nul_in_the_middle.txt"]; validate_strings = false)
end
end

2 comments on commit 0a94bfc

@ericphanson
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/30209

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.1 -m "<description of version>" 0a94bfcfdf1dea093ab7ef1a1ed081a36b43e09b
git push origin v0.2.1

Please sign in to comment.