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

simple memcpy/strlen bug #7

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

simple memcpy/strlen bug #7

wants to merge 2 commits into from

Conversation

Sehun0819
Copy link

@Sehun0819 Sehun0819 commented Sep 7, 2021

  • memcpy
char dst[5];
char src[5] = "abcd";
memcpy(dst, src, 5);

Sparrow raises following alarm on above code

= Alarms =
1. memcpy.c:8 {main} UnProven
  memcpy (StartOf(dst), StartOf(src), 5) @main-17:  offset: [6, 6], size: [5, 5] UnProven, allocsite: main-10
  memcpy (StartOf(dst), StartOf(src), 5) @main-17:  offset: [6, 6], size: [5, 5] UnProven, allocsite: main-8

And I found out current code calculates 'offset = len + 1` and it must be a typo.

  • strlen
char* str = "abcd";
char* substr = str + 1;
int len1 = strlen(str);
int len2 = strlen(substr);

Currently both len1 and len2 are evaluated to 4, as model_strlen doesn't count offset.

@Sehun0819 Sehun0819 changed the title simple memcpy bug simple memcpy/strlen bug Sep 19, 2021
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.

1 participant