diff --git a/main.cpp b/main.cpp index 699bf62..1f72ad1 100644 --- a/main.cpp +++ b/main.cpp @@ -155,12 +155,24 @@ struct DirTree } }; +constexpr uint64_t max_sz() +{ + uint64_t sz =0; + for(int i=0;i vecargs; auto args = arg_strings(argc,argv, vecargs); + const auto max_size = max_sz(); + static_assert(max_size == sizeof(DATA)); + if(!verify_hash()) { cerr << "Error: Bad message hash" << endl; @@ -172,20 +184,31 @@ int main(int argc,char** argv) #endif DirTree tree(path); + uint64_t sz=0; for(int i=0;i sizeof(DATA)) + { +#ifndef SILENT + cerr << "Failed: Invalid sizes (" << sz << " is larger than " << sizeof(DATA) << ")" << endl; +#endif + return 1; + } + #ifndef SILENT - cout << " <- " << DATA_NAMES[i] << " (" << DATA_LENGTHS[i] << ")" << flush; + cout << " <- " << DATA_NAMES[i] << " (" << data_len << ")" << flush; #endif - if(!verify_hash(i, data, DATA_LENGTHS[i])) { + if(!verify_hash(i, data, data_len)) { #ifndef SILENT cout << " FAILED: Invalid hash" << endl; cerr << "Aborting." << endl; #endif return 1; } else { - write_to_file(&tree / DATA_NAMES[i], data, DATA_LENGTHS[i]); + write_to_file(&tree / DATA_NAMES[i], data, data_len); #ifndef SILENT cout << " OK" << endl; #endif diff --git a/sfexec-create b/sfexec-create index 79b4b92..a49dc0c 100755 --- a/sfexec-create +++ b/sfexec-create @@ -11,7 +11,7 @@ $SCRIPTPATH/generator -o "$SCRIPTPATH/file.h" "$@" || exit 1 echo "Compiling binary..." -g++ -I$SCRIPTPATH/include/ -w --std=c++20 "$SCRIPTPATH/main.cpp" "$SCRIPTPATH/sha256_literal/sha256.cpp" -o sfexec +g++ -I$SCRIPTPATH/include/ -w --std=c++17 "$SCRIPTPATH/main.cpp" "$SCRIPTPATH/sha256_literal/sha256.cpp" -o sfexec rm "$SCRIPTPATH/file.h"