From 0ab45205af1f9ce347eb85b583b2d951c0b95acf Mon Sep 17 00:00:00 2001 From: Assar Westerlund Date: Tue, 26 Nov 1996 13:05:17 +0000 Subject: [PATCH] Initialize error string and check for NULL from strdup. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@1081 ec53bebd-3082-4978-b11e-865c3cabbd6b --- lib/otp/otp_challenge.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/otp/otp_challenge.c b/lib/otp/otp_challenge.c index 540db084a..154015063 100644 --- a/lib/otp/otp_challenge.c +++ b/lib/otp/otp_challenge.c @@ -50,7 +50,12 @@ otp_challenge (OtpContext *ctx, char *user, char *str, size_t len) int ret; ctx->challengep = 0; + ctx->err = NULL; ctx->user = strdup(user); + if (ctx->user == NULL) { + ctx->err = "Out of memory"; + return -1; + } dbm = otp_db_open (); if (dbm == NULL) { ctx->err = "Cannot open database"; @@ -61,7 +66,6 @@ otp_challenge (OtpContext *ctx, char *user, char *str, size_t len) if (ret) return ret; sprintf (str, "[ otp-%s %u %s ]", ctx->alg->name, ctx->n-1, ctx->seed); - ctx->err = NULL; ctx->challengep = 1; return 0; }