Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

faulty intialization in spiffs_create_object #184

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

robert-b
Copy link

the pullrequest adds a simple shell script to run valgrind :-)
It also fixes:
==25336== Conditional jump or move depends on uninitialised value(s)
==25336== at 0x41220B: _write (test_spiffs.c:208)
==25336== by 0x40E993: spiffs_phys_wr (spiffs_cache.c:215)
==25336== by 0x405622: spiffs_object_append (spiffs_nucleus.c:1436)
==25336== by 0x40B141: spiffs_hydro_write (spiffs_hydrogen.c:450)
==25336== by 0x40B809: SPIFFS_write (spiffs_hydrogen.c:587)
==25336== by 0x41402A: test_create_and_write_file (test_spiffs.c:779)
==25336== by 0x415A8E: __test_lu_check1 (test_check.c:58)
==25336== by 0x428D4F: run_tests (testrunner.c:192)
==25336== by 0x411D08: main (main.c:9)
Which may cause sideeffects for various users ....
My memory overruns seems to be fixe - here I need just more testing to be shure.
Happy testing!

oix_hdr.p_hdr.obj_id = obj_id;
oix_hdr.p_hdr.span_ix = 0;
oix_hdr.p_hdr.flags = 0xff & ~(SPIFFS_PH_FLAG_FINAL | SPIFFS_PH_FLAG_INDEX | SPIFFS_PH_FLAG_USED);
oix_hdr.type = type;
oix_hdr.size = SPIFFS_UNDEFINED_LEN; // keep ones so we can update later without wasting this page
strncpy((char*)oix_hdr.name, (const char*)name, SPIFFS_OBJ_NAME_LEN);
strncpy((char*)oix_hdr.name, (const char*)name, len);
Copy link
Contributor

Choose a reason for hiding this comment

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

This no longer copies the null at the end (len is strlen of name). ALso, if you know the length, safer to use memcpy....

Copy link
Author

Choose a reason for hiding this comment

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

this is exactly what i wanted.
overwrites in oix_hdr should be prevented.
the null termination is done by:
spiffs_page_object_ix_header oix_hdr = {.p_hdr = {0}};

Copy link
Contributor

Choose a reason for hiding this comment

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

Please use memcpy then to indicate that you don't need the (rather obscure) behavior of strncpy.

Copy link
Author

Choose a reason for hiding this comment

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

'c' is pretty obscure :-)
i personaly like the behaviour of strncpy because it copies only bytes up to the length given.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah -- but that isn't what strncpy does that is magic!!

memcpy copies the exact number of bytes.
strlcpy copies the string but ensures that it doesn't overflow the destination and ensures that the destination is null terminated (by truncating the string if needed).
strncpy copies the string (up to the buffer size) and then null fills the rest of the destination buffer.

two tests did fail.
@valkuc
Copy link

valkuc commented Dec 1, 2017

Hi, please use one of SPIFFS_DBG/SPIFFS_GC_DBG/SPIFFS_CACHE_DBG/SPIFFS_CHECK_DBG macro for debug printing instead of direct call to printf

@robert-b
Copy link
Author

robert-b commented Dec 3, 2017

yes, can be done.
i am still debugging the software.

@@ -1250,7 +1250,7 @@ SUITE_TESTS(bug_tests)
ADD_TEST(fuzzer_found_1)
ADD_TEST(fuzzer_found_2)
ADD_TEST(fuzzer_found_3)
ADD_TEST(fuzzer_found_4)
// ADD_TEST(fuzzer_found_4)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this change?

Copy link
Author

Choose a reason for hiding this comment

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

you can re-enable the test.
got a problem with the the test and disabled it to run through the cremaining tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants