librpc/ndr: add NDR_ERR_INCOMPLETE_BUFFER and LIBNDR_FLAG_INCOMPLETE_BUFFER
authorStefan Metzmacher <metze@samba.org>
Tue, 8 Mar 2011 09:14:51 +0000 (10:14 +0100)
committerGünther Deschner <gd@samba.org>
Tue, 11 Feb 2014 15:02:13 +0000 (16:02 +0100)
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 <metze@samba.org>
Reviewed-by: Guenther Deschner <gd@samba.org>
librpc/ndr/libndr.h
librpc/ndr/ndr.c

index 8070c3cb56f24b78a1d1d41cc18c8073f141c1e7..bc843c12e27a6a10d31d524b63d9503545c720bb 100644 (file)
@@ -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)
index 3ed0310a639247041ea654a0c8f957ca1885dc38..99e9fe4d8fdac25f950a94819b508e9e7bd1d823 100644 (file)
@@ -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 }
 };