Updating headings on every page
This commit is contained in:
@@ -4,7 +4,7 @@ date: 2022-08-13
|
||||
draft: false
|
||||
---
|
||||
|
||||
# Introduction
|
||||
## Introduction
|
||||
|
||||
Series on summarizing themes in "Secure Coding in C and C++" by Robert C. Seacord, part 2. Find part 1 here [Always null Terminate (Part 1)]({{<ref "secure-coding-in-c-summations-null-terminate.md">}}). We are currently going through this book in our work book club and there are a lot of good themes that seem to be threaded through the book. These are my notes, thoughts, and summaries on some of what I've read and our book club have discussed.
|
||||
|
||||
@@ -12,11 +12,11 @@ This is written for an audience that has a broad overview of security concepts.
|
||||
|
||||
The first theme to discuss is always `null` terminating `char *` or `char array` buffers (unless you have a *very* specific reason for not). This is very important to help prevent buffer overflows, reading arbitrary memory, accessing 'inaccessible' memory. This is part 2 where we will discuss string cat and length. For a brief discussion on string copy see [part 1]({{<ref "secure-coding-in-c-summations-null-terminate.md">}}).
|
||||
|
||||
# Functions Needing null
|
||||
## Functions Needing null
|
||||
|
||||
One of the important reasons to `null` terminate is there are several very common functions that require `null` termination. Even some that you wouldn't necessarily think of. Without having `null` at the end of the buffer, it creates a situation where things could go wrong.
|
||||
|
||||
## String Cat
|
||||
### String Cat
|
||||
|
||||
The next set of functions to look at are concatenating strings. These not only need to be `null` terminated, but they also need to be properly allocated. If they are not a concatenation could overwrite `null` terminators, and the resulting string could cause errors further in the code. Memory allocation will be discussed further in another post. First I'm going to throw a table at you, it gives a summary of string concat functions and how they handle some of the issues. We will discuss further after the table.
|
||||
|
||||
@@ -29,7 +29,7 @@ The next set of functions to look at are concatenating strings. These not only n
|
||||
|
||||
Lets go over each function:
|
||||
|
||||
### strcat
|
||||
#### strcat
|
||||
|
||||
```c
|
||||
char *strcat(char *dest, char *src)
|
||||
@@ -46,7 +46,7 @@ Arbitrary memory reads can be a problem since it could mean revealing data meant
|
||||
|
||||
Be sure to set the last character to `null` after the `strcat` is completed.
|
||||
|
||||
### strncat
|
||||
#### strncat
|
||||
|
||||
```c
|
||||
strncat(char *dest, char *src, size_t src_len)
|
||||
@@ -59,7 +59,7 @@ In addition if `src` is not `null` terminated and `src_len` is longer than the l
|
||||
`strncat` helps the developer watch for these issues but doesn't actually solve them.
|
||||
|
||||
|
||||
### strlcat
|
||||
#### strlcat
|
||||
|
||||
```c
|
||||
size_t strlcat(char *dst, const char *src, size_t size)
|
||||
@@ -74,13 +74,13 @@ Point one is great so you don't need to worry as much about pre setting the memo
|
||||
|
||||
Point two is good so you can compare `size` to the return value to see if the source was truncated.
|
||||
|
||||
## Sensing a Theme
|
||||
### Sensing a Theme
|
||||
|
||||
There are two themes for string concatenating, one is **`null` terminate all character buffers**, the second is proper memory allocation. This will be discussed in a future post.
|
||||
|
||||
Every one of these functions require the source and destination to be `null` terminated. If they are not, or if there is a `null` in the middle, it will cause issues!
|
||||
|
||||
# Conclusion
|
||||
## Conclusion
|
||||
|
||||
`null` termination is important so that we don't accidentally read or write to arbitrary memory. This concludes the discussion on `null` termination, the next post will cover proper memory allocation.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user