httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@locus.apache.org
Subject cvs commit: apache-2.0/src/lib/apr/include apr_errno.h apr_file_io.h
Date Mon, 03 Apr 2000 16:03:16 GMT
rbb         00/04/03 09:03:16

  Modified:    src      CHANGES
               src/lib/apr/file_io/unix dir.c fileacc.c filedup.c
                        filestat.c open.c pipe.c readwrite.c
               src/lib/apr/include apr_errno.h apr_file_io.h
  Log:
  Added error checking for APR File I/O routines on Unix.  This needs to be
  ported to the rest of the platforms.
  Submitted by:	Jon Travis <jtravis@covalent.net>
  Reviewed by:	Ryan Bloom
  
  Revision  Changes    Path
  1.51      +3 -0      apache-2.0/src/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/CHANGES,v
  retrieving revision 1.50
  retrieving revision 1.51
  diff -u -r1.50 -r1.51
  --- CHANGES	2000/04/03 04:53:34	1.50
  +++ CHANGES	2000/04/03 16:03:13	1.51
  @@ -1,4 +1,7 @@
   Changes with Apache 2.0a3-dev
  +  *) Added error checking for file I/O APR routines.
  +     [Jon Travis <jtravis@covalent.net>]
  +
     *) APR: Don't use the values of resolver error codes for the 
        corresponding APR error codes.  On Unix and Win32, return the 
        proper APR error code after a resolver error. [Jeff Trawick]
  
  
  
  1.22      +43 -5     apache-2.0/src/lib/apr/file_io/unix/dir.c
  
  Index: dir.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/unix/dir.c,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- dir.c	2000/03/31 08:35:49	1.21
  +++ dir.c	2000/04/03 16:03:14	1.22
  @@ -75,6 +75,11 @@
    */                        
   ap_status_t ap_opendir(struct dir_t **new, const char *dirname, ap_context_t *cont)
   {
  +    if (new == NULL)
  +        return APR_EBADARG;
  +    if (cont == NULL)
  +        return APR_ENOCONT;
  +
       (*new) = (struct dir_t *)ap_palloc(cont, sizeof(struct dir_t));
   
       (*new)->cntxt = cont;
  @@ -101,6 +106,9 @@
   {
       ap_status_t rv;
   
  +    if (thedir == NULL)
  +        return APR_EBADARG;
  +
       if ((rv = dir_cleanup(thedir)) == APR_SUCCESS) {
           ap_kill_cleanup(thedir->cntxt, thedir, dir_cleanup);
           return APR_SUCCESS;
  @@ -119,6 +127,14 @@
   #if APR_HAS_THREADS && defined(_POSIX_THREAD_SAFE_FUNCTIONS) \
       && !defined(READDIR_IS_THREAD_SAFE)
       ap_status_t ret;
  +#endif
  +
  +    if (thedir == NULL)
  +        return APR_EBADARG;
  +
  +#if APR_HAS_THREADS && defined(_POSIX_THREAD_SAFE_FUNCTIONS) \
  +    && !defined(READDIR_IS_THREAD_SAFE)
  +
       ret = readdir_r(thedir->dirstruct, thedir->entry, &thedir->entry);
       /* Avoid the Linux problem where at end-of-directory thedir->entry
        * is set to NULL, but ret = APR_SUCCESS.
  @@ -145,6 +161,9 @@
    */                        
   ap_status_t ap_rewinddir(struct dir_t *thedir)
   {
  +    if (thedir == NULL)
  +        return APR_EBADARG;
  +
       rewinddir(thedir->dirstruct);
       return APR_SUCCESS;
   }
  @@ -160,6 +179,10 @@
   ap_status_t ap_make_dir(const char *path, ap_fileperms_t perm, ap_context_t *cont)
   {
       mode_t mode = get_fileperms(perm);
  +
  +    if (cont == NULL) 
  +        return APR_ENOCONT;
  +
       if (mkdir(path, mode) == 0) {
           return APR_SUCCESS;
       }
  @@ -176,6 +199,9 @@
    */                        
   ap_status_t ap_remove_dir(const char *path, ap_context_t *cont)
   {
  +    if (cont == NULL)
  +        return APR_ENOCONT;
  +
       if (rmdir(path) == 0) {
           return APR_SUCCESS;
       }
  @@ -195,6 +221,9 @@
       struct stat filestat;
       char *fname = NULL;    
   
  +    if (size == NULL || thedir == NULL)
  +        return APR_EBADARG;
  +
       if (thedir->entry == NULL) {
           *size = -1;
           return APR_ENOFILE;
  @@ -211,16 +240,19 @@
   }
   
   /* ***APRDOC********************************************************
  - * ap_status_t ap_dir_entry_mtime(time_t *mtime, ap_dir_t *thedir)
  + * ap_status_t ap_dir_entry_mtime(ap_time_t *mtime, ap_dir_t *thedir)
    *    Get the last modified time of the current directory entry. 
    * arg 1) the last modified time of the directory entry. 
    * arg 2) the currently open directory.
    */                        
  -ap_status_t ap_dir_entry_mtime(time_t *mtime, struct dir_t *thedir)
  +ap_status_t ap_dir_entry_mtime(ap_time_t *mtime, struct dir_t *thedir)
   {
       struct stat filestat;
       char *fname = NULL;
   
  +    if (mtime == NULL || thedir == NULL)
  +        return APR_EBADARG;
  +
       if (thedir->entry == NULL) {
           *mtime = -1;
           return APR_ENOFILE;
  @@ -233,7 +265,7 @@
           return APR_ENOSTAT;
       }
       
  -    *mtime = filestat.st_mtime;
  +    ap_ansi_time_to_ap_time(mtime, filestat.st_mtime);
       return APR_SUCCESS;
   }
    
  @@ -248,6 +280,9 @@
       struct stat filestat;
       char *fname = NULL;
   
  +    if (type == NULL || thedir == NULL)
  +        return APR_EBADARG;
  +
       if (thedir->entry == NULL) {
           *type = APR_REG;
           return APR_ENOFILE;
  @@ -287,10 +322,13 @@
    */                        
   ap_status_t ap_get_dir_filename(char **new, struct dir_t *thedir)
   {
  +    if (new == NULL)
  +        return APR_EBADARG;
  +
       /* Detect End-Of-File */
       if (thedir == NULL || thedir->entry == NULL) {
  -       *new = NULL;
  -       return APR_ENOENT;
  +        *new = NULL;
  +        return APR_ENOENT;
       }
       (*new) = ap_pstrdup(thedir->cntxt, thedir->entry->d_name);
       return APR_SUCCESS;
  
  
  
  1.19      +10 -2     apache-2.0/src/lib/apr/file_io/unix/fileacc.c
  
  Index: fileacc.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/unix/fileacc.c,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- fileacc.c	2000/03/31 08:35:49	1.18
  +++ fileacc.c	2000/04/03 16:03:14	1.19
  @@ -64,6 +64,9 @@
    */                     
   ap_status_t ap_get_filename(char **new, struct file_t *thefile)
   {
  +    if(new == NULL)
  +        return APR_EBADARG;
  +
       if (thefile != NULL) {
           *new = ap_pstrdup(thefile->cntxt, thefile->fname);
           return APR_SUCCESS;
  @@ -111,11 +114,14 @@
    */                     
   ap_status_t ap_get_filedata(void **data, char *key, struct file_t *file)
   {    
  +    if(data == NULL || key == NULL)
  +        return APR_EBADARG;
  +
       if (file != NULL) {
           return ap_get_userdata(data, key, file->cntxt);
       }
       else {
  -        data = NULL;
  +        *data = NULL;
           return APR_ENOFILE;
       }
   }
  @@ -132,11 +138,13 @@
   ap_status_t ap_set_filedata(struct file_t *file, void *data, char *key,
                               ap_status_t (*cleanup) (void *))
   {    
  +    if(data == NULL || key == NULL)
  +        return APR_EBADARG;
  +
       if (file != NULL) {
           return ap_set_userdata(data, key, cleanup, file->cntxt);
       }
       else {
  -        data = NULL;
           return APR_ENOFILE;
       }
   }
  
  
  
  1.12      +6 -0      apache-2.0/src/lib/apr/file_io/unix/filedup.c
  
  Index: filedup.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/unix/filedup.c,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- filedup.c	2000/03/31 08:35:49	1.11
  +++ filedup.c	2000/04/03 16:03:14	1.12
  @@ -59,12 +59,16 @@
    *    duplicate the specified file descriptor.
    * arg 1) The structure to duplicate into. 
    * arg 2) The file to duplicate.
  + * NOTE: *arg1 must point to a valid ap_file_t, or point to NULL
    */         
   ap_status_t ap_dupfile(struct file_t **new_file, struct file_t *old_file)
   {
       char *buf_oflags;
       int have_file = 0;
   
  +    if (new_file == NULL || old_file == NULL)
  +        return APR_EBADARG;
  +
       if ((*new_file) == NULL) {
           (*new_file) = (struct file_t *)ap_pcalloc(old_file->cntxt,
                                      sizeof(struct file_t));
  @@ -92,6 +96,8 @@
           }
           (*new_file)->filehand = freopen(old_file->fname, buf_oflags, 
                                           old_file->filehand); 
  +	if ((*new_file)->filehand == NULL)
  +	    return errno;
       }
       else {
           if (have_file) {
  
  
  
  1.17      +18 -4     apache-2.0/src/lib/apr/file_io/unix/filestat.c
  
  Index: filestat.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/unix/filestat.c,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- filestat.c	2000/03/31 08:35:49	1.16
  +++ filestat.c	2000/04/03 16:03:14	1.17
  @@ -89,9 +89,17 @@
   ap_status_t ap_getfileinfo(ap_finfo_t *finfo, struct file_t *thefile)
   {
       struct stat info;
  -/* XXX: this should be the equivalent of fstat() in unix, using stat() here is wrong */
  -    int rv = stat(thefile->fname, &info);
  +    int rv;
   
  +    if (finfo == NULL || thefile == NULL)
  +        return APR_EBADARG;
  +
  +    if (thefile->filehand == NULL) {
  +        rv = fstat(thefile->filedes, &info);
  +    } else {
  +        rv = stat(thefile->fname, &info);
  +    }
  +
       if (rv == 0) {
           finfo->protection = info.st_mode;
           finfo->filetype = filetype_from_mode(info.st_mode);
  @@ -120,9 +128,15 @@
   ap_status_t ap_stat(ap_finfo_t *finfo, const char *fname, ap_context_t *cont)
   {
       struct stat info;
  -    int rv = stat(fname, &info);
  +    int rv;
   
  -    if (rv == 0) {
  +    if(finfo == NULL || fname == NULL)
  +        return APR_EBADARG;
  +
  +    if(cont == NULL)
  +        return APR_ENOCONT;
  +
  +    if ((rv = stat(fname, &info)) == 0) {
           finfo->protection = info.st_mode;
           finfo->filetype = filetype_from_mode(info.st_mode);
           finfo->user = info.st_uid;
  
  
  
  1.35      +37 -1     apache-2.0/src/lib/apr/file_io/unix/open.c
  
  Index: open.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/unix/open.c,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- open.c	2000/03/31 08:35:49	1.34
  +++ open.c	2000/04/03 16:03:15	1.35
  @@ -59,6 +59,7 @@
   {
       struct file_t *file = thefile;
       int rv;
  +
       if (file->buffered) {
           rv = fclose(file->filehand);
       }
  @@ -96,13 +97,20 @@
    * arg 4) Access permissions for file.
    * arg 5) The context to use.
    * NOTE:  If mode is APR_OS_DEFAULT, the system open command will be 
  - *        called without any mode parameters.
  + *        called without any mode parameters.  *arg1 must point to a valid
  + *        file_t, or NULL (in which case it will be allocated)
    */
   ap_status_t ap_open(struct file_t **new, const char *fname, ap_int32_t flag,  ap_fileperms_t
perm, ap_context_t *cont)
   {
       int oflags = 0;
       char *buf_oflags;
   
  +    if (new == NULL)
  +        return APR_EBADARG;
  +
  +    if (cont == NULL)
  +        return APR_ENOCONT;
  +
       if ((*new) == NULL) {
           (*new) = (struct file_t *)ap_palloc(cont, sizeof(struct file_t));
       }
  @@ -192,6 +200,9 @@
   {
       ap_status_t rv;
     
  +    if (file == NULL)
  +        return APR_EBADARG;
  +
       if ((rv = file_cleanup(file)) == APR_SUCCESS) {
           ap_kill_cleanup(file->cntxt, file, file_cleanup);
           return APR_SUCCESS;
  @@ -209,6 +220,9 @@
    */
   ap_status_t ap_remove_file(char *path, ap_context_t *cont)
   {
  +    if (cont == NULL)
  +        return APR_ENOCONT;
  +
       if (unlink(path) == 0) {
           return APR_SUCCESS;
       }
  @@ -227,6 +241,9 @@
    */
   ap_status_t ap_get_os_file(ap_os_file_t *thefile, struct file_t *file)
   {
  +    if (thefile == NULL)
  +        return APR_EBADARG;
  +
       if (file == NULL) {
           return APR_ENOFILE;
       }
  @@ -254,6 +271,13 @@
                              ap_context_t *cont)
   {
       int *dafile = thefile;
  +    
  +    if (file == NULL || thefile == NULL)
  +        return APR_EBADARG;
  +
  +    if (cont == NULL)
  +        return APR_ENOCONT;
  +
       if ((*file) == NULL) {
           (*file) = ap_pcalloc(cont, sizeof(struct file_t));
           (*file)->cntxt = cont;
  @@ -277,6 +301,9 @@
    */
   ap_status_t ap_eof(ap_file_t *fptr)
   {
  +    if (fptr == NULL)
  +        return APR_EBADARG;
  +
       if (fptr->buffered) {
           if (feof(fptr->filehand) == 0) {
               return APR_SUCCESS;
  @@ -297,6 +324,9 @@
    */
   ap_status_t ap_ferror(ap_file_t *fptr)
   {
  +    if (fptr == NULL)
  +        return APR_EBADARG;
  +
       if (ferror(fptr->filehand)) {
           return (-1);
       }
  @@ -312,6 +342,12 @@
    */
   ap_status_t ap_open_stderr(struct file_t **thefile, ap_context_t *cont)
   {
  +    if (thefile == NULL)
  +        return APR_EBADARG;
  +
  +    if (cont == NULL)
  +        return APR_ENOCONT;
  +
       (*thefile) = ap_pcalloc(cont, sizeof(struct file_t));
       if ((*thefile) == NULL) {
           return APR_ENOMEM;
  
  
  
  1.17      +15 -0     apache-2.0/src/lib/apr/file_io/unix/pipe.c
  
  Index: pipe.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/unix/pipe.c,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- pipe.c	2000/03/31 08:35:50	1.16
  +++ pipe.c	2000/04/03 16:03:15	1.17
  @@ -86,6 +86,9 @@
    */
   ap_status_t ap_set_pipe_timeout(struct file_t *thepipe, ap_int32_t timeout)
   {
  +    if(thepipe == NULL)
  +        return APR_EBADARG;
  +
       if (thepipe->pipe == 1) {
           thepipe->timeout = timeout;
           return APR_SUCCESS;
  @@ -105,6 +108,12 @@
   {
       int filedes[2];
   
  +    if(in == NULL || out == NULL)
  +        return APR_EBADARG;
  +
  +    if(cont == NULL)
  +        return APR_ENOCONT;
  +
       if (pipe(filedes) == -1) {
           return errno;
       }
  @@ -144,6 +153,9 @@
   {
       mode_t mode = get_fileperms(perm);
   
  +    if(cont == NULL)
  +        return APR_ENOCONT;
  +
       if (mkfifo(filename, mode) == -1) {
           return errno;
       }
  @@ -159,6 +171,9 @@
   {
   #ifndef BEOS /* this code won't work on BeOS */
       int fd_flags;
  +
  +    if(thepipe == NULL)
  +        return APR_EBADARG;
   
       fd_flags = fcntl(thepipe->filedes, F_GETFL, 0);
   #if defined(O_NONBLOCK)
  
  
  
  1.30      +31 -0     apache-2.0/src/lib/apr/file_io/unix/readwrite.c
  
  Index: readwrite.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/unix/readwrite.c,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- readwrite.c	2000/03/31 08:35:50	1.29
  +++ readwrite.c	2000/04/03 16:03:15	1.30
  @@ -69,6 +69,9 @@
   {
       ap_ssize_t rv;
   
  +    if(thefile == NULL || nbytes == NULL || (buf == NULL && *nbytes != 0))
  +        return APR_EBADARG;
  +
       if (thefile->filedes < 0 && !thefile->buffered) {
           *nbytes = 0;
           return APR_EBADF;
  @@ -148,6 +151,9 @@
   {
       ap_size_t rv;
   
  +    if(thefile == NULL || nbytes == NULL || (buf == NULL && *nbytes != 0))
  +        return APR_EBADARG;
  +
       if (thefile->filedes < 0 && !thefile->buffered) {
           *nbytes = 0;
           return APR_EBADF;
  @@ -221,6 +227,10 @@
                         ap_size_t nvec, ap_ssize_t *nbytes)
   {
       int bytes;
  +
  +    if(thefile == NULL || vec == NULL || nvec < 0 || nbytes == NULL)
  +        return APR_EBADARG;
  +
       if ((bytes = writev(thefile->filedes, vec, nvec)) < 0) {
           *nbytes = 0;
           return errno;
  @@ -240,6 +250,9 @@
    */
   ap_status_t ap_putc(char ch, ap_file_t *thefile)
   {
  +    if(thefile == NULL)
  +        return APR_EBADARG;
  +
       if (thefile->buffered) {
           if (fputc(ch, thefile->filehand) == ch) {
               return APR_SUCCESS;
  @@ -260,6 +273,9 @@
    */
   ap_status_t ap_ungetc(char ch, ap_file_t *thefile)
   {
  +    if(thefile == NULL)
  +        return APR_EBADARG;
  +
       if (thefile->buffered) {
           if (ungetc(ch, thefile->filehand) == ch) {
               return APR_SUCCESS;
  @@ -280,6 +296,9 @@
   {
       ssize_t rv;
       
  +    if(thefile == NULL || ch == NULL)
  +        return APR_EBADARG;
  +
       if (thefile->buffered) {
           int r;
   
  @@ -316,6 +335,9 @@
       ssize_t rv;
       int len;
   
  +    if(thefile == NULL || str == NULL)
  +        return APR_EBADARG;
  +
       if (thefile->buffered) {
           if (fputs(str, thefile->filehand)) {
               return APR_SUCCESS;
  @@ -337,6 +359,9 @@
    */
   ap_status_t ap_flush(ap_file_t *thefile)
   {
  +    if(thefile == NULL)
  +        return APR_EBADARG;
  +
       if (thefile->buffered) {
           if (!fflush(thefile->filehand)) {
               return APR_SUCCESS;
  @@ -361,6 +386,9 @@
       ssize_t rv;
       int i;    
   
  +    if(thefile == NULL || str == NULL || len < 0)
  +        return APR_EBADARG;
  +
       if (thefile->buffered) {
           if (fgets(str, len, thefile->filehand)) {
               return APR_SUCCESS;
  @@ -401,6 +429,9 @@
       va_list ap;
       char *buf;
       int len;
  +
  +    if(fptr == NULL || format == NULL)
  +        return APR_EBADARG;
   
       buf = malloc(HUGE_STRING_LEN);
       if (buf == NULL) {
  
  
  
  1.18      +1 -0      apache-2.0/src/lib/apr/include/apr_errno.h
  
  Index: apr_errno.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/include/apr_errno.h,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- apr_errno.h	2000/04/03 03:35:00	1.17
  +++ apr_errno.h	2000/04/03 16:03:16	1.18
  @@ -111,6 +111,7 @@
   #define APR_ENOFUNCPOINTER (APR_OS_START_ERROR + 17)
   #define APR_ENODSOHANDLE   (APR_OS_START_ERROR + 18)
   #define APR_EDSOOPEN       (APR_OS_START_ERROR + 19)
  +#define APR_EBADARG        (APR_OS_START_ERROR + 20)
   
   /* APR STATUS VALUES */
   #define APR_INCHILD        (APR_OS_START_STATUS + 1)
  
  
  
  1.36      +1 -1      apache-2.0/src/lib/apr/include/apr_file_io.h
  
  Index: apr_file_io.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/include/apr_file_io.h,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- apr_file_io.h	2000/03/31 08:35:55	1.35
  +++ apr_file_io.h	2000/04/03 16:03:16	1.36
  @@ -173,7 +173,7 @@
                               ap_status_t (*cleanup) (void *));
   
   ap_status_t ap_dir_entry_size(ap_ssize_t *size, ap_dir_t *thedir);
  -ap_status_t ap_dir_entry_mtime(time_t *mtime, ap_dir_t *thedir);
  +ap_status_t ap_dir_entry_mtime(ap_time_t *mtime, ap_dir_t *thedir);
   ap_status_t ap_dir_entry_ftype(ap_filetype_e *type, ap_dir_t *thedir);
   
   #ifdef __cplusplus
  
  
  

Mime
View raw message