This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: aio_error() POSIX compliance


This is a small patch to fix a POSIX compliance issue in aio_error().

The IEEE Std 1003.1-2001
(http://www.opengroup.org/onlinepubs/007904975/toc.htm) says
(http://www.opengroup.org/onlinepubs/007904975/functions/aio_error.html)
with respect to aio_error():

     int aio_error(const struct aiocb *aiocbp);

     The aio_error() function may fail if:

     [EINVAL] The aiocbp argument does not refer to an asynchronous
     operation whose return status has not yet been retrieved.

1. Right now, glibc does not do any error checking for whether the aiocbp is
invalid.  For example, if aio_error() is passed a null pointer, it
segfaults (see below for code listing for test0020.c):

    % ./test0020
    Segmentation fault

Because the spec uses the 'may fail' phrasing, I do not think that any test
more restrictive than that for a null pointer is acceptable from a
performance standpoint.  I suggest that aio_error() perform a test for a
null pointer being passed.

Here is the patch (authored by Tom Gall and Amos Waterland of IBM LTC).

---- Begin patch ----

Index: rt/aio_error.c
===================================================================
RCS file: /cvs/glibc/libc/rt/aio_error.c,v
retrieving revision 1.2
diff -u -r1.2 aio_error.c
--- rt/aio_error.c	6 Jul 2001 04:55:39 -0000	1.2
+++ rt/aio_error.c	12 Jun 2002 23:53:41 -0000
@@ -29,11 +29,21 @@
 /* And undo the hack.  */
 #undef aio_error64
 
+#include <errno.h>
 
 int
 aio_error (aiocbp)
      const struct aiocb *aiocbp;
 {
+  /* We could do a more restrictive check, but for performance, since the
+   * spec makes EINVAL a 'may fail', we only check for null pointer.
+   */
+  if (aiocbp == NULL)
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
   return aiocbp->__error_code;
 }

---- End patch ----

---- Begin test0020.c ----

/* Show that aio_error() segfaults if passed a null pointer.
 * Amos Waterland <apw@us.ibm.com>
 * 12 June 2002
 */

#include <aio.h>

int main( int argc, char *argv[] )
{
    aio_error( NULL );

    return 0;
}

---- End test0020.c ----


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]