lib: Protect against tevent nterror mismatches
authorVolker Lendecke <vl@samba.org>
Sun, 19 Dec 2010 13:22:28 +0000 (14:22 +0100)
committerVolker Lendecke <vlendec@samba.org>
Sun, 19 Dec 2010 23:12:02 +0000 (00:12 +0100)
Autobuild-User: Volker Lendecke <vlendec@samba.org>
Autobuild-Date: Mon Dec 20 00:12:02 CET 2010 on sn-devel-104

lib/util/tevent_ntstatus.c

index c4dd0740dc1d9c01220a1d78a30a3018eae005cd..764d251b591bf7dba84f65bf60de9fb7af614a7c 100644 (file)
 #include "../replace/replace.h"
 #include "tevent_ntstatus.h"
 
+#define TEVENT_NTERROR_MAGIC (0x917b5acd)
+
 bool _tevent_req_nterror(struct tevent_req *req,
                         NTSTATUS status,
                         const char *location)
 {
-       return _tevent_req_error(req, NT_STATUS_V(status),
-                                location);
+       uint64_t err;
+
+       if (NT_STATUS_IS_OK(status)) {
+               return false;
+       }
+
+       /*
+        * I've put this variable here, because I'm not 100% certain
+        * how to correctly assign a 64-bit constant and left-shift it
+        * by 32 bits in a single expression. If anyone knows, feel
+        * free :-)
+        */
+       err = TEVENT_NTERROR_MAGIC;
+       err <<= 32;
+       err |= NT_STATUS_V(status);
+
+       return _tevent_req_error(req, err, location);
 }
 
 bool tevent_req_is_nterror(struct tevent_req *req, NTSTATUS *status)
@@ -44,7 +61,10 @@ bool tevent_req_is_nterror(struct tevent_req *req, NTSTATUS *status)
                *status = NT_STATUS_NO_MEMORY;
                break;
        case TEVENT_REQ_USER_ERROR:
-               *status = NT_STATUS(err);
+               if ((err >> 32) != TEVENT_NTERROR_MAGIC) {
+                       abort();
+               }
+               *status = NT_STATUS(err & 0xffffffff);
                break;
        default:
                *status = NT_STATUS_INTERNAL_ERROR;