From e2a621466e740cc7fc2a659163f8895287c9a01e Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 8 Mar 2011 10:14:51 +0100 Subject: librpc/ndr: add NDR_ERR_INCOMPLETE_BUFFER and LIBNDR_FLAG_INCOMPLETE_BUFFER If we pull a pipe chunk we need a way to check if we have enough bytes to parse the complete chunk. Setting ndr_pull->flags |= LIBNDR_FLAG_INCOMPLETE_BUFFER would change NDR_ERR_BUFSIZE (and later maybe others) into NDR_ERR_INCOMPLETE_BUFFER. Signed-off-by: Stefan Metzmacher Reviewed-by: Guenther Deschner --- librpc/ndr/libndr.h | 11 ++++++++++- librpc/ndr/ndr.c | 10 ++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/librpc/ndr/libndr.h b/librpc/ndr/libndr.h index 8070c3cb56..bc843c12e2 100644 --- a/librpc/ndr/libndr.h +++ b/librpc/ndr/libndr.h @@ -123,6 +123,14 @@ struct ndr_print { #define LIBNDR_FLAG_STR_RAW8 (1<<13) #define LIBNDR_STRING_FLAGS (0x7FFC) +/* + * don't debug NDR_ERR_BUFSIZE failures, + * as the available buffer might be incomplete. + * + * return NDR_ERR_INCOMPLETE_BUFFER instead. + */ +#define LIBNDR_FLAG_INCOMPLETE_BUFFER (1<<16) + /* * This lets ndr_pull_subcontext_end() return * NDR_ERR_UNREAD_BYTES. @@ -206,7 +214,8 @@ enum ndr_err_code { NDR_ERR_INVALID_POINTER, NDR_ERR_UNREAD_BYTES, NDR_ERR_NDR64, - NDR_ERR_FLAGS + NDR_ERR_FLAGS, + NDR_ERR_INCOMPLETE_BUFFER }; #define NDR_ERR_CODE_IS_SUCCESS(x) (x == NDR_ERR_SUCCESS) diff --git a/librpc/ndr/ndr.c b/librpc/ndr/ndr.c index 3ed0310a63..99e9fe4d8f 100644 --- a/librpc/ndr/ndr.c +++ b/librpc/ndr/ndr.c @@ -453,6 +453,15 @@ _PUBLIC_ enum ndr_err_code ndr_pull_error(struct ndr_pull *ndr, va_list ap; int ret; + if (ndr->flags & LIBNDR_FLAG_INCOMPLETE_BUFFER) { + switch (ndr_err) { + case NDR_ERR_BUFSIZE: + return NDR_ERR_INCOMPLETE_BUFFER; + default: + break; + } + } + va_start(ap, format); ret = vasprintf(&s, format, ap); va_end(ap); @@ -1510,6 +1519,7 @@ const static struct { { NDR_ERR_INVALID_POINTER, "Invalid Pointer" }, { NDR_ERR_UNREAD_BYTES, "Unread Bytes" }, { NDR_ERR_NDR64, "NDR64 assertion error" }, + { NDR_ERR_INCOMPLETE_BUFFER, "Incomplete Buffer" }, { 0, NULL } }; -- cgit