]> arthur.barton.de Git - netatalk.git/blobdiff - libatalk/adouble/ad_read.c
Merge master
[netatalk.git] / libatalk / adouble / ad_read.c
index 877ab574cff326dc3b70750572fa2577d4bec1ab..224c72d9fb381fe12470a27117a2aab52117545a 100644 (file)
@@ -60,7 +60,7 @@ ssize_t adf_pread(struct ad_fd *ad_fd, void *buf, size_t count, off_t offset)
 /* XXX: locks have to be checked before each stream of consecutive
  *      ad_reads to prevent a denial in the middle from causing
  *      problems. */
-ssize_t ad_read( struct adouble *ad, const u_int32_t eid, off_t off, char *buf, const size_t buflen)
+ssize_t ad_read( struct adouble *ad, const uint32_t eid, off_t off, char *buf, const size_t buflen)
 {
     ssize_t     cc;
 
@@ -102,12 +102,15 @@ ssize_t ad_read( struct adouble *ad, const u_int32_t eid, off_t off, char *buf,
                 }
             }
         } else { /* AD_VERSION_EA */
-            if ((off + buflen) > ad->ad_rlen) {
+            if (off > ad->ad_rlen) {
                 errno = ERANGE;
                 return -1;
             }
-            memcpy(buf, ad->ad_resforkbuf + off, buflen);
-            cc = buflen;
+            if (ad->ad_rlen == 0)
+                return 0;
+            if ((off + buflen) > ad->ad_rlen)
+                cc = ad->ad_rlen;
+            memcpy(buf, ad->ad_resforkbuf + off, cc);
         }
     }