From 49dc973586b4b9b72ffcac3bbb5dc7fda0d1ad4e Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 19 Dec 2010 14:22:28 +0100 Subject: lib: Protect against tevent nterror mismatches Autobuild-User: Volker Lendecke Autobuild-Date: Mon Dec 20 00:12:02 CET 2010 on sn-devel-104 --- lib/util/tevent_ntstatus.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'lib/util/tevent_ntstatus.c') diff --git a/lib/util/tevent_ntstatus.c b/lib/util/tevent_ntstatus.c index c4dd0740dc..764d251b59 100644 --- a/lib/util/tevent_ntstatus.c +++ b/lib/util/tevent_ntstatus.c @@ -20,12 +20,29 @@ #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; -- cgit