aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog.txt2
-rw-r--r--guts/execl.c12
-rw-r--r--guts/execle.c12
-rw-r--r--guts/execlp.c12
-rw-r--r--pseudo_client.c5
-rw-r--r--pseudo_util.c21
6 files changed, 53 insertions, 11 deletions
diff --git a/ChangeLog.txt b/ChangeLog.txt
index 2feff1a..b9953bd 100644
--- a/ChangeLog.txt
+++ b/ChangeLog.txt
@@ -1,5 +1,7 @@
2010-08-16:
* (rp) Fix ld_preload/ld_library_path mixup.
+ * (seebs) Handle failed allocations.
+ * (seebs) Fix logic for dropping empty LD_PRELOAD.
2010-08-12:
* (seebs) Fix install of libpseudo so the plain library is created
diff --git a/guts/execl.c b/guts/execl.c
index 92a4cdc..d7b477c 100644
--- a/guts/execl.c
+++ b/guts/execl.c
@@ -10,6 +10,12 @@
size_t i = 0;
size_t alloc_size = 256;
const char **argv = malloc(sizeof (const char *) * alloc_size);
+ if (!argv) {
+ pseudo_debug(1, "execl failed: couldn't allocate memory for %lu arguments\n",
+ (unsigned long) alloc_size);
+ errno = ENOMEM;
+ return -1;
+ }
argv[i++] = arg;
@@ -18,6 +24,12 @@
if ( i > alloc_size - 1 ) {
alloc_size = alloc_size + 256;
argv = realloc(argv, sizeof (const char *) * alloc_size);
+ if (!argv) {
+ pseudo_debug(1, "execl failed: couldn't allocate memory for %lu arguments\n",
+ (unsigned long) alloc_size);
+ errno = ENOMEM;
+ return -1;
+ }
}
}
diff --git a/guts/execle.c b/guts/execle.c
index f4c2ea7..13fbfb9 100644
--- a/guts/execle.c
+++ b/guts/execle.c
@@ -11,6 +11,12 @@
size_t alloc_size = 256;
const char **argv = malloc(sizeof (const char *) * alloc_size);
char *const *envp;
+ if (!argv) {
+ pseudo_debug(1, "execle failed: couldn't allocate memory for %lu arguments\n",
+ (unsigned long) alloc_size);
+ errno = ENOMEM;
+ return -1;
+ }
argv[i++] = arg;
@@ -19,6 +25,12 @@
if ( i > alloc_size - 1 ) {
alloc_size = alloc_size + 256;
argv = realloc(argv, sizeof (const char *) * alloc_size);
+ if (!argv) {
+ pseudo_debug(1, "execle failed: couldn't allocate memory for %lu arguments\n",
+ (unsigned long) alloc_size);
+ errno = ENOMEM;
+ return -1;
+ }
}
}
envp = va_arg (ap, char *const *);
diff --git a/guts/execlp.c b/guts/execlp.c
index 8fd2cdf..d09a64d 100644
--- a/guts/execlp.c
+++ b/guts/execlp.c
@@ -10,6 +10,12 @@
size_t i = 0;
size_t alloc_size = 256;
const char **argv = malloc(sizeof (const char *) * alloc_size);
+ if (!argv) {
+ pseudo_debug(1, "execlp failed: couldn't allocate memory for %lu arguments\n",
+ (unsigned long) alloc_size);
+ errno = ENOMEM;
+ return -1;
+ }
argv[i++] = arg;
@@ -18,6 +24,12 @@
if ( i > alloc_size - 1 ) {
alloc_size = alloc_size + 256;
argv = realloc(argv, sizeof (const char *) * alloc_size);
+ if (!argv) {
+ pseudo_debug(1, "execlp failed: couldn't allocate memory for %lu arguments\n",
+ (unsigned long) alloc_size);
+ errno = ENOMEM;
+ return -1;
+ }
}
}
diff --git a/pseudo_client.c b/pseudo_client.c
index c933329..c5a1531 100644
--- a/pseudo_client.c
+++ b/pseudo_client.c
@@ -466,13 +466,10 @@ client_ping(void) {
ping.type = PSEUDO_MSG_PING;
ping.op = OP_NONE;
- if (!tag)
- tag = strdup("");
-
ping.pathlen = snprintf(tagbuf, sizeof(tagbuf), "%s%c%s",
program_invocation_name ? program_invocation_name : "<unknown>",
0,
- tag);
+ tag ? tag : "");
free(tag);
ping.client = getpid();
ping.result = 0;
diff --git a/pseudo_util.c b/pseudo_util.c
index 7b942e4..93aceb7 100644
--- a/pseudo_util.c
+++ b/pseudo_util.c
@@ -111,13 +111,19 @@ int pseudo_set_value(const char * key, const char * value) {
if (_in_init == -1) _libpseudo_init();
- for (i = 0; pseudo_env[i].key && memcmp(pseudo_env[i].key, key, pseudo_env[i].key_len + 1); i++) ;
+ for (i = 0; pseudo_env[i].key && memcmp(pseudo_env[i].key, key, pseudo_env[i].key_len + 1); i++)
+ ;
if (pseudo_env[i].key) {
if (pseudo_env[i].value) free(pseudo_env[i].value);
- if (value)
- pseudo_env[i].value = strdup(value);
- else
+ if (value) {
+ char *new = strdup(value);
+ if (new)
+ pseudo_env[i].value = new;
+ else
+ pseudo_diag("warning: failed to save new value (%s) for key %s\n",
+ value, key);
+ } else
pseudo_env[i].value = NULL;
} else {
if (!_in_init) pseudo_diag("Unknown variable %s.\n", key);
@@ -600,8 +606,9 @@ pseudo_dropenvp(char * const *envp) {
pseudo_diag("fatal: can't allocate new environment variable.\n");
return 0;
} else {
- /* don't keep an empty value */
- if (memcmp(new_val, "LD_PRELOAD=", 11)) {
+ /* don't keep an empty value; if the whole string is
+ * LD_PRELOAD=, we just drop it. */
+ if (memcmp(new_val, "LD_PRELOAD=", 12)) {
new_envp[j++] = new_val;
}
}
@@ -629,7 +636,7 @@ pseudo_setupenv() {
while (pseudo_env[i].key) {
if (pseudo_env[i].value)
- setenv(pseudo_env[i].key, strdup(pseudo_env[i].value), 0);
+ setenv(pseudo_env[i].key, pseudo_env[i].value, 0);
i++;
}