Skip to content

CID 1508977: Resource leak #10204

Closed

Description

@maskit
101int
102get_redis_auth_key(char *retKeyBuff, int buffSize)
103{
104  int retval = 0;
105  // Get the Key
   	1. Condition ssl_param.redis_auth_key_file.length(), taking true branch.
106  if (ssl_param.redis_auth_key_file.length()) {
   	2. open_fn: Returning handle opened by open.
   	3. var_assign: Assigning: fd = handle returned from open(ssl_param.redis_auth_key_file.c_str(), 0).
107    int fd = open(ssl_param.redis_auth_key_file.c_str(), O_RDONLY);
108    struct stat info;
     	CID 1508975: Argument cannot be negative (NEGATIVE_RETURNS) [[select issue](https://scan6.scan.coverity.com/defectInstanceId=34625550&fileInstanceId=157339969&mergedDefectId=1508975)]
   	4. noescape: Resource fd is not freed or pointed-to in fstat. [Note: The source code implementation of the function has been overridden by a builtin model.]
   	5. Condition 0 == fstat(fd, &info), taking true branch.
109    if (0 == fstat(fd, &info)) {
110      size_t n = info.st_size;
111      std::string key_data;
112      key_data.resize(n);
   	6. noescape: Resource fd is not freed or pointed-to in read.
113      auto read_len = read(fd, const_cast<char *>(key_data.data()), n);
114      // Strip any trailing newlines
   	7. Condition read_len > 1, taking true branch.
   	8. Condition key_data[read_len - 1] == '\n', taking true branch.
   	10. Condition read_len > 1, taking true branch.
   	11. Condition key_data[read_len - 1] == '\n', taking true branch.
   	13. Condition read_len > 1, taking true branch.
   	14. Condition key_data[read_len - 1] == '\n', taking false branch.
115      while (read_len > 1 && key_data[read_len - 1] == '\n') {
116        --read_len;
   	9. Jumping back to the beginning of the loop.
   	12. Jumping back to the beginning of the loop.
117      }
118      memset(retKeyBuff, 0, buffSize);
     	CID 1508982: Argument cannot be negative (NEGATIVE_RETURNS) [[select issue](https://scan6.scan.coverity.com/defectInstanceId=34625480&fileInstanceId=157339969&mergedDefectId=1508982)]
     	CID 1508997: Out-of-bounds access (OVERRUN) [[select issue](https://scan6.scan.coverity.com/defectInstanceId=34625595&fileInstanceId=157339969&mergedDefectId=1508997)]
119      strncpy(retKeyBuff, key_data.c_str(), read_len);
120      retval = key_data.length();
121    }
   	
CID 1508977 (#1-2 of 2): Resource leak (RESOURCE_LEAK)
15. leaked_handle: Handle variable fd going out of scope leaks the handle.
122  } else {
123    TSError("Can not get redis auth key.");
124  }
125
126  return retval;
127}

Activity

  1. moved this to Todo in ATS v10.0.xon Aug 16, 2023
  2. moved this from Todo to Coverity Defects in ATS v10.0.xon Aug 22, 2023
  3. linked a pull request that will close this issueMake sure open() and read() succeeded #10273on Aug 24, 2023
  4. moved this from Coverity Defects to Done in ATS v10.0.xon Oct 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions