Kevin Day [Mon, 14 Mar 2022 03:10:17 +0000 (22:10 -0500)]
Update: Consistency improvements with *_append() and *_append_all(), add tests, and other clean ups.
The array functions for managing structures needs to be consistent with the *_append() functions.
This introduces the *_append() all across the board.
The previous *_append() behavior is essentially refactored into *_append_all().
The *_append() now accepts a single type for a given structure rather than a set.
(The single type can still be representative of a set itself.)
Add a lot of tests.
Add missing f_iki tests.
The f_string tests are not fully implemented, the f_dynamic_* functions are only partially tested.
All of the other f_string structures should be fully tested now.
Make the macro_f_string_range_t_initialize() macro consistency with all other macros.
That is, the macro initialize that does not have a digit initializes using all of the structures members.
This effectively refactors macro_f_string_range_t_initialize() into macro_f_string_range_t_initialize2() and macro_f_string_range_t_initialize2() into macro_f_string_range_t_initialize().
Change the behavior of the *_resize() and *_adjust() functions to return F_none rather than a direct f_memory status code.
Update some of the string functions to return F_data_not_eos.
Restructure some of the code to be a bit more organized.
Specifically, the f_iki_data_t is moved into its own source and header files.
Reduce the clutter in some of the private source and header files by moving some of their content into separate individual files as appropriate.
Kevin Day [Thu, 10 Mar 2022 04:51:29 +0000 (22:51 -0600)]
Progress: Controller and Control sockets.
This also adds a new FSS: FSS-000F (Simple Packet).
I decided that this needs its own specific specification to represent it.
This further helps make it clear that a Packet is not the same as a Payload.
There can still be some confusion because the FSS-000F (Simple Packet) has a Payload Block.
That Payload Block contains the FSS-000E (Payload).
That FSS-000E (Payload) has a Payload section within itself.
This means that there are three different, but very similar (and also related), contexts used for a "payload".
To try and avoid this, I refer to the payload in FSS-000F (Simple Packet) as the Payload Block.
I refer to the payload in the specifications as the FSS Payload or the FSS-000E (Payload).
I refer to the payload within the FSS-000F (Simple Packet) as the Payload Object, the Payload Content, or the payload section.
Kevin Day [Wed, 9 Mar 2022 05:10:08 +0000 (23:10 -0600)]
Update: Revert back to 'char' rather than 'unsigned char'.
There are a lot more changes that I realized.
changing 'char' to 'unsigned char' will be for the next development release after the upcoming stable release.
Introduce the f_char_t type to allow for easier switching from 'char' to 'unsigned char'.
In all places that us 'unsigned char', just switch to 'char'.
Move the directory '..' and '.' into static strings.
Kevin Day [Tue, 8 Mar 2022 03:46:17 +0000 (21:46 -0600)]
Update: Switch to explicitly using sizeof() for char memset() and memcpy().
Different architectures might not actually have a 1-byte size.
Rather than assuming the common behavior, always call sizeof(unsigned char) to determine size of memset() and mempcy() functions.
Kevin Day [Tue, 8 Mar 2022 03:12:18 +0000 (21:12 -0600)]
Update: Avoid the generic 'char' and switch to the explicit 'unsigned char'.
Operations against unsigned are generally safer than the signed equivalents.
Using the generic 'char' may be different between compilers and expecations cannot be guaranteed.
This could result in obscure security issues.
Changing this to 'unsigned char' guarantees consistent behavior.
There are problems with some standard libc functions that expect char.
Explicitly cast to 'char' in these cases.
Kevin Day [Sun, 6 Mar 2022 22:56:52 +0000 (16:56 -0600)]
Progress: Implement controller to/from control networking.
Continue implementing the contoller to control communication.
I thought I described the packet structures in addition to the payload structure.
It seems I have not.
This begins adding the packet structure documentation.
Kevin Day [Sat, 5 Mar 2022 19:00:13 +0000 (13:00 -0600)]
Update: Provide open-standard-license-1.0.
The Open Standard License is a more formal definition of my original intents and license behind my Standards and Specifications provided in this project.
This standard is still considered an Informal Draft because I have yet to perform legal review and as such it is considered incomplete.
This standard will be formalized pending legal advice and even the name is subject to change.
I thought that there might be confusion between the LGPL license in this project (which focuses on Source Code) and the Standards and Specifications provided within this project.
To make this difference explicitly clear, I am in the process of formalizing the license.
One big important part of this is this license focuses on Implementations of the Standard or Specification.
This is a substantially different concept to what is used in the LGPL and similar licenses.
Kevin Day [Wed, 2 Mar 2022 05:51:29 +0000 (23:51 -0600)]
Update: Add test mode and provide -fstack-protector flag.
The recently added Github action for running tests is failing due to a stack overflow bug.
Compile with ssp explicitly enabled during testing to help better identify these cases.
The problem has not yet been identified and does not reproduce locally.
More investigation on that is be required.
This overflow happens while executing the cmocka based test.
There is the possibility that the overflow is in cmocka or as a result of how I am using cmocka.
Kevin Day [Tue, 1 Mar 2022 04:24:16 +0000 (22:24 -0600)]
Cleanup: Scripts syntax and styles.
The primary focus is on fixing the uppercase letters for the error and warning statements to follow proper sentence structure.
Other clean ups are incidental.
Kevin Day [Tue, 1 Mar 2022 02:49:52 +0000 (20:49 -0600)]
Regression: Some IKI vocabularies are missing their first character.
The previous bugfix (4f0c01eb) failed to check for additional problems introduced by the changes.
I should focus on writing unit tests for fl_read() shortly.
Kevin Day [Tue, 1 Mar 2022 00:49:51 +0000 (18:49 -0600)]
Update: Socket parameters, rename f_socket_bind_file() to f_socket_bind_local(), and return F_local_not when UNIX socket is required.
Make the f_socket_t passed to the f_socket_bind() and f_socket_bind_file() a pointer constant.
Use the f_socket_bind_local() rather than f_socket_bind_file() to better communicate that this is a local (UNIX) socket.
The f_socket_bind_local() requires the socket to be a local (UNIX) socket, so return F_local_not (with error bit) if it is not a local (UNIX) socket.
Kevin Day [Sun, 27 Feb 2022 01:33:59 +0000 (19:33 -0600)]
Bugfix: A Rule's "define" settings are not being exported.
The exporting of the define is never performed and needs to be.
This is a quick implementation.
I've added a TODO describing what I really want to do.
The improved implementation is to be addressed after the FLL-0.5.8 release.
Kevin Day [Sun, 27 Feb 2022 01:31:19 +0000 (19:31 -0600)]
Feature: Maps and Multi-Maps should support appending a single map rather than just an entire set.
This is really an oversight on my part.
The append should by default append a single item.
To append an entire set, a new function should be used (an append all function).
This should be done for all of the string types that are applicable.
Such changes are left for the next release and are not planed for the 0.5.8 release.
This functionality is necessary for bug fixes in the controller program.
Kevin Day [Sun, 27 Feb 2022 00:31:48 +0000 (18:31 -0600)]
Feature: Implement IKI support in controller program.
The functionality is designed to mimic some of the design used in Featureless Make in regards to IKI variables.
There are now "define", "parameter", and "program" IKI vocabularies available.
The "program" should probably have some sort of security property in an Entry to restrict its use.
There is a likelyhood of some design not wanting to expose the program parameters to the Rule.
I may also want to implement a "time" vocabulary in the future (likely to happen no sooner than FLL-0.5.0).
It appears that the define environment variables are not being exported as expected.
This is either an existing bug or a problem in the new feature.
Having reviewed this, I suspect that the problem is in the existing design.
A follow up commit will address this issue.
The --simulate and --test displays any loaded IKI variables.
Kevin Day [Sat, 26 Feb 2022 22:21:04 +0000 (16:21 -0600)]
Update: Delete socket rather than resize when array is over large.
I realized that this might be more performant.
If I have to resize the array because it is over large, then a resize could result in a copy of memory.
At this point in the program, the data is irrelevant.
I suspect deleting the array will perform better than resizing the array to a smaller size.
Kevin Day [Sat, 26 Feb 2022 17:20:01 +0000 (11:20 -0600)]
Security: Invalid va_arg() call resulting in overflow.
This overflow doesn't seem to cause crashes, which is even scarier as has gotten away with unnoticed.
The else condition inside of the formatted print functions are accidentally declaring va_arg() when it shouldn't.
The except_at and except_in are also being unnecessarily declared.
Kevin Day [Sat, 26 Feb 2022 16:50:26 +0000 (10:50 -0600)]
Security: The va_list has undefined behavior when passed into functions.
When the va_list is started using va_start(), the va_arg() must be called within the same function.
This is a design problem with how va_list and its respective functions are implemented.
The man pages directly document that passing an already started va_list to a function and then calling va_arg() is undefined.
The va_list, being a macro, might also be a pointer.
This makes passing it as a pointer (or with "const") risky.
Due to the mentioned undefined states and risks, this is considered and treated as a security issue.
Move the va_XXX() logic into a single function.
This unfortunately means some functions have to be expanded out into the code and deleted.
The code now, unfortunately, has more nested as a result of having to add more loops within the same function.
The va_copy() macro is used and so the ap list state is no longer changed outside of the function.
Kevin Day [Sat, 26 Feb 2022 05:04:47 +0000 (23:04 -0600)]
Bugfix: Improper IKI vocabulary position for when a quote is immediately to the left of the vocabulary name.
I distantly remember attempting to shorthand and optimize the logic to reduce the while loop usage.
This appears to have backfired in that I missed one of the possible conditions.
An example of this is the following bash command utilizing IKI substitution:
echo "IKI Path is 'define:"PATH"'"
In the aboce string, the bug is claining the IKI variable is "'define".
The quote is not a word charcter, not a dash, and not a plus.
The IKI vocabulary is supposed to be "define".
Redesign this back to have the multiple loops.
While this is messier, it should be harder to make a logic mistake.
Cleanup some of the logic to not need the private_f_iki_seek_special() function.
Make sure the width is always calculated prior to calling the UTF aware string functions.
Update wording in iki.txt specification to make a little more sense.
Kevin Day [Sat, 26 Feb 2022 04:58:24 +0000 (22:58 -0600)]
Bugfix: private_fl_print_convert_number() problems and do some cleanup.
The private_fl_print_convert_number() function stops either on non-diit, asterisk, or NULL.
The code is subtracting 1 from the string position.
This allows for the subsequent continue and resulting string increment to not overflow the buffer.
The problem happens when the stop position is a non-digit.
This non-digit is effectivly being skipped by this logic.
Change the logic to always return a position that will allow the subsequent increment without modification.
The position at function exit must never be pointing at NULL.
The position at function exit must never be pointing at a non-digit.
Use "++string" instead of "string += 1".
Change the structure to order from 8, 16, 32, 64, and 128.
Kevin Day [Sat, 26 Feb 2022 03:45:37 +0000 (21:45 -0600)]
Bugfix: Improper if condition range check.
This is supposed to check the start and stop range, but accidentally checks the start range on both side.
This mistake appears to have been copy pasted quite a few times.
Kevin Day [Fri, 25 Feb 2022 04:10:04 +0000 (22:10 -0600)]
Update: Return F_data_not when amount or size is 0 in memory allocation functions and add missing F_string_tripless_t.
Return F_data_not rather than return F_parameter (with error bit set).
This allows for more possibilities where a set of data may be calculated without worrying about an error that is not really an error.
If you want to allocate nothing, then nothing is allocated (and the same for deallocated).
The resize and adjust functions still use a length of 0 as synonymous to deleting the data.
The array of an array of F_triple_t is no longer missing.
All appropriate allocation functions are defined.
Kevin Day [Wed, 23 Feb 2022 04:04:15 +0000 (22:04 -0600)]
Update: IKI Improvements and some cleanups.
The _di_X_t_ where "X" is something like f_fss_object, is missing the leading "f_" in several cases.
Make the *_increase() step variable an f_array_length_t.
Rather than trying to optimize, just guarantee whatever step size is desired is available.
Move the iki_read programs practice of defining an iki_data_t structure into the level_0 iki project.
This then allows simplifying the arguments passed to the iki read functions.
Kevin Day [Mon, 21 Feb 2022 01:52:21 +0000 (19:52 -0600)]
Update: Controller and control.
Fix bug in control where parameter should be "settings" and not "socket".
The controller can now detect the current path and provide a canonical relative path only for paths whose actual canonical path is within the current working directory that the controller program started in.
Fix printing of the help in the controller program (missing slashes).
Don't create socket and pid files when running validate and simulate.
When running simulate, still create the pid and socket files as appropriate.
Add new entry setting to allow explicitly setting the pid file path.
Remove no longer necessary functions that ensure terminating NULL.
The recent changes in the string functions now guarantee this.
Remove a lot of todo comments.
I will either get to them or not.
I plan on getting to writing IKI support.
It needs to happen and I can use the Fake program as an example.
Kevin Day [Sun, 20 Feb 2022 06:48:32 +0000 (00:48 -0600)]
Update: Make sure constant pointers that are intended to be read-only are just that.
I often read "const char *name" as a constant pointer.
This is strictly incorrect.
This actual means that this is a pointer to a constant character.
Mass change the pointers to constants that are intended to be themselves constant.
This is changed via a regex and test to compile and run.
I'm not sure if there are any problems with this change but everything seems fine.
This new code looks more awkward but is strictly correct.
Now "const char * const name" represents a constant pointer to a constant string.
This makes the parameter a constant and still allows for the pointer to point to a constant variable.
Kevin Day [Sun, 20 Feb 2022 00:36:52 +0000 (18:36 -0600)]
Progress: Continue mass converting to f_string_static_t and use const more.
In particular this separates the fl_conversion functions into two forms:
1) That accepts only the f_string_static_t and uses dynamic.used as the length.
2) That accepts both f_string_static_t and f_string_range_t and uses the range to determine the length.
This makes the conversion functions more consistent with the rest of the project's practices.
Kevin Day [Sat, 19 Feb 2022 13:45:44 +0000 (07:45 -0600)]
Update: Fakefile inner Objects should load the last Object from settings Section.
Use the last found Object for each name for Objects that support only a single value.
That is to say if there is:
load_build yes
load_build maybe
load_build no
Then the last load (whose value is "no") will be used.
No warnings will be thrown.
Objects that support multiple values will continue to append Content for each Object as they are found.
This does not change the "settings" and "main" Objects to match this behavior.
Those will remain as first specified is the first and only one processed and used.
This makes the behavior with the fakefile more consistent with the build settings.
Kevin Day [Sat, 19 Feb 2022 04:49:48 +0000 (22:49 -0600)]
Feature: Enable support for modes on (almost) all Fake build settings Objects.
The only ones that are now not supposed to support this are the "modes" and "modes_default" Objects.
It should now be possible to build against clang with a command like the following:
fake clean build -m monolithic -m clang
This is possible because of the "build_compiler-clang clang" and similar settings added to the build settings file in addition to the functionality added by this commit.
Kevin Day [Sat, 19 Feb 2022 02:10:16 +0000 (20:10 -0600)]
Security: Invalid reads, always add NULL for compatibility.
After switching from f_string_t to f_string_static_t, the NULL terminated string problem has become apparent.
If at any point in time these strings are passed to a standard function that expects NULL terminated strings, then an invalid read (or write) can occur.
Manually appending a NULL termination every time its needed has made the code messier than I would like.
This commit changes the behavior to instead always append a NULL termination after the string.used when appending strings.
I accept the additional resource cost of 1-byte per string to guarantee this.
This should make the program more easily more secure by catering to the NULL terminated string code out there.
This project still doesn't need the or care about NULL termination for most (but not all) of its functions.
Kevin Day [Fri, 18 Feb 2022 04:11:06 +0000 (22:11 -0600)]
Security: Executed program string is not NULL terminated.
While the FLL code doesn't need NULL termination, the C/POSIX execute functions are.
The lack of a NULL terminated results in an invalid read on execute.
Kevin Day [Thu, 17 Feb 2022 03:05:06 +0000 (21:05 -0600)]
Update: Console improvements with related security fix.
Add f_console_environment_process() to process environment variable data passed via main().
Add appropriate testing.
Setup all level 3 (programs) to have the environment data (envp).
The level 3 currently do not utilize this.
While looking at the tests, I realized that I noticed that I did not fully verify the sanity of the passed argc, argv, and now envp.
This is a security issue in that invalid data (argc could be wrong, argv could be NULL, etc..) could result in an invalid read.
Update the f_console_parameter_process() to verify the argc and argv data (f_console_parameter_process() doesn't utilize envp).
Improve tests to catch these potential problems.
Return F_data_not (without error bit) to represent that there is no argc, argv is NULL, or when argv[0] is NULL.
Change the previous F_data_not return to instead return F_complete_not (without error bit) to represent that all of the expected values were not found.
Update functions to use "const" after the asterisk representing the parameter pointer.
Kevin Day [Wed, 16 Feb 2022 05:37:15 +0000 (23:37 -0600)]
Refactor: Switch to a more directory based source file structure.
Mass change all of the code to further utilize directories.
The project has gotten big enough for this to matter.
The stable API should have a relatively clean directory structure.
Kevin Day [Tue, 15 Feb 2022 06:47:20 +0000 (00:47 -0600)]
Update: The build setting path_sources is not being properly used and improve skeleton process.
Resolve the fixme regarding the path_sources_object and similar.
Consolidate the static source build into functions.
The fake_build_setting_name_preserve_path_headers_s is in the wrong location, resulting in the incorrect loading of build settings data.
Provide default for path_sources.
Make the main->path_sources a prefix path where all sources exist (there will likely need to be a follow up commit to address this in bootstrap.sh).
Get rid of the path_source_* forr bash, c, and other custom paths.
Get rid of the redundant version default assignment in fake_build_load_setting_defaults().
Rename fake_build_load_setting_defaults() to fake_build_load_setting_override().
Kevin Day [Tue, 15 Feb 2022 03:24:44 +0000 (21:24 -0600)]
Refactor: Remove "_type" from f_type_array functions.
The f_type_array project is really just an exception case extension of f_type.
It's purpose is to provide the array functions for the associated array structures in f_type.
These cannot be stored in f_type due to circular dependency needs for the f_memory project.
I used f_type_* to prefix these functions but the inconsistency between the structure names has shown to be a problem.
Rename these functions to not have the "_type" within them.