]> arthur.barton.de Git - netatalk.git/blobdiff - libatalk/adouble/ad_attr.c
AppleDouble buffer overrun by extremely long filename
[netatalk.git] / libatalk / adouble / ad_attr.c
index 8d026fe9f47c7ac1a55d1eb786eea064761a84a8..123560b5683b3e4af2729ce02631f238c48ffe4a 100644 (file)
@@ -1,7 +1,3 @@
-/*
- * $Id: ad_attr.c,v 1.13 2009-12-23 07:21:08 franklahm Exp $
- */
-
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif /* HAVE_CONFIG_H */
@@ -64,7 +60,7 @@ int ad_getattr(const struct adouble *ad, u_int16_t *attr)
 /* ----------------- */
 int ad_setattr(const struct adouble *ad, const u_int16_t attribute)
 {
-    u_int16_t *fflags;
+    uint16_t fflags;
 
     /* we don't save open forks indicator */
     u_int16_t attr = attribute & ~htons(ATTRBIT_DOPEN | ATTRBIT_ROPEN);
@@ -82,22 +78,24 @@ int ad_setattr(const struct adouble *ad, const u_int16_t attribute)
     }
 #if AD_VERSION == AD_VERSION2
     else if (ad->ad_version == AD_VERSION2) {
-        if (ad_getentryoff(ad, ADEID_AFPFILEI)) {
+        if (ad_getentryoff(ad, ADEID_AFPFILEI) && ad_getentryoff(ad, ADEID_FINDERI)) {
             memcpy(ad_entry(ad, ADEID_AFPFILEI) + AFPFILEIOFF_ATTR, &attr, sizeof(attr));
             
             /* Now set opaque flags in FinderInfo too */
-            fflags = (u_int16_t *)ad_entry(ad, ADEID_FINDERI) + FINDERINFO_FRFLAGOFF;
+            memcpy(&fflags, ad_entry(ad, ADEID_FINDERI) + FINDERINFO_FRFLAGOFF, 2);
             if (attr & htons(ATTRBIT_INVISIBLE))
-                *fflags |= htons(FINDERINFO_INVISIBLE);
+                fflags |= htons(FINDERINFO_INVISIBLE);
             else
-                *fflags &= htons(~FINDERINFO_INVISIBLE);
+                fflags &= htons(~FINDERINFO_INVISIBLE);
 
             /* See above comment in ad_getattr() */
             if (attr & htons(ATTRBIT_MULTIUSER)) {
                 if ( ! (ad->ad_adflags & ADFLAGS_DIR) )
-                    *fflags |= htons(FINDERINFO_ISHARED);
+                    fflags |= htons(FINDERINFO_ISHARED);
             } else
-                    *fflags &= htons(~FINDERINFO_ISHARED);
+                    fflags &= htons(~FINDERINFO_ISHARED);
+
+            memcpy(ad_entry(ad, ADEID_FINDERI) + FINDERINFO_FRFLAGOFF, &fflags, 2);
         }
     }
 #endif
@@ -154,9 +152,9 @@ u_int32_t ad_getid (struct adouble *adp, const dev_t st_dev, const ino_t st_ino
      * only use the ID if adouble is writable for us.
      */
     if (adp
-        && ( adp->ad_options & ADVOL_CACHE)
+        && (adp->ad_options & ADVOL_CACHE)
         && (adp->ad_md->adf_flags & O_RDWR )
-        && (sizeof(dev_t) == ad_getentrylen(adp, ADEID_PRIVID)) /* One check to ensure ALL values are there */
+        && (sizeof(dev_t) == ad_getentrylen(adp, ADEID_PRIVDEV)) /* One check to ensure ALL values are there */
         ) {
         memcpy(&dev, ad_entry(adp, ADEID_PRIVDEV), sizeof(dev_t));
         memcpy(&ino, ad_entry(adp, ADEID_PRIVINO), sizeof(ino_t));
@@ -192,9 +190,12 @@ u_int32_t ad_forcegetid (struct adouble *adp)
  */
 int ad_setname(struct adouble *ad, const char *path)
 {
-    if (ad_getentryoff(ad, ADEID_NAME)) {
-        ad_setentrylen( ad, ADEID_NAME, strlen( path ));
-        memcpy(ad_entry( ad, ADEID_NAME ), path, ad_getentrylen( ad, ADEID_NAME ));
+    int len;
+    if ((len = strlen(path)) > ADEDLEN_NAME)
+        len = ADEDLEN_NAME;
+    if (path && ad_getentryoff(ad, ADEID_NAME)) {
+        ad_setentrylen( ad, ADEID_NAME, len);
+        memcpy(ad_entry( ad, ADEID_NAME ), path, len);
         return 1;
     }
     return 0;