[CDRIVER-1900] Coverity analysis defect 76404: Out-of-bounds write Created: 02/Nov/16  Updated: 09/Nov/16  Resolved: 09/Nov/16

Status: Closed
Project: C Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 1.5.0

Type: Bug Priority: Major - P3
Reporter: Coverity Collector User Assignee: A. Jesse Jiryu Davis
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Out-of-bounds write to a buffer

Defect 76404 (STATIC_C)
Checker OVERRUN (subcategory write)
File: /src/libbson/examples/bson-streaming-reader.c
Function main
/src/libbson/examples/bson-streaming-reader.c, line: 160
Calling allocating function "malloc" which allocated memory dictated by argument "strlen(optarg)".

             hostname = (char *)malloc (strlen (optarg));

/src/libbson/examples/bson-streaming-reader.c, line: 160
Assigning: "hostname" = "malloc(strlen(optarg))".

             hostname = (char *)malloc (strlen (optarg));

/src/libbson/examples/bson-streaming-reader.c, line: 161
strcpy, whose first argument "hostname" has length equal to strlen of its second argument "optarg", will overrun its first argument because of the terminating null.

             strcpy (hostname, optarg);



 Comments   
Comment by Githook User [ 09/Nov/16 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-1900 off-by-one in example code
Branch: master
https://github.com/mongodb/libbson/commit/dec2ba3fdbfb10fe8a5bce646d0df43490b003f7

Generated at Wed Feb 07 21:13:33 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.