如何按给定Git Diff修改OpenBSD的arc4random.c代码?
First, let's break down what your existing Git diff is doing:
diff --git openbsd-compat/arc4random.c openbsd-compat/arc4random.c
--- openbsd-compat/arc4random.c
+++ openbsd-compat/arc4random.c
@@ -242,7 +242,7 @@ void arc4random_buf(void *buf, size_t n) {
_ARC4_LOCK();
_rs_random_buf(buf, n);
memset(buf, 0, n); _ARC4_UNLOCK();}
endif /* !HAVE_ARC4RANDOM_BUF */
This diff replaces the call to _rs_random_buf() with memset() to zero out the buffer instead of filling it with random data, within the arc4random_buf() function that's compiled when HAVE_ARC4RANDOM_BUF is not defined.
Here's how to replicate this change in the OpenBSD src repository's lib/libc/crypt/arc4random.c:
Step 1: Locate the target function
Open thelib/libc/crypt/arc4random.cfile and find thearc4random_buf()function wrapped in the#endif /* !HAVE_ARC4RANDOM_BUF */block. Look for the code section that includes:void arc4random_buf(void *buf, size_t n) { _ARC4_LOCK(); _rs_random_buf(buf, n); _ARC4_UNLOCK(); } # endif /* !HAVE_ARC4RANDOM_BUF */Step 2: Modify the line inside the lock/unlock block
Replace the line_rs_random_buf(buf, n);withmemset(buf, 0, n);. Your modified code should look like this:void arc4random_buf(void *buf, size_t n) { _ARC4_LOCK(); memset(buf, 0, n); _ARC4_UNLOCK(); } # endif /* !HAVE_ARC4RANDOM_BUF */Step 3: Verify the context
Double-check that you're modifying the correct instance ofarc4random_buf()—it should be the one guarded by the!HAVE_ARC4RANDOM_BUFpreprocessor condition, and surrounded by the_ARC4_LOCK()and_ARC4_UNLOCK()calls to ensure thread safety (just like in your original diff).
That's it! This change will match exactly what your Git diff specifies.
内容的提问来源于stack exchange,提问作者Hessnov

