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

Make sure argv indeces exist before comparing them in test_lfs.c and test_time.c #91

Closed
wants to merge 1 commit into from

Conversation

amberjennings
Copy link

@amberjennings amberjennings commented Apr 18, 2024

This should resolve issue #89

  • Ensures that argv values exist before attempting to strcmp them to operations
  • This is far from a perfect solution -- in the future, it would be good to have this checking happen before anything else is done.

Copy link
Member

@dmitri-mcguckin dmitri-mcguckin left a comment

Choose a reason for hiding this comment

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

Left a suggestion to consider.

Also- this is 100% not your fault as we need to still set up a lot of the guidance and procedures for what we'd eventually like to see in PR's.

But just to get started- PR's are much more friendly to the reviewer if you:

  1. Describe (just a short summary with link to applicable issues) what the PR is for.
  2. If there's anything un-intuitive happening in the code, describe the design and your thought process behind the design (make sure your code is sound, in general).
  3. Prescribe whether or not your code is polished. It's ok if it's not, just list out things that ought to be done in future refactors and/or make those issue for tracking.

time_t unix_time = rtcGetTimeUnix(&msec);
char *timestr = ctime(&unix_time);
chprintf(chp, "UNIX Time: %d\r\n"
"Date: %s\r\n",
unix_time, timestr);
} else if (!strcmp(argv[1], "set") && argc > 2) {
} else if (argv[1] != NULL && !strcmp(argv[1], "set") && argc > 2) {
Copy link
Member

Choose a reason for hiding this comment

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

In this (and similar) situations this actually creates a new subtle bug. You're checking if the value at the location is zero'ed out- which sometimes will be true- sometimes wont. This also assumes that this is in-bounds.

Me thinks it would be better to check against argc and ensure it is greater than or equal to the current spot you are trying to deference.

For example: argv[0] is technically always a valid pointer, but it's also a de-reference operation that's not guaranteed to work if the array was never allocated, or not allocated with the size you assume. This code would break if we simply passed no args to this tool.

Copy link
Author

Choose a reason for hiding this comment

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

I've updated the description for now, will make it more detailed ASAP. Will also make this conditional/similar more sturdy, likely today or tomorrow.
Thanks!

@dmitri-mcguckin dmitri-mcguckin added the bug Something isn't working label Apr 18, 2024
@amberjennings amberjennings marked this pull request as draft April 18, 2024 21:42
@ryanpdx
Copy link
Member

ryanpdx commented Jul 14, 2024

With #99 are we dropping support for F4 apps, so this is no longer needed

@amberjennings amberjennings deleted the amber-89 branch September 23, 2024 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants