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

STR32-C: Support reducing buffer size via realloc #31

Closed
lcartey opened this issue Jul 26, 2022 · 0 comments · Fixed by #579
Closed

STR32-C: Support reducing buffer size via realloc #31

lcartey opened this issue Jul 26, 2022 · 0 comments · Fixed by #579
Assignees
Labels
Difficulty-High A false positive or false negative report which is expected to take 1+ week effort to address false positive/false negative An issue related to observed false positives or false negatives. Impact-Medium Phase II user-report Issue reported by an end user of CodeQL Coding Standards

Comments

@lcartey
Copy link
Collaborator

lcartey commented Jul 26, 2022

Affected rules

  • STR32-C

Description

Support reducing buffer size via realloc.

Example

#include <stdlib.h>
#include <wchar.h>
  
wchar_t *cur_msg = NULL;
size_t cur_msg_size = 1024;
size_t cur_msg_len = 0;
 
void lessen_memory_usage(void) {
  wchar_t *temp;
  size_t temp_size;
 
  /* ... */
 
  if (cur_msg != NULL) {
    temp_size = cur_msg_size / 2 + 1;
    temp = realloc(cur_msg, temp_size * sizeof(wchar_t));
    /* temp &and cur_msg may no longer be null-terminated */
    if (temp == NULL) {
      /* Handle error */
    }
 
    cur_msg = temp;
    cur_msg_size = temp_size;
    cur_msg_len = wcslen(cur_msg);
  }
}

As taken from https://wiki.sei.cmu.edu/confluence/display/c/STR32-C.+Do+not+pass+a+non-null-terminated+character+sequence+to+a+library+function+that+expects+a+string#STR32C.Donotpassanonnullterminatedcharactersequencetoalibraryfunctionthatexpectsastring-NoncompliantCodeExample.1

@lcartey lcartey added Difficulty-High A false positive or false negative report which is expected to take 1+ week effort to address Impact-Medium false positive/false negative An issue related to observed false positives or false negatives. labels Jul 26, 2022
@ravikprasad ravikprasad added the user-report Issue reported by an end user of CodeQL Coding Standards label Feb 20, 2024
@knewbury01 knewbury01 self-assigned this Apr 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty-High A false positive or false negative report which is expected to take 1+ week effort to address false positive/false negative An issue related to observed false positives or false negatives. Impact-Medium Phase II user-report Issue reported by an end user of CodeQL Coding Standards
Projects
Development

Successfully merging a pull request may close this issue.

4 participants