As reported by Bill Parker in trac #600, strdup() return values are not
always correctly checked for failed allocations. This patch adds missing
checks by using string_alloc(), which performs the required checks.
Signed-off-by: Steffan Karger <steffan@karger.me>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <
561130FC.
8090008@karger.me>
URL: http://article.gmane.org/gmane.network.openvpn.devel/10176
Signed-off-by: Gert Doering <gert@greenie.muc.de>
}
static inline void
-check_malloc_return (void *p)
+check_malloc_return (const void *p)
{
if (!p)
out_of_memory ();
#include <ctype.h>
#include <assert.h>
+#include "buffer.h"
+
/* MinGW w32api 3.17 is still incomplete when it comes to CryptoAPI while
* MinGW32-w64 defines all macros used. This is a hack around that problem.
*/
(LPTSTR) &lpMsgBuf, 0, NULL);
if (lpMsgBuf) {
char *p;
- rv = strdup(lpMsgBuf);
+ rv = string_alloc(lpMsgBuf, NULL);
LocalFree(lpMsgBuf);
/* trim to the left */
if (rv)
init_options_dev (struct options *options)
{
if (!options->dev && options->dev_node) {
- char *dev_node = strdup(options->dev_node); /* POSIX basename() implementaions may modify its arguments */
+ char *dev_node = string_alloc(options->dev_node, NULL); /* POSIX basename() implementaions may modify its arguments */
options->dev = basename (dev_node);
}
}
{
if (path)
{
- char *path_cp = strdup(path); /* POSIX basename() implementaions may modify its arguments */
+ char *path_cp = string_alloc(path, NULL); /* POSIX basename() implementaions may modify its arguments */
const char *bn = basename (path_cp);
if (bn)
{
/* Is the directory path leading to the given file accessible? */
if (type & CHKACC_DIRPATH)
{
- char *fullpath = strdup(file); /* POSIX dirname() implementaion may modify its arguments */
+ char *fullpath = string_alloc (file, NULL); /* POSIX dirname() implementaion may modify its arguments */
char *dirpath = dirname(fullpath);
if (platform_access (dirpath, mode|X_OK) != 0)
/* Parse allowed ciphers, getting IDs */
i = 0;
- tmp_ciphers_orig = tmp_ciphers = strdup(ciphers);
+ tmp_ciphers_orig = tmp_ciphers = string_alloc (ciphers, NULL);
token = strtok (tmp_ciphers, ":");
while(token)