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>
... | ... |
@@ -46,6 +46,8 @@ |
46 | 46 |
#include <ctype.h> |
47 | 47 |
#include <assert.h> |
48 | 48 |
|
49 |
+#include "buffer.h" |
|
50 |
+ |
|
49 | 51 |
/* MinGW w32api 3.17 is still incomplete when it comes to CryptoAPI while |
50 | 52 |
* MinGW32-w64 defines all macros used. This is a hack around that problem. |
51 | 53 |
*/ |
... | ... |
@@ -116,7 +118,7 @@ static char *ms_error_text(DWORD ms_err) |
116 | 116 |
(LPTSTR) &lpMsgBuf, 0, NULL); |
117 | 117 |
if (lpMsgBuf) { |
118 | 118 |
char *p; |
119 |
- rv = strdup(lpMsgBuf); |
|
119 |
+ rv = string_alloc(lpMsgBuf, NULL); |
|
120 | 120 |
LocalFree(lpMsgBuf); |
121 | 121 |
/* trim to the left */ |
122 | 122 |
if (rv) |
... | ... |
@@ -822,7 +822,7 @@ void |
822 | 822 |
init_options_dev (struct options *options) |
823 | 823 |
{ |
824 | 824 |
if (!options->dev && options->dev_node) { |
825 |
- char *dev_node = strdup(options->dev_node); /* POSIX basename() implementaions may modify its arguments */ |
|
825 |
+ char *dev_node = string_alloc(options->dev_node, NULL); /* POSIX basename() implementaions may modify its arguments */ |
|
826 | 826 |
options->dev = basename (dev_node); |
827 | 827 |
} |
828 | 828 |
} |
... | ... |
@@ -1615,7 +1615,7 @@ argv_extract_cmd_name (const char *path) |
1615 | 1615 |
{ |
1616 | 1616 |
if (path) |
1617 | 1617 |
{ |
1618 |
- char *path_cp = strdup(path); /* POSIX basename() implementaions may modify its arguments */ |
|
1618 |
+ char *path_cp = string_alloc(path, NULL); /* POSIX basename() implementaions may modify its arguments */ |
|
1619 | 1619 |
const char *bn = basename (path_cp); |
1620 | 1620 |
if (bn) |
1621 | 1621 |
{ |
... | ... |
@@ -2578,7 +2578,7 @@ check_file_access(const int type, const char *file, const int mode, const char * |
2578 | 2578 |
/* Is the directory path leading to the given file accessible? */ |
2579 | 2579 |
if (type & CHKACC_DIRPATH) |
2580 | 2580 |
{ |
2581 |
- char *fullpath = strdup(file); /* POSIX dirname() implementaion may modify its arguments */ |
|
2581 |
+ char *fullpath = string_alloc (file, NULL); /* POSIX dirname() implementaion may modify its arguments */ |
|
2582 | 2582 |
char *dirpath = dirname(fullpath); |
2583 | 2583 |
|
2584 | 2584 |
if (platform_access (dirpath, mode|X_OK) != 0) |
... | ... |
@@ -197,7 +197,7 @@ tls_ctx_restrict_ciphers(struct tls_root_ctx *ctx, const char *ciphers) |
197 | 197 |
|
198 | 198 |
/* Parse allowed ciphers, getting IDs */ |
199 | 199 |
i = 0; |
200 |
- tmp_ciphers_orig = tmp_ciphers = strdup(ciphers); |
|
200 |
+ tmp_ciphers_orig = tmp_ciphers = string_alloc (ciphers, NULL); |
|
201 | 201 |
|
202 | 202 |
token = strtok (tmp_ciphers, ":"); |
203 | 203 |
while(token) |