summaryrefslogtreecommitdiff
path: root/libpam_misc/xstrdup.c
diff options
context:
space:
mode:
authorAndrew G. Morgan <morgan@kernel.org>2000-06-20 22:10:38 +0000
committerAndrew G. Morgan <morgan@kernel.org>2000-06-20 22:10:38 +0000
commitea488580c42e8918445a945484de3c8a5addc761 (patch)
treec992f3ba699caafedfadc16af38e6359c3c24698 /libpam_misc/xstrdup.c
Initial revision
Diffstat (limited to 'libpam_misc/xstrdup.c')
-rw-r--r--libpam_misc/xstrdup.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/libpam_misc/xstrdup.c b/libpam_misc/xstrdup.c
new file mode 100644
index 00000000..6a4ca6f7
--- /dev/null
+++ b/libpam_misc/xstrdup.c
@@ -0,0 +1,31 @@
+/* $Id$ */
+
+#include <malloc.h>
+#include <string.h>
+#include <security/pam_misc.h>
+
+/*
+ * Safe duplication of character strings. "Paranoid"; don't leave
+ * evidence of old token around for later stack analysis.
+ */
+
+char *xstrdup(const char *x)
+{
+ register char *new=NULL;
+
+ if (x != NULL) {
+ register int i;
+
+ for (i=0; x[i]; ++i); /* length of string */
+ if ((new = malloc(++i)) == NULL) {
+ i = 0;
+ } else {
+ while (i-- > 0) {
+ new[i] = x[i];
+ }
+ }
+ x = NULL;
+ }
+
+ return new; /* return the duplicate or NULL on error */
+}