rbb 99/05/24 20:14:20
Modified: apr/file_io/unix dir.c fileacc.c filedup.c open.c pipe.c readwrite.c apr/misc/unix start.c apr/test testfile.c testthread.c include apr_errno.h apr_file_io.h Log: Tracked down a heap corruption finally. Revision Changes Path 1.11 +10 -14 apache-apr/apr/file_io/unix/dir.c Index: dir.c =================================================================== RCS file: /home/cvs/apache-apr/apr/file_io/unix/dir.c,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- dir.c 1999/05/24 17:28:15 1.10 +++ dir.c 1999/05/25 03:14:14 1.11 @@ -74,21 +74,19 @@ ap_status_t ap_opendir(ap_context_t *cont, const char *dirname, struct dir_t **new) { - struct dir_t *thedir = (struct dir_t *)ap_palloc(cont->pool, sizeof(struct dir_t)); + (*new) = (struct dir_t *)ap_palloc(cont->pool, sizeof(struct dir_t)); - thedir->cntxt = cont; - thedir->dirname = strdup(dirname); - thedir->dirstruct = opendir(dirname); - thedir->entry = NULL; - - if (thedir->dirstruct == NULL) { - thedir->dirstruct = NULL; - *new = thedir; + (*new)->cntxt = cont; + (*new)->dirname = strdup(dirname); + (*new)->dirstruct = opendir(dirname); + (*new)->entry = NULL; + + if ((*new)->dirstruct == NULL) { + (*new)->dirstruct = NULL; return errno; } else { - ap_register_cleanup(thedir->cntxt->pool, (void *)thedir, dir_cleanup, NULL); - *new = thedir; + ap_register_cleanup((*new)->cntxt->pool, (void *)(*new), dir_cleanup, NULL); return APR_SUCCESS; } } @@ -217,9 +215,7 @@ ap_status_t ap_get_dir_filename(struct dir_t *thedir, char **new) { - char *name = (char *)ap_palloc(thedir->cntxt->pool, strlen(thedir->entry->d_name)); - name = ap_pstrdup(thedir->cntxt->pool, thedir->entry->d_name); - *new = name; + (*new) = ap_pstrdup(thedir->cntxt->pool, thedir->entry->d_name); return APR_SUCCESS; } 1.10 +2 -1 apache-apr/apr/file_io/unix/fileacc.c Index: fileacc.c =================================================================== RCS file: /home/cvs/apache-apr/apr/file_io/unix/fileacc.c,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- fileacc.c 1999/05/24 17:28:15 1.9 +++ fileacc.c 1999/05/25 03:14:14 1.10 @@ -56,6 +56,7 @@ #include "fileio.h" #include "apr_file_io.h" #include "apr_general.h" +#include "apr_lib.h" #include <errno.h> #include <string.h> #include <sys/types.h> @@ -65,7 +66,7 @@ ap_status_t ap_get_filename(struct file_t *thefile, char **new) { if (thefile != NULL) { - *new = thefile->fname; + *new = ap_pstrdup(thefile->cntxt->pool, thefile->fname); return APR_SUCCESS; } else { 1.13 +17 -17 apache-apr/apr/file_io/unix/filedup.c Index: filedup.c =================================================================== RCS file: /home/cvs/apache-apr/apr/file_io/unix/filedup.c,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- filedup.c 1999/05/24 17:28:16 1.12 +++ filedup.c 1999/05/25 03:14:14 1.13 @@ -56,29 +56,29 @@ #include "fileio.h" #include "apr_file_io.h" #include "apr_general.h" +#include "apr_lib.h" #include <string.h> -ap_status_t ap_dupfile(struct file_t *old_file, struct file_t **new) +ap_status_t ap_dupfile(struct file_t *old_file, struct file_t **new_file) { - struct file_t *new_file = (struct file_t *)ap_palloc(old_file->cntxt->pool, + (*new_file) = (struct file_t *)ap_palloc(old_file->cntxt->pool, sizeof(struct file_t)); - if (new_file == NULL) { - *new = NULL; + if ((*new_file) == NULL) { return APR_ENOMEM; - } - old_file->filedes = dup(new_file->filedes); - old_file->fname = strdup(new_file->fname); - old_file->buffered = new_file->buffered; - old_file->protection = new_file->protection; - old_file->user = new_file->user; - old_file->group = new_file->group; - old_file->size = new_file->size; - old_file->atime = new_file->atime; - old_file->mtime = new_file->mtime; - old_file->ctime = new_file->ctime; - ap_register_cleanup(old_file->cntxt->pool, (void *)new_file, file_cleanup, NULL); - *new = new_file; + } + (*new_file)->cntxt = old_file->cntxt; + (*new_file)->filedes = dup(old_file->filedes); + (*new_file)->fname = ap_pstrdup(old_file->cntxt->pool, old_file->fname); + (*new_file)->buffered = old_file->buffered; + (*new_file)->protection = old_file->protection; + (*new_file)->user = old_file->user; + (*new_file)->group = old_file->group; + (*new_file)->size = old_file->size; + (*new_file)->atime = old_file->atime; + (*new_file)->mtime = old_file->mtime; + (*new_file)->ctime = old_file->ctime; + ap_register_cleanup((*new_file)->cntxt->pool, (void *)(*new_file), file_cleanup, NULL); return APR_SUCCESS; } 1.24 +12 -18 apache-apr/apr/file_io/unix/open.c Index: open.c =================================================================== RCS file: /home/cvs/apache-apr/apr/file_io/unix/open.c,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- open.c 1999/05/24 17:28:16 1.23 +++ open.c 1999/05/25 03:14:15 1.24 @@ -76,13 +76,12 @@ ap_status_t ap_open(ap_context_t *cont, char *fname, ap_int32_t flag, ap_fileperms_t perm, struct file_t **new) { int oflags = 0; - struct file_t *dafile; struct stat info; mode_t mode = get_fileperms(perm); - dafile = (struct file_t *)ap_palloc(cont->pool, sizeof(struct file_t)); + (*new) = (struct file_t *)ap_palloc(cont->pool, sizeof(struct file_t)); - dafile->cntxt = cont; + (*new)->cntxt = cont; if ((flag & APR_READ) && (flag & APR_WRITE)) { oflags = O_RDWR; @@ -94,15 +93,14 @@ oflags = O_WRONLY; } else { - dafile->filedes = -1; - *new = dafile; + (*new)->filedes = -1; return APR_EACCES; } if (flag & APR_BUFFERED) { - dafile->buffered = TRUE; + (*new)->buffered = TRUE; } - dafile->fname = strdup(fname); + (*new)->fname = strdup(fname); if (flag & APR_CREATE) { oflags |= O_CREAT; @@ -111,8 +109,7 @@ } } if ((flag & APR_EXCL) && !(flag & APR_CREATE)) { - dafile->filedes = -1; - *new = dafile; + (*new)->filedes = -1; return APR_EACCES; } @@ -123,22 +120,19 @@ oflags |= O_TRUNC; } - dafile->filedes = open(fname, oflags, mode); + (*new)->filedes = open(fname, oflags, mode); - if (dafile->filedes < 0) { - dafile->filedes = -1; - *new = dafile; + if ((*new)->filedes < 0) { + (*new)->filedes = -1; return errno; } - if (ap_updatefileinfo(dafile) == APR_SUCCESS) { - ap_register_cleanup(dafile->cntxt->pool, (void *)dafile, file_cleanup, NULL); - *new = dafile; + if (ap_updatefileinfo(*new) == APR_SUCCESS) { + ap_register_cleanup((*new)->cntxt->pool, (void *)(*new), file_cleanup, NULL); return APR_SUCCESS; } else { - dafile->filedes = -1; - *new = dafile; + (*new)->filedes = -1; return APR_ENOSTAT; } } 1.9 +2 -5 apache-apr/apr/file_io/unix/pipe.c Index: pipe.c =================================================================== RCS file: /home/cvs/apache-apr/apr/file_io/unix/pipe.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- pipe.c 1999/05/24 17:28:16 1.8 +++ pipe.c 1999/05/25 03:14:15 1.9 @@ -83,15 +83,12 @@ ap_status_t ap_create_namedpipe(ap_context_t *cont, char *dirpath, ap_fileperms_t perm, char **new) { - char *tmp; mode_t mode = get_fileperms(perm); - tmp = tempnam(dirpath, NULL); - if (mkfifo(tmp, mode) == -1) { - *new = NULL; + *new = tempnam(dirpath, NULL); + if (mkfifo((*new), mode) == -1) { return errno; } - *new = tmp; return APR_SUCCESS; } 1.11 +5 -3 apache-apr/apr/file_io/unix/readwrite.c Index: readwrite.c =================================================================== RCS file: /home/cvs/apache-apr/apr/file_io/unix/readwrite.c,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- readwrite.c 1999/05/24 17:28:16 1.10 +++ readwrite.c 1999/05/25 03:14:15 1.11 @@ -56,20 +56,22 @@ #include "fileio.h" #include "apr_file_io.h" #include "apr_general.h" +#include "apr_lib.h" #include "apr_errno.h" #include <errno.h> #include <unistd.h> #include <sys/uio.h> -ap_status_t ap_read(struct file_t *thefile, void *buf, ap_ssize_t *nbytes) +ap_status_t ap_read(const struct file_t *thefile, void *buf, ap_ssize_t *nbytes) { - ap_size_t rv; + ap_ssize_t rv; if (thefile->filedes < 0) { *nbytes = -1; return APR_EBADF; } - + + buf = ap_palloc(thefile->cntxt->pool, *nbytes); rv = read(thefile->filedes, buf, *nbytes); *nbytes = rv; 1.3 +2 -2 apache-apr/apr/misc/unix/start.c Index: start.c =================================================================== RCS file: /home/cvs/apache-apr/apr/misc/unix/start.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- start.c 1999/05/10 14:36:27 1.2 +++ start.c 1999/05/25 03:14:17 1.3 @@ -67,7 +67,7 @@ pool = ap_init_alloc(); if (pool == NULL) { - errno = ENOPOOL; + errno = APR_ENOPOOL; return NULL; } new = (ap_context_t *)ap_palloc(pool, sizeof(ap_context_t)); @@ -98,7 +98,7 @@ pool = ap_make_sub_pool(cont->pool); if (pool == NULL) { - errno = ENOPOOL; + errno = APR_ENOPOOL; return NULL; } new = (ap_context_t *)ap_palloc(pool, sizeof(ap_context_t)); 1.20 +8 -5 apache-apr/apr/test/testfile.c Index: testfile.c =================================================================== RCS file: /home/cvs/apache-apr/apr/test/testfile.c,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- testfile.c 1999/05/24 17:28:18 1.19 +++ testfile.c 1999/05/25 03:14:18 1.20 @@ -73,11 +73,14 @@ ap_uint64_t rv = 0; ap_ssize_t nbytes = 0; ap_off_t zer = 0; - char buf; + char *buf; char *str; char *filename = "test.fil"; - context = ap_initialize(NULL); + if ((context = ap_initialize(NULL)) == NULL) { + fprintf(stderr, "Couldn't allocate context."); + exit(-1); + } fprintf(stdout, "Testing file functions.\n"); @@ -106,7 +109,7 @@ fprintf(stdout, "\tWriting to file......."); - nbytes = (ap_uint64_t)strlen("this is a test"); + nbytes = (ap_ssize_t)strlen("this is a test"); if (ap_write(thefile, "this is a test", &nbytes) != APR_SUCCESS) { perror("something's wrong"); exit(-1); @@ -130,8 +133,8 @@ } fprintf(stdout, "\tReading from the file......."); - nbytes = (ap_uint64_t)strlen("this is a test"); - if (ap_read(thefile, &buf, &nbytes) != APR_SUCCESS) { + nbytes = (ap_ssize_t)strlen("this is a test"); + if (ap_read(thefile, buf, &nbytes) != APR_SUCCESS) { perror("something's wrong"); exit(-1); } 1.4 +1 -2 apache-apr/apr/test/testthread.c Index: testthread.c =================================================================== RCS file: /home/cvs/apache-apr/apr/test/testthread.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- testthread.c 1999/05/24 18:16:45 1.3 +++ testthread.c 1999/05/25 03:14:18 1.4 @@ -116,8 +116,7 @@ ap_status_t st; fprintf(stdout, "Initializing the context......."); - context = ap_initialize(NULL); - if (context == NULL) { + if (ap_create_context(NULL, NULL,context) != APR_SUCCESS) { fprintf(stderr, "could not initialize\n"); exit(-1); } 1.13 +1 -0 apache-apr/include/apr_errno.h Index: apr_errno.h =================================================================== RCS file: /home/cvs/apache-apr/include/apr_errno.h,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- apr_errno.h 1999/05/24 18:16:48 1.12 +++ apr_errno.h 1999/05/25 03:14:19 1.13 @@ -370,6 +370,7 @@ #define APR_ENOPOOL 4002 #define APR_ENOFILE 4003 #define APR_EBADDATE 4004 +#define APR_ENOCONT 4005 #ifdef __cplusplus } 1.30 +1 -1 apache-apr/include/apr_file_io.h Index: apr_file_io.h =================================================================== RCS file: /home/cvs/apache-apr/include/apr_file_io.h,v retrieving revision 1.29 retrieving revision 1.30 diff -u -r1.29 -r1.30 --- apr_file_io.h 1999/05/24 17:28:19 1.29 +++ apr_file_io.h 1999/05/25 03:14:20 1.30 @@ -108,7 +108,7 @@ ap_status_t ap_close(ap_file_t *); ap_status_t ap_remove_file(ap_context_t *, char *); -ap_status_t ap_read(ap_file_t *, void *, ap_ssize_t *); +ap_status_t ap_read(const ap_file_t *, void *, ap_ssize_t *); ap_status_t ap_write(ap_file_t *, void *, ap_ssize_t *); ap_status_t ap_writev(ap_file_t *, const ap_iovec_t *, ap_ssize_t *);