Bug 8715 - Use non-matching NTSTATUS and WERROR members
Use non-matching NTSTATUS and WERROR members
Status: RESOLVED FIXED
Product: Samba 3.6
Classification: Unclassified
Component: Build environment
unspecified
All All
: P5 minor
: ---
Assigned To: Björn Jacke
Samba QA Contact
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-01-23 14:42 UTC by David Disseldorp
Modified: 2012-02-15 16:10 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Disseldorp 2012-01-23 14:42:23 UTC
Currently NTSTATUS and WERROR structure based types are defined as:
#if defined(HAVE_IMMEDIATE_STRUCTURES)
typedef struct {uint32_t v;} WERROR;
#define W_ERROR_V(x) ((x).v)

and...

#if defined(HAVE_IMMEDIATE_STRUCTURES)
typedef struct {uint32_t v;} NTSTATUS;
#define NT_STATUS_V(x) ((x).v)


With matching 'v' members, it's easy to make silly mistakes such as:

...
WERROR werr;

werr = my_fn();        /* XXX returns WERROR type */
if (NT_STATUS_IS_OK(werr)
 || (NT_STATUS_EQUAL(werr, NT_STATUS_OBJECT_NAME_COLLISION))) {
...

With differing members, the compiler catches attempts to use [NT_STATUS|W_ERROR]_IS_OK() and [NT_STATUS|W_ERROR]_EQUAL() with incorrect types:

diff --git a/libcli/util/werror.h b/libcli/util/werror.h
index b490974..4c14b7f 100644
--- a/libcli/util/werror.h
+++ b/libcli/util/werror.h
@@ -30,9 +30,9 @@
 */
 
 #if defined(HAVE_IMMEDIATE_STRUCTURES)
-typedef struct {uint32_t v;} WERROR;
+typedef struct {uint32_t w;} WERROR;
 #define W_ERROR(x) ((WERROR) { x })
-#define W_ERROR_V(x) ((x).v)
+#define W_ERROR_V(x) ((x).w)
 #else
 typedef uint32_t WERROR;
 #define W_ERROR(x) (x)
Comment 1 David Disseldorp 2012-01-23 15:10:35 UTC
Ready for review:

http://git.samba.org/?p=ddiss/samba.git;a=shortlog;h=refs/heads/bso8715_catch_ntstatus_werr_swaps

The following changes since commit c3a7573a849bfbc88feed43f12b6bdc71300ab0a:

  s3-spoolss: fix incorrect error check type (2012-01-22 05:03:36 +0100)

are available in the git repository at:
  git://git.samba.org/ddiss/samba.git bso8715_catch_ntstatus_werr_swaps

David Disseldorp (2):
      lib: use differing NTSTATUS and WERROR struct members
      common: fix incorrect error check types

 libcli/util/werror.h                    |    4 ++--
 source3/printing/nt_printing.c          |    2 +-
 source3/rpc_client/cli_winreg_spoolss.c |    2 +-
 source4/lib/registry/tools/regtree.c    |    2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)
Comment 2 Volker Lendecke 2012-01-23 20:13:48 UTC
+1. Put it in asap please :-)

Volker
Comment 3 Jeremy Allison 2012-01-23 20:16:09 UTC
Already in the process of adding this to master :-). This is *excellent* work !
Comment 4 David Disseldorp 2012-02-15 16:10:56 UTC
Thanks for the review Volker and Jeremy :)

This change is in master as:
commit af6bf7714d8eb4cd3ac4e9f9ab674326e74c6a49
lib: use differing NTSTATUS and WERROR struct members

IMO a 3.6 merge is not valuable, closing.