Kevin Day [Mon, 18 Jul 2022 01:26:23 +0000 (20:26 -0500)]
Bugfix: IKI substitution is incorrectly applied.
The function controller_rule_action_read_delimit_apply() is remapping the array and applies the delimits.
Another function is then applying the same delimits again, but against the remapped buffer.
This results in the delimits being applied to the wrong locations in the string.
Get rid of the controller_rule_action_read_delimit_apply().
The use of this function results in an incorrect string when printing validation.
Thoroughly clear the entire IKI data when processing the actions.
Kevin Day [Sun, 17 Jul 2022 23:42:21 +0000 (18:42 -0500)]
Security: Invalid reads on NULL terminated strings with a max width greater than 1.
The max width cannot be reliably trusted in NULL terminated strings.
Check if each character in the expected max width is not terminated early due to a NULL.
If it is, then adjust the max width.
Kevin Day [Sun, 17 Jul 2022 20:49:48 +0000 (15:49 -0500)]
Update: Reduce number of allocations by pre-determining size when easily possible.
There are several cases where the expected size can be calculated.
Pre-allocated the expected size to reduce reallocation and improve performance by reducing memory overhead.
I also noticed that the comment is no longer correct and that the not quoted check could be reversed.
Changing this simplified the code, slightly.
Kevin Day [Sun, 17 Jul 2022 20:34:16 +0000 (15:34 -0500)]
Bugfix: Reserved parameter IKI expansion is not adding spaces and the "top" reserved parameter should always end in a slash.
The IKI expansion on reserved parameters, such as "parameter:"fakefile"", should include spaces as appropriate.
For example, given a call to "fake -f my_fakefile", the parameter:"fakefile" should expand into "-f my_fakefile" but is instead expanding into "-fmy_fakefile".
For security reasons, the expanded paths, such as parameter:"top", should always have a trailing slash.
Consider "rm -Rf parameter:"top"tmp" vs "rm -Rf parameter:"top"/tmp".
On the left side, if parameter:"top" resolves into an empty string, then the command is: "rm -Rf tmp".
On the right side, if parameter:"top" resolves into an empty string, then the command is: "rm -Rf /tmp".
The right side would end up destroying a path outside of the project root, such as "/tmp"!
Kevin Day [Sun, 17 Jul 2022 03:09:09 +0000 (22:09 -0500)]
Update: Add support for +E/++error, change '+q' to '+Q', and fix some past tense words.
Selecting a quiet mode that still prints errors is very helpful in embedded fakefiles inside of controller rules.
I noticed that almost all of the verbosity related parameters are upper case except for the "quiet" parameter.
Change the "quiet" parameter from "+q" to "+Q".
I noticed some words in the past tense.
The goal is to use present tense.
Using past tense a habit I hope to get out of when programming.
There parameters are not always expanding properly resulting in the parameter being empty, having the incorrect order, or being improperly merged with another parameter.
Change the array resize behavior to resize after incrementing the arguments rather than before.
Detect and handle special cases where separation needs to be applied and when separation does not need to be applied.
Remove random space that is being accidentally appended when printing arguments (probably an accident from a previous commit).
settings:
parameter a iki <-assure_space unassure_space->
parameter b value
main:
if exist 'parameter:"a"'
print yes (parameter:"a")
else
print no (parameter:"a")
print 0 parameter:"a"
print 1 parameter:"b"
print 2 parameter:"b".
print 3 "parameter:"b""
print 4 "parameter:"b\" between parameter:"b""
print 5 'begin parameter:"a" middle parameter:"a" end'
print 6 "begin parameter:"a\" middle parameter:"a\" end"
print 7 begin parameter:"a" middle parameter:"a" end
print 8 begin parameter:"a"! middle parameter:"a"@parameter:"a" end
Should produce results like:
no (iki <-assure_space unassure_space->)
0 iki <-assure_space unassure_space->
1 value
2 value.
3 value
4 value between value
5 begin iki <-assure_space unassure_space-> middle iki <-assure_space unassure_space-> end
6 begin iki <-assure_space unassure_space-> middle iki <-assure_space unassure_space-> end
7 begin iki <-assure_space unassure_space-> middle iki <-assure_space unassure_space-> end
8 begin iki <-assure_space unassure_space->! middle iki <-assure_space unassure_space->@iki <-assure_space unassure_space-> end
Move the relevant arguments and iki data into a shared cache to save memory consumption.
Rename path_cache to cache_path for consistency.
Kevin Day [Fri, 15 Jul 2022 04:27:43 +0000 (23:27 -0500)]
Bugfix: Single quotes are not being properly detected in FSS Extended Read functions.
A copy and paste mistake where f_fss_quote_type_double_e when instead f_fss_quote_type_single_e should be used resulted in the quote being set to NULL.
Kevin Day [Thu, 14 Jul 2022 02:05:08 +0000 (21:05 -0500)]
Update: Change "exists" to "exist" in fakefile syntax.
The use of "exists" is grammatically correct and the use of "exist" is grammatically incorrect.
This is not in English grammar.
The practices of this project are to focus on using "s" strictly for plural.
The practices of this project are to use simple or base words more often.
The area in which proper grammar is allowed is when interacting with the user rather than with code.
A project like Fake has a target user who is a programmer.
This is a grey area.
The project is already using "if define" rather than "if defined".
For the purpose of keeping a consistent design, I am favoring "exist" over "exists" for this grey area.
Another bonus is that "exist" is shorter than "exists" (however trivial).
Kevin Day [Wed, 13 Jul 2022 23:19:21 +0000 (18:19 -0500)]
Update: Strip out NULL characters after applying delimits.
Once a rule is read and the IKI data is parsed, apply the IKI delimits.
NULL characters replace the delimits.
Strip out all NULL characters from the string after the delimits are applied.
Kevin Day [Wed, 13 Jul 2022 12:05:32 +0000 (07:05 -0500)]
Bugfix: Delimits are not being applied for IKI variables.
The controller program is not applying the delimits for would-be-valid IKI variables.
This becomes a huge problem when these would-be-valid IKI variables are passed to the fake program.
If the would-be-valid IKI variables are properly delimited, then the fake program would see them as valid IKI variables.
Kevin Day [Wed, 13 Jul 2022 12:01:39 +0000 (07:01 -0500)]
Bugfix: IKI variables are incorrectly being processed when there is a non-IKI IKI-like string.
The delimits, after the first, are not being processed.
This is the result of an accidental double increment.
When checking against a possible IKI variable and it is determined that the string cannot be an IKI variable, a double increment occurs.
What is happening is that the break statement only breaks out of the immediate loop.
There is a second loop that does an increment is not being broken out of.
Utilize the separator_found boolean to determine whether or not to perform the additional break.
Kevin Day [Mon, 11 Jul 2022 02:45:33 +0000 (21:45 -0500)]
Security: Invalid read for formatted printing using partial ranges on a string.
If the start position is greater than the used buffer, then an invalid read occurs.
Properly verify that the start position is not greater than or equal to the used length of the string.
Kevin Day [Sun, 10 Jul 2022 22:26:42 +0000 (17:26 -0500)]
Cleanup: Converted type is actually uint32_t rather than f_utf_char_t.
The f_utf_char_t is supposed to be an uint32_t so this is not a problem.
The intent and design of this, however, is that f_utf_char_t is a special case representing the character as a string rather than as a digit.
The f_utf_char_t is stored as a 4-byte integer to store each byte representing a character.
The uint32_t is simply a straight up 4-byte integer.
This is the numeric value of the code point rather than the representation as a string.
This is an important semantic difference.
Kevin Day [Sun, 10 Jul 2022 22:10:52 +0000 (17:10 -0500)]
Feature: The featureless make program now supports the "write" operation.
This is an oversight on my part.
There should be an operation to write to a file.
There are two forms of this new "write" operation.
1) Truncate a file (deletes all data within a file).
2) Append to a file.
A file is created if it does not already exist in both cases.
The "write" operation supports some standard escape sequences as well as some non-standard ones.
Standard Escape Sequences:
- "\f": Form Feed.
- "\n": New Line.
- "\r": Carriage Return.
- "\t": Tab.
- "\v": Vertical Tab.
- "\\": Backslash Character (may require additional slashes in certain circumstances.)
- "\0": NULL Character.
Non-Standard Escape Sequences:
- "\U+": Unicode Sequence (followed by a valid Unicode sequence with a minimum 4 hexidecimal digits and a maximum of 6 hexidecimal digits).
- "\U-": Terminate a Unicode Sequence, allowing for "\U+000A\U-5" to be equivalent to "\n5".
Kevin Day [Sun, 10 Jul 2022 05:45:05 +0000 (00:45 -0500)]
Bugfix: Incorrect information is printed on certain errors.
Remove unused line variable.
The f_fss_count_lines() function appends to the calculated length variable.
The number is not being reset.
This results in each iteration adding to the previous:
Line number 1, count = 1.
Line number 2, count = 3.
Line number 3, count = 6.
etc...
Reset the line number on each pass of the loop to get the correct line number.
An error message is printing "1" when it should be printing "2".
The "%Q" should be used instead of "%s" for the static string.
Replace "parameter" with "Content" to be consistent with other error messages.
Kevin Day [Sun, 10 Jul 2022 02:52:07 +0000 (21:52 -0500)]
Refactor: "if defined" and "if not defined" to be easier to use in fake program.
Using "if not defined parameter work" can be confusing.
Using "if not parameter work" is shorter and easier to understand.
Using "if defined environment PATH" can be very confusing.
Using "if define PATH" is shorter and a lot easier to understand.
Break apart the "if defined" (and "if not defined") logic into two operations:
1) "if define" (and "if not define").
2) "if parameter" (and "if not parameter").
This makes the behavior easier to understand as it directly maps to the "defined" and "parameter" settings.
Kevin Day [Sat, 9 Jul 2022 22:59:59 +0000 (17:59 -0500)]
Update: Use "settings" instead of "setting" for better consistency between fake program and controller program.
Featureless Make is using "settings" and the Controller program is using "setting".
Fix this inconsistency.
The term "settings" sounds more accurate than "setting".
Kevin Day [Sat, 9 Jul 2022 22:44:24 +0000 (17:44 -0500)]
Update: Restrict environment to PATH and LD_LIBRARY_PATH by default.
Change all of the setting files and fakefiles to restrict the environment variables.
Only PATH and LD_LIBRARY_PATH are exposed so that custom build environments can easily be used by default.
Kevin Day [Sat, 9 Jul 2022 22:02:15 +0000 (17:02 -0500)]
Update: Make environment variable handling design consistent between fake and controller programs.
The Featureless Make system does not have a way of passing all environment variables.
Add a flag to designate whether or not environments is empty because it is not defined or is empty because it is defined as empty just like the controller program does.
This then allows for more flexible control over whether or not the environment variable security.
Update the example setting files and fakefiles to expose PATH and LD_LIBRARY_PATH by default.
Kevin Day [Sat, 9 Jul 2022 04:58:16 +0000 (23:58 -0500)]
Bugfix: Condition blocks are still being processed when they should be skipped.
Re-design the block code to simplify the logic and make the code more readable.
This is only a partial re-design.
I did not perform an extensive review.
I am considering writing some runtime/program tests to better catch problems and regressions.
Kevin Day [Tue, 5 Jul 2022 13:47:27 +0000 (08:47 -0500)]
Update: Change default controller settings path to './'.
This feels more natural to me now that I am writing and testing the controller settings.
I originally wanted the default to be self contained.
If I want to run in a sub-directory such as 'controller/', then just pass '-s controller'.
Kevin Day [Tue, 5 Jul 2022 13:43:31 +0000 (08:43 -0500)]
Refactor: Rename "script" setting to "engine".
The scripting engine is now called "engine".
This fixes ambiguity issues between the "script" action and the scripting engine.
This makes the code and configuration files easier to read and understand.
Kevin Day [Tue, 5 Jul 2022 01:17:48 +0000 (20:17 -0500)]
Feature: The fake progam is supposed to support a piped fakefile.
I thought I implemented this already.
I just tried to use it and found it that I had not implemented.
This feature is supposed to be in the stable release.
Kevin Day [Sat, 2 Jul 2022 03:28:42 +0000 (22:28 -0500)]
Update: Improve design in f_conversion to be safer when handling variables allowed to be replaced.
The constants are allowed (and encouraged) to be changed as desired by some developer or distributor.
This means constant strings like f_string_ascii_1_s could, in theory, be any length.
Change the do..while loops into normal while loops.
Change the while loop using sizeof(f_char_t) to instead use the actual constant string structure(via a pointer).
This situations was identified by the -fanalyzer functionality of GCC-12.1.
The -fanalyzer from earlier GCC versions, such as GCC 11, did not identify this.
The sizeof(f_char_t) is not strictly needed for the fwrite_unlocked() calls because they are wrapped in a loop.
The sizeof(f_char_t) can be assumed to be 1 in general and even if it is greater than 1, the loop will still ensure success.
Removing the sizeof(f_char_t) simplifies the design.
Kevin Day [Fri, 1 Jul 2022 22:22:05 +0000 (17:22 -0500)]
Update: Example bootstrap script now supports building all programs.
Looping over all programs, building them, and installing them is a very common process.
Adding support for this to the example bootstrap script should save me some time and effort.
Also change the separate clean and build commands into a single command using the rebuild command.
Kevin Day [Fri, 1 Jul 2022 05:32:38 +0000 (00:32 -0500)]
Bugfix: Problems exposed by f_thread unit tests.
Notable fixes:
- Rename f_thread_semaphore_file_create() to f_thread_semaphore_file_open().
- Rename f_thread_semaphore_file_delete() to f_thread_semaphore_file_close().
- Rename f_thread_semaphore_file_destroy() to f_thread_semaphore_file_delete().
- Have f_thread_semaphore_file_open() accept a double pointer for semaphore because sem_open() returns a pointer.
- Initializer f_thread_semaphore_t_initialize is on a union which is initialized differently from a normal digit.
Kevin Day [Wed, 29 Jun 2022 22:10:19 +0000 (17:10 -0500)]
Update: The featureless make should default to 'make' mode.
This makes the fake program closer to how make operations.
With this changed, just type 'fake' and it operates as if 'fake make' was the command given.
Kevin Day [Sat, 25 Jun 2022 15:49:30 +0000 (10:49 -0500)]
Update: White space function changes.
Make the is white space functions accept "strict" to be more consistent with how other functions operation.
For the next development release I want to consider separate functions to avoid passing a boolean as a parameter to do this (for performance reasons).
This changes behavior in some cases and if I did something wrong then there will be a regression.
Look out for white space regressions specifically in the FSS programs.
Kevin Day [Sat, 25 Jun 2022 05:00:37 +0000 (00:00 -0500)]
Update: Use "decimal" instead of "digit".
The unit tests are failing because the function no longer exists.
The use if "digit" is probably the result of an over zealous refactor.
Rename the affected functions back to "decimal".
Kevin Day [Sat, 25 Jun 2022 04:09:26 +0000 (23:09 -0500)]
Bugfix: Problems in f_utf exposed by unit tests.
The is alphabetic needs to perform the is valid check because its default catch-all is returning F_true.
Ideally at some point (probably distant point) in the future, the literal codes for alphabetic will be matched rather than calling all of the other functions.
In this situation the is valid check can be removed.
Several of the is digit test value assignments are not checking if the value (the pointer) is NULL.
Kevin Day [Thu, 23 Jun 2022 23:52:19 +0000 (18:52 -0500)]
Update: The fake program should check file existence when clean is combined with another command like build or make.
When the make or build command is specified after a clean command, the clean command should do an appropriate file dependency check.
This acts as a safety measure such that if the make or build command could not normally be run due to the missing required files, then the clean operation should not be run.
Kevin Day [Wed, 22 Jun 2022 04:19:36 +0000 (23:19 -0500)]
Progress: f_utf unit tests and make significant change Unicode digit/decimal functions.
The controller program is using f_utf_is_alphabetic_decimal().
The previous functionality of that function is now handled by f_utf_is_alphabetic_digit().
I reconsidered some of the design I implemented in the previous commit (e696e3941592c6910f2f8ecc87a698d4f618c3b4).
The design of reading the value for the variable "value" and then saving to it is too much complexity.
Simplify the design and just expect the caller to read the "value" and decide if it is or is not in range.
Get rid of the "*_is_decimal()" functions.
The "*_is_digit()" functions work like the "*_is_decimal()" functions did.
I am avoiding the term "decimal" because it refers to base-10.
The term "digit" is a bit more general.
The only downside is that fractions might fall under "digit" (really they are two digits), which this function currently does not handle.
The "*_is_numeric()" functions will recognize fractions.
I didn't get as far as I wanted to.
The number of Unicode values to assign has worn me down.
The tests processing is not complete and I haven't gone back and done my normal review.
I tried to keep the "value" as small as possible, but unsurprisingly some language out there has a digit that represents billions.
I am forced to use a 64-bit data type for this.
Kevin Day [Tue, 21 Jun 2022 00:26:53 +0000 (19:26 -0500)]
Update: The f_utf project regarding digits and perform other clean ups follow up.
I had not gotten around to testing the programs after the previous commit.
I did not get to writing the function f_utf_is_alphabetic_digit() (and then forgot about this important part).
The controller program is using f_utf_is_alphabetic_decimal().
The previous functionality of that function is now handled by f_utf_is_alphabetic_digit().
Kevin Day [Mon, 20 Jun 2022 04:42:18 +0000 (23:42 -0500)]
Update: The f_utf project regarding digits and perform other clean ups.
Redesign the digit and decimal behavior.
The is digit functions now refers to base-10 but does not attempt to return the identified digit.
The is decimal functions now refers to base-10 and supports providing the identified digit.
The is decimal functions also support other base units than just base-10.
The alphabetic digit/numeric functions now also have a alphebetic decimal function.
Clean up more places in the code using "sequence" rather than "character" or "characters".
Functions like f_utf_character_is_alpha_digit() are now like f_utf_character_is_alphabetic_digit().
Add related unit tests.
The is digit functions have unit tests that tests if the digit returned is correct.
I have not reviewed all of the "numeric" Unicode digits to confirm/deny that my is decimal functions are complete.
I observed what looks like bugs in the alphabetic functions.
In these cases the final return statement is returning F_false when they instead should be returning F_true.
Kevin Day [Sun, 19 Jun 2022 00:22:56 +0000 (19:22 -0500)]
Security: Floating point exception due to incorrect number type used in conversion function.
The power is being used as the entire value.
To do this it must be capable of holding the entire supported digits of f_number_unsigned_t.
Using int results in a floating point exception.
Kevin Day [Sat, 18 Jun 2022 23:50:38 +0000 (18:50 -0500)]
Bugfix: The byte_dump --first and --last are not always working as expected.
The problem is due to a calculation resulting in a negative value.
The code "width_utf == -1 ? 0 : width_utf - width_count" does not account for when width_count > width_utf.
Refactor the use of "characters" with "sequence" to reflect recent changes in terminology usage.
Kevin Day [Sat, 18 Jun 2022 22:28:32 +0000 (17:28 -0500)]
Update: Follow up previous Unicode changes.
The previous commit changed a significant amount of behavior.
That commit noted that follow up changes would be necessary.
First things first.
I noticed that when I simplified the is valid checks I ended up over simplifying them.
There are several byte sequences that are not valid UTF-8 sequences.
I previously added surrogates and it turns out that UTF-8 specifically does not support Unicode surrogates.
Remove all related code.
The f_utf_char_t is supposed to be in big-endian format.
The macros are fixed to properly handle this.
This fix exposed problems in the conversion functions.
The conversion functions lack the proper big-endian and little-endian support.
Introduce a new structure and parameters to support designating the big-endian and little-endian.
Support a default order to host byte order.
The utf8 program needs to properly handle the endianness in a different way.
The bytes are in left-to-right format but when converted are converted in a left-to-right format but shifted to the right.
Swapping between little-endian to big-endian would be incorrect because the byte order is aleady correct.
The byte position is what is incorrect.
That is 0x0000c280 should be shifted to 0xc2800000.
Swapping the endianness would instead yield 0x80c20000 (which is incorrect).
The use of the word "character" as a variable name and in documentation can be confusing.
I have recently defined a "byte sequence", a "code point", and a "unicode" as specific types.
Change the word "character" to the appropriate name to make the code less confusing and more specific.
There are also other words used in place of "character" that might not be the ones listed above.
Some of the tests, particularly the emoji tests, have incorrect data.
I discovered that many sources out on the internet violate the standard and call code points an emoji that are not official recognized as an emoji by the standard.
I'm going with wikipedia on the new and updated emoji list.
The f_char_t is available so update old code that still uses uint8_t to instead use f_char_t for character related data.
Changes to the is valid code resulted in identifying invalid byte sequences that were previously considered valid.
Kevin Day [Fri, 17 Jun 2022 03:56:34 +0000 (22:56 -0500)]
Update: Unit tests for f_utf and relating changes or bug fixes.
Fix several problems exposed by unit tests.
Fix several unit tests to work as expected due to problems with the data files.
At some point I seem to have diverged from always ensuring that the f_utf_char_t is always big-endian.
I probably got lost in ensuring the differences between big and little endian that I ended up making the f_utf_char_t act little-endian in cases where host is little-endian.
The f_utf_char_t must always be big-endian.
However, there are cases where the big and little endian behavior must be processed.
Break up the macros into having "_be" and "_le" to make this possible.
The iscntrl() check return value needs to be explicitly handled to ensure that only F_false or F_true is returned.
This is already fixed in one function already.
Apply the existing fix to the other function.
The f_utf_char_t should be seen as a single character rather than a stream of bytes.
Unit tests now treat any non-zero value after the designated width as invalid.
The is valid checking code now tests for this invalid case.
The unit tests are improved.
Test for F_true and F_false rather than calling assert_true() and assert_false().
Error bits and other status codes were previously passing when they should fail due to the use of assert_true() and assert_false().
This commit changes the byte order of the f_utf_char_t.
This will break code such as the code used in the utf8 program.
A follow up commit is necessary to fix any byte order problems.
Kevin Day [Tue, 14 Jun 2022 12:25:18 +0000 (07:25 -0500)]
Update: Add unit tests in f_utf project.
These tests are created based on the comments in the code.
Unlike previous tests, I reviewed the Unicode database separate of my code.
This approach is faster but will not expose any Unicode Codepoints that I missed when writing the code.
This adds tests for the following:
- combining
- phonetic
- subscript
- superscript
- wide
Kevin Day [Tue, 14 Jun 2022 00:02:51 +0000 (19:02 -0500)]
Update: Add some unit tests for f_utf.
Add the structure for the remaining tests.
The (currently) unused tests are just copy and pastes and may need changes.
With the exception of the "valid" tests, these unit tests use statically generated data files containing bytesequences (unsigned 32-bit) in base-10 format.
The base-10 format representation of the bytesequence is used for easy reading using standard libc functions.
These static data files are generated using a combination of the Unicode database codepoints, a script I wrote, and the "unicode" program.
The Unicode codepoints used for each generated bytesequence set are also provided.
This implements the following tests:
- control
- digit
- emoji
- symbol
- valid
The intent of this is to test the entire spectrum of valid codepoints (except for the "valid" tests which tests every single possible value).
Due to every single value being tested by "valid" tests for both f_utf_is_valid() and f_utf_character_is_valid() results in a long running test.
Kevin Day [Sun, 12 Jun 2022 04:23:37 +0000 (23:23 -0500)]
Update: Add script for generating Unicode Codepoints from integers.
A simple script that I am using for generating a range of Unicode Codepoints in the format needed by the generate_unicode.sh script.
The private use area is represented by multiple sets of all values within some range.
These ranges are a massive list.
This script generates these.
The only thing I need to do is use a calculator program to convert hex to integer.
These integers are then passed to the script as an inclusive range.