vfs_fruit: rename empty_finderinfo() and make it more robust
authorRalph Boehme <slow@samba.org>
Fri, 9 Dec 2016 15:25:38 +0000 (16:25 +0100)
committerUri Simchoni <uri@samba.org>
Wed, 1 Mar 2017 23:32:20 +0000 (00:32 +0100)
No change in behaviour, but ad_entry(ad, ADEID_FINDERI) can in theory
return NULL.

The next commit will add the same function for a AfpInfo type, so rename
this function that works on struct adouble to ad_empty_finderinfo().

BUG: https://bugzilla.samba.org/show_bug.cgi?id=12427

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Uri Simchoni <uri@samba.org>
source3/modules/vfs_fruit.c

index a383e3890a58c825d005f0a836d7bada5e9d8df9..0e29168d76c473e773dda397f163954a4d9d3af4 100644 (file)
@@ -1576,16 +1576,20 @@ static bool del_fruit_stream(TALLOC_CTX *mem_ctx, unsigned int *num_streams,
        return true;
 }
 
-static bool empty_finderinfo(const struct adouble *ad)
+static bool ad_empty_finderinfo(const struct adouble *ad)
 {
-
+       int cmp;
        char emptybuf[ADEDLEN_FINDERI] = {0};
-       if (memcmp(emptybuf,
-                  ad_entry(ad, ADEID_FINDERI),
-                  ADEDLEN_FINDERI) == 0) {
-               return true;
+       char *fi = NULL;
+
+       fi = ad_entry(ad, ADEID_FINDERI);
+       if (fi == NULL) {
+               DBG_ERR("Missing FinderInfo in struct adouble [%p]\n", ad);
+               return false;
        }
-       return false;
+
+       cmp = memcmp(emptybuf, fi, ADEDLEN_FINDERI);
+       return (cmp == 0);
 }
 
 /**
@@ -2871,7 +2875,7 @@ static ssize_t fruit_pwrite(vfs_handle_struct *handle,
                }
                memcpy(ad_entry(ad, ADEID_FINDERI),
                       &ai->afpi_FinderInfo[0], ADEDLEN_FINDERI);
-               if (empty_finderinfo(ad)) {
+               if (ad_empty_finderinfo(ad)) {
                        /* Discard metadata */
                        if (config->meta == FRUIT_META_STREAM) {
                                rc = SMB_VFS_FTRUNCATE(fsp, 0);
@@ -3218,7 +3222,7 @@ static NTSTATUS fruit_streaminfo(vfs_handle_struct *handle,
        if (config->meta == FRUIT_META_NETATALK) {
                ad = ad_get(talloc_tos(), handle,
                            smb_fname->base_name, ADOUBLE_META);
-               if (ad && !empty_finderinfo(ad)) {
+               if (ad && !ad_empty_finderinfo(ad)) {
                        if (!add_fruit_stream(
                                    mem_ctx, pnum_streams, pstreams,
                                    AFPINFO_STREAM_NAME, AFP_INFO_SIZE,