Skip to content

Commit 8b07b89

Browse files
committed
PR feedback
1 parent cf2f801 commit 8b07b89

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

docs/code-quality/c28213.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,39 +28,42 @@ The following code generates C28160. The `buffer` parameter annotation doesn't m
2828
*From example.h:*
2929

3030
```cpp
31-
void example_func(_Out_writes_(n) char* buffer, int n);
31+
void addNullTerminate(_Out_writes_(n) char* buffer, int n);
3232
```
3333
3434
*From example.cpp:*
3535
3636
```cpp
3737
_Use_decl_annotations_
38-
void example_func(_Out_writes_z_(n) char* buffer, int n)
38+
void addNullTerminate(_Out_writes_z_(n) char* buffer, int n)
3939
{
4040
buffer[n] = '\0';
4141
}
4242
```
4343

44-
To fix this issue, either change the annotations so they match at all locations, or after verifying the declaration annotations are correct, remove all annotations except `_Use_decl_annotations_` from the function definition. In this example, `_Out_writes_z_` appears to be correct, so we move that annotation to the function declaration in the header file. You can also remove all other annotations from the definition to simplify future maintenance, although this step is optional.
45-
46-
In real world code, it's not usually as clear which annotation is correct. For more information and guidance, see [using SAL Annotations to reduce code defects](using-sal-annotations-to-reduce-c-cpp-code-defects.md).
44+
Examine the function definition to determine what the correct annotations should be. In this case, `_Out_writes_z_(n)` appears to be correct so we move that annotation to the function declaration in the header file. This resolves the issue because the annotations in the declaration and definition now match.
4745

4846
*From example.h:*
4947

5048
```cpp
51-
void example_func(_Out_writes_z_(n) char* buffer, int n);
49+
void addNullTerminate(_Out_writes_z_(n) char* buffer, int n);
5250
```
5351
52+
The buffer annotation on the definition can now be removed to simplify future maintenance (although this step is optional).
53+
5454
*From example.cpp:*
5555
5656
```cpp
5757
_Use_decl_annotations_
58-
void example_func(char* buffer, int n)
58+
void addNullTerminate(char* buffer, int n)
5959
{
6060
buffer[n] = '\0';
6161
}
6262
```
6363

64+
In real world code, it's not usually as clear which annotation is correct. For more information and guidance, see [using SAL Annotations to reduce code defects](using-sal-annotations-to-reduce-c-cpp-code-defects.md).
65+
66+
6467
## See also
6568

6669
[Rule sets for C++ code](./using-rule-sets-to-specify-the-cpp-rules-to-run.md)\

docs/code-quality/c6029.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ helpviewer_keywords: ["C6029"]
99

1010
> Possible buffer overrun in call to '*function*'
1111
12-
Possible buffer overrun in function called due to an unchecked buffer length/size parameter.
12+
Possible buffer overrun in called function due to an unchecked buffer length/size parameter.
1313

1414
## Remarks
1515

16-
This warning indicates a function that takes a buffer and a size is passed an unchecked size. The data read-in from some external source hasn't been verified to see whether it's smaller than the buffer size. An attacker might intentionally specify a far larger than expected value for the size, which can lead to a buffer overrun. Generally, whenever you read data from an untrusted external source, make sure to verify it for validity. It's appropriate to verify the size to make sure it's in the expected range.
16+
This warning indicates a function that takes a buffer and a size is passed an unchecked size. The data read-in from some external source hasn't been verified to see whether it's smaller than the buffer size. An attacker might intentionally specify a value far larger than expected for the size, which can lead to a buffer overrun. Generally, whenever you read data from an untrusted external source, make sure to verify it for validity. It's appropriate to verify the size to make sure it's in the expected range.
1717

1818
Code analysis name: `USING_TAINTED_DATA`
1919

@@ -79,7 +79,7 @@ void processDataMultiple(FILE* file)
7979
while( dataSize > 0 )
8080
{
8181
size_t readSize = dataSize > MAX_BUFFER_SIZE ? MAX_BUFFER_SIZE : dataSize;
82-
fread(buffer, sizeof(uint32_t), readSize, file);
82+
readSize = fread(buffer, sizeof(uint32_t), readSize, file);
8383
dataSize = dataSize - readSize;
8484
// Process the data in `buffer`...
8585
}

0 commit comments

Comments
 (0)