From 38458bc47a2560f697dbb017cddcaeac32d9bb63 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bastien=20ROUCARI=C3=88S?=
Date: Tue, 11 Jan 2011 17:39:12 +0100
Subject: [PATCH 1/3] Avoid xmalloc in openat implementation
Do not call xmalloc but return NULL in case of error. Caller are safe
and fallback to fchdir implementation.
---
lib/openat-proc.c | 10 +++++++++-
1 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/lib/openat-proc.c b/lib/openat-proc.c
index 51a8aa2..d543491 100644
--- a/lib/openat-proc.c
+++ b/lib/openat-proc.c
@@ -28,6 +28,7 @@
#include
#include
#include
+#include
#include "dirname.h"
#include "intprops.h"
@@ -42,6 +43,11 @@
#undef open
#undef close
+/* In this file we always malloc a stricly positive size.
+ repl_malloc(size >0) and malloc(size >0) are equivalent
+ Use therefore use the system malloc. */
+#undef malloc
+
#define PROC_SELF_FD_FORMAT "/proc/self/fd/%d/%s"
#define PROC_SELF_FD_NAME_SIZE_BOUND(len) \
@@ -98,7 +104,9 @@ openat_proc_name (char buf[OPENAT_BUFFER_SIZE], int fd, char const *file)
else
{
size_t bufsize = PROC_SELF_FD_NAME_SIZE_BOUND (strlen (file));
- char *result = (bufsize < OPENAT_BUFFER_SIZE ? buf : xmalloc (bufsize));
+ char *result = (bufsize < OPENAT_BUFFER_SIZE ? buf : malloc (bufsize));
+ if (NULL == result)
+ return NULL;
sprintf (result, PROC_SELF_FD_FORMAT, fd, file);
return result;
}
--
1.7.1