s3: Add some asserts to the filename util functions
authorTim Prouty <tprouty@samba.org>
Mon, 20 Jul 2009 21:32:32 +0000 (14:32 -0700)
committerTim Prouty <tprouty@samba.org>
Tue, 21 Jul 2009 00:26:57 +0000 (17:26 -0700)
In the smb_filename struct stream_name must equal NULL if there
is no stream name.  These asserts should catch any future offenders
of this invariant early.

source3/smbd/filename_util.c

index 1a7af714de032d49a17f6a4beebff644cb5c1705..867709a3737d79ab4a08c4d3611ecd6b7e98fa97 100644 (file)
@@ -29,6 +29,9 @@ NTSTATUS get_full_smb_filename(TALLOC_CTX *ctx,
                               char **full_name)
 {
        if (smb_fname->stream_name) {
                               char **full_name)
 {
        if (smb_fname->stream_name) {
+               /* stream_name must always be NULL if there is no stream. */
+               SMB_ASSERT(smb_fname->stream_name[0] != '\0');
+
                *full_name = talloc_asprintf(ctx, "%s%s", smb_fname->base_name,
                                             smb_fname->stream_name);
        } else {
                *full_name = talloc_asprintf(ctx, "%s%s", smb_fname->base_name,
                                             smb_fname->stream_name);
        } else {
@@ -134,6 +137,10 @@ NTSTATUS copy_smb_filename(TALLOC_CTX *ctx,
                           const struct smb_filename *smb_fname_in,
                           struct smb_filename **smb_fname_out)
 {
                           const struct smb_filename *smb_fname_in,
                           struct smb_filename **smb_fname_out)
 {
+       /* stream_name must always be NULL if there is no stream. */
+       if (smb_fname_in->stream_name) {
+               SMB_ASSERT(smb_fname_in->stream_name[0] != '\0');
+       }
 
        *smb_fname_out = talloc_zero(ctx, struct smb_filename);
        if (*smb_fname_out == NULL) {
 
        *smb_fname_out = talloc_zero(ctx, struct smb_filename);
        if (*smb_fname_out == NULL) {
@@ -174,6 +181,11 @@ NTSTATUS copy_smb_filename(TALLOC_CTX *ctx,
  ***************************************************************************/
 bool is_ntfs_stream_smb_fname(const struct smb_filename *smb_fname)
 {
  ***************************************************************************/
 bool is_ntfs_stream_smb_fname(const struct smb_filename *smb_fname)
 {
+       /* stream_name must always be NULL if there is no stream. */
+       if (smb_fname->stream_name) {
+               SMB_ASSERT(smb_fname->stream_name[0] != '\0');
+       }
+
        if (lp_posix_pathnames()) {
                return false;
        }
        if (lp_posix_pathnames()) {
                return false;
        }