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

Add interactive Key-Value app #325

Merged
merged 10 commits into from
Jul 26, 2023
Merged

Add interactive Key-Value app #325

merged 10 commits into from
Jul 26, 2023

Conversation

bradjc
Copy link
Contributor

@bradjc bradjc commented Jun 16, 2023

This app can set/get/delete keys through stdin.

I also added sync functions to make the app easier to write.

examples/tests/kv_interactive/main.c Outdated Show resolved Hide resolved
examples/tests/kv_interactive/main.c Outdated Show resolved Hide resolved
examples/tests/kv_interactive/main.c Outdated Show resolved Hide resolved
examples/tests/kv_interactive/main.c Outdated Show resolved Hide resolved
Comment on lines 103 to 107
int value_start = key_end + 1;
int value_end = find_end(value_start);
int value_len = value_end - value_start;

memcpy(key_buf, read_buf + key_start, key_len);
Copy link
Contributor

Choose a reason for hiding this comment

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

If key_end is 64 then won't this overflow?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Worst case is it copies the entire buffer minus the "set " at the beginning, so it should fit.

Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't the worst case an overflow?

If key_end is 64 then we have the following:

      int key_start   = 4;
      int key_end     = 64; // A valid result from find_end()
      int key_len     = 60;
      int value_start = 65;
      int value_end   = ??;
      int value_len   = ??;

     char read_buf[64];

This memcpy() will become:

       memcpy(key_buf, read_buf + 4, 60);

which is ok,

    key_buf[60] = '\0';

Seems like the wrong place to set the terminator though

but

    memcpy(value_buf, read_buf + 65, ??);

Is an overflow

Copy link
Member

@ppannuto ppannuto left a comment

Choose a reason for hiding this comment

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

bors r+

@bors
Copy link
Contributor

bors bot commented Jul 26, 2023

Build succeeded!

The publicly hosted instance of bors-ng is deprecated and will go away soon.

If you want to self-host your own instance, instructions are here.
For more help, visit the forum.

If you want to switch to GitHub's built-in merge queue, visit their help page.

@bors bors bot merged commit 4f84ecb into master Jul 26, 2023
2 of 4 checks passed
@bors bors bot deleted the kv-sync branch July 26, 2023 14:42
tyler-potyondy pushed a commit to tyler-potyondy/libtock-c that referenced this pull request Mar 13, 2024
325: Add interactive Key-Value app r=ppannuto a=bradjc

This app can set/get/delete keys through stdin.

I also added sync functions to make the app easier to write.

Co-authored-by: Brad Campbell <bradjc5@gmail.com>
Co-authored-by: Pat Pannuto <pat.pannuto@gmail.com>
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.

3 participants