From aaf6fd7514d3549ebdb545af63fefac951a19ee4 Mon Sep 17 00:00:00 2001 From: Tom Yu Date: Wed, 24 Jan 2001 02:18:20 +0000 Subject: [PATCH] * rc_io.c (getdir): Subtract one from dirlen, since sizeof includes the terminating NUL character. Avoid redundant path separators. (krb5_rc_io_move): When renaming OLD to NEW, don't copy the filename. This was causing temporary files to get leaked. (krb5_rc_io_close): Don't FREE if d->fn is NULL. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@12935 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/rcache/ChangeLog | 9 +++++++++ src/lib/krb5/rcache/rc_io.c | 22 +++++++++++----------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/lib/krb5/rcache/ChangeLog b/src/lib/krb5/rcache/ChangeLog index 933a57465..622d4fe1c 100644 --- a/src/lib/krb5/rcache/ChangeLog +++ b/src/lib/krb5/rcache/ChangeLog @@ -1,3 +1,12 @@ +2001-01-23 Tom Yu + + * rc_io.c (getdir): Subtract one from dirlen, since sizeof + includes the terminating NUL character. Avoid redundant path + separators. + (krb5_rc_io_move): When renaming OLD to NEW, don't copy the + filename. This was causing temporary files to get leaked. + (krb5_rc_io_close): Don't FREE if d->fn is NULL. + 2001-01-16 Ken Raeburn * rcfns.c: New file, with function versions of former dispatch diff --git a/src/lib/krb5/rcache/rc_io.c b/src/lib/krb5/rcache/rc_io.c index 549788f52..8c7853eeb 100644 --- a/src/lib/krb5/rcache/rc_io.c +++ b/src/lib/krb5/rcache/rc_io.c @@ -61,7 +61,7 @@ static void getdir() #if defined(_MSDOS) || defined(_WIN32) if (!(dir = getenv("TEMP"))) if (!(dir = getenv("TMP"))) - dir = "C:\\"; + dir = "C:"; #else if (!(dir = getenv("TMPDIR"))) #ifdef RCTMPDIR @@ -70,7 +70,7 @@ static void getdir() dir = "/tmp"; #endif #endif - dirlen = strlen(dir) + sizeof(PATH_SEPARATOR); + dirlen = strlen(dir) + sizeof(PATH_SEPARATOR) - 1; } krb5_error_code krb5_rc_io_creat (context, d, fn) @@ -242,33 +242,32 @@ krb5_error_code krb5_rc_io_move (context, new, old) krb5_rc_iostuff *new; krb5_rc_iostuff *old; { + char *fn = NULL; + #if defined(_MSDOS) || defined(_WIN32) /* * Work around provided by Tom Sanfilippo to work around poor * Windows emulation of POSIX functions. Rename and dup has * different semantics! */ - char *fn = NULL; GETDIR; close(new->fd); unlink(new->fn); close(old->fd); if (rename(old->fn,new->fn) == -1) /* MUST be atomic! */ return KRB5_RC_IO_UNKNOWN; - if (!(fn = malloc(strlen(new->fn) - dirlen + 1))) - return KRB5_RC_IO_MALLOC; - strcpy(fn, new->fn + dirlen); + fn = new->fn; + new->fn = NULL; /* avoid clobbering */ krb5_rc_io_close(context, new); krb5_rc_io_open(context, new, fn); free(fn); #else if (rename(old->fn,new->fn) == -1) /* MUST be atomic! */ return KRB5_RC_IO_UNKNOWN; + fn = new->fn; + new->fn = NULL; /* avoid clobbering */ (void) krb5_rc_io_close(context, new); - new->fn = malloc(strlen(old->fn)+1); - if (new->fn == 0) - return ENOMEM; - strcpy(new->fn, old->fn); + new->fn = fn; #ifdef macintosh new->fd = fcntl(old->fd, F_DUPFD); #else @@ -339,7 +338,8 @@ krb5_error_code krb5_rc_io_close (context, d) krb5_context context; krb5_rc_iostuff *d; { - FREE(d->fn); + if (d->fn != NULL) + FREE(d->fn); d->fn = NULL; if (close(d->fd) == -1) /* can't happen */ return KRB5_RC_IO_UNKNOWN; -- 2.26.2