httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jon Travis <jtra...@covalent.net>
Subject PATCH: Broken buffering-fu
Date Thu, 30 Mar 2000 00:24:28 GMT
Ok, ran into a small problem this evening:

Passing in (under UNIX) flag set of:
        APR_WRITE | APR_CREATE | APR_APPEND | APR_BUFFERED,

to ap_open set everything up correctly in the structure, however, when
one goes to write a file based on said structure, a EBADF was returned.
The patch for the fiend is at the end.

In addition, I'd like to stress my opinion again about opaque data types
requiring
magic numbers (at least for a debug mode).  While glancing at ap_open()
this
eve, I noticed that it is perfectly reasonable (judging on the
documentation for
ap_open(), and 'pseudo-common sense) for someone to call ap_open like
this:

void foo(){
    ap_file_t *myfile;

    ap_open(&myfile, ...
    ap_action_on(myfile
...

This would of course be the wrong thing to do, as myfile does not have
the proper
allocation.  If we had magic-mojo in the ap_file_t, the ap_action_on
routine would
have known that the myfile was mal-allocated.  This is given, that the
program
even got to this point, as ap_open could be assigning memory anywhere it
pleased.
The opaque-mojo would at least give you a better idea of where the
problem
occurred, etc.


Anyway, here's the patch:  (short ... so nice)


--- apache-2.0.cvs/src/lib/apr/file_io/unix/readwrite.c Tue Mar 14
10:36:12 2000+++ apache-2.0.mydso/src/lib/apr/file_io/unix/readwrite.c
Wed Mar 29 18:11:37 2000
@@ -149,7 +149,7 @@
 {
     ap_size_t rv;

-    if (thefile->filedes < 0) {
+    if (thefile->filedes < 0 && !thefile->buffered) {
         *nbytes = 0;
         return APR_EBADF;
     }



Mime
View raw message