[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Possible memory leak in lowercase() function


Hello!

I fixed a bug in lowercase().
Patch is attached.

--
Sincerely yours, Dmitry V. Krivenok
Orange System Co., Ltd.
Saint-Petersburg, Russia
work phone: +7 812 332-32-40
cellular phone: +7 921 576-70-91
e-mail: krivenok@xxxxxxxxxxxxxxx
web: http://www.orangesystem.ru
skype: krivenok_dmitry
jabber: krivenok_dmitry@xxxxxxxxx
icq: 242-526-443

From b880b247c0b320eb86c9b1a1d121a42d074ef6ad Mon Sep 17 00:00:00 2001
From: Dmitry V. Krivenok <krivenok@xxxxxxxxxxxxxxx>
Date: Thu, 10 Sep 2009 16:08:41 +0400
Subject: [PATCH] Fixed possible memory leak in lowercase function.

If user passed NULL pointer to lowercase() function, duplicated
string "new" wasn't freed before return.

Signed-off-by: Dmitry V. Krivenok <krivenok@xxxxxxxxxxxxxxx>
---
 libssh/keyfiles.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/libssh/keyfiles.c b/libssh/keyfiles.c
index 0e73fcb..67d897e 100644
--- a/libssh/keyfiles.c
+++ b/libssh/keyfiles.c
@@ -1019,11 +1019,12 @@ static int alldigits(const char *s) {
  */
 static char *lowercase(const char* str) {
   char *p = 0;
-  char *new = strdup(str);
-
-  if((str == NULL) || (new == NULL)) {
-    return NULL;
-  }
+  char *new = NULL;
+  
+  if(str == NULL) return NULL;
+  
+  new = strdup(str);
+  if(new == NULL) return NULL;
 
   for (p = new; *p; p++) {
     *p = tolower(*p);
-- 
1.6.3.3


Archive administrator: postmaster@lists.cynapses.org