liboqs/tests/test_lint.py
Douglas Stebila 6e0b0d79a9
Add SPDX-License-Identifier headers (#749)
* Add SPDX-License-Identifier in src/common

* Add SPDX-License-Identifier in FrodoKEM

* Add SPDX-License-Identifier in SIKE

* Add SPDX-License-Identifier in BIKE

* Add SPDX-License-Identifier in OQS headers

* Add SPDX-License-Identifier in files generated during copy-from-pqclean

* Add SPDX-License-Identifier in Picnic

* Add SPDX-License-Identifier in qTesla

* Add SPDX-License-Identifier in CMake files

* Update license info in README

* Add SPDX-License-Identifier in scripts

* Add SPDX-License-Info to CMakeLists

* Add SPDX-License-Info in tests

* Add SPDX-License-Info to various files

* Prettyprint

* Add test for SPDX-License-Identifier headers

* Updated license identifiers for CPU extension detection code.

* Use conjunction for SPDX in file with two licenses

Co-authored-by: xvzcf <xvzcf@users.noreply.github.com>
2020-05-12 11:45:37 -04:00

28 lines
1.1 KiB
Python

# SPDX-License-Identifier: MIT
import helpers
import pytest
import sys
###
# Checks that "free" is not used unprotected in the main OQS code.
###
@helpers.filtered_test
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not needed on Windows")
def test_free():
files = helpers.run_subprocess(['find', 'src', '-name', '*.c'])
files = helpers.run_subprocess(['grep', '-v', 'picnic/external'], input=files.encode('utf8'))
lines = helpers.run_subprocess(['xargs', 'grep', '[^_]free('], input=files.encode('utf8'))
lines = lines.split("\n")
okay = True
for line in lines:
if line == "": continue
if not('IGNORE free-check' in line):
okay = False
print("Suspicious `free` in " + line)
assert okay, "'free' is used in some files. These should be changed to 'OQS_MEM_secure_free' or 'OQS_MEM_insecure_free' as appropriate. If you are sure you want to use 'free' in a particular spot, add the comment '// IGNORE free-check' on the line where 'free' occurs."
if __name__ == "__main__":
import sys
pytest.main(sys.argv)