]> arthur.barton.de Git - netatalk.git/commitdiff
Fix string length calculation for empty strings
authorFrank Lahm <franklahm@googlemail.com>
Tue, 3 Jul 2012 10:15:19 +0000 (12:15 +0200)
committerFrank Lahm <franklahm@googlemail.com>
Wed, 15 Aug 2012 18:14:22 +0000 (20:14 +0200)
etc/afpd/spotlight.c
etc/afpd/spotlight_marshalling.c

index 2d9d6315e1ee6df933f89ca745ce0623e306cca0..8eb26a7eb7fddea7b0626a6d525ac0e9a8d6ebbe 100644 (file)
@@ -204,9 +204,12 @@ int afp_spotlight_rpc(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_
         DALLOC_CTX *reply;
         EC_NULL( reply = talloc_zero(tmp_ctx, DALLOC_CTX) );
 
-        EC_ZERO( sl_unpack(query, ibuf + 22) );
+        ret = sl_unpack(query, ibuf + 22);
         dd_dump(query, 0);
-
+        if (ret != 0) {
+            LOG(log_error, logtype_sl, "sl_unpack");
+            EC_FAIL;
+        }
         char **cmd;
         EC_NULL_LOG( cmd = dalloc_get(query, "DALLOC_CTX", 0, "DALLOC_CTX", 0, "char *", 0) );
 
@@ -304,6 +307,7 @@ int main(int argc, char **argv)
 
 #endif
 
+#if 0
     /* Now the Spotlight types */
     sl_array_t *sl_arrary = talloc_zero(dd, sl_array_t);
     i = 0x1234;
@@ -316,25 +320,29 @@ int main(int argc, char **argv)
 
     dalloc_add(dd, sl_arrary, sl_array_t);
     dd_dump(dd, 0);
+#endif
 
     /* now parse a real spotlight packet */
-    char ibuf[8192];
-    char rbuf[8192];
-    int fd;
-    size_t len;
-    DALLOC_CTX *query;
+    if (argc > 1) {
+        char ibuf[8192];
+        char rbuf[8192];
+        int fd;
+        size_t len;
+        DALLOC_CTX *query;
 
-    EC_NULL( query = talloc_zero(mem_ctx, DALLOC_CTX) );
+        EC_NULL( query = talloc_zero(mem_ctx, DALLOC_CTX) );
 
-    EC_NEG1_LOG( fd = open("openQuery-packet.bin", O_RDONLY) );
-    EC_NEG1_LOG( len = read(fd, ibuf, 8192) );
-    close(fd);
-    EC_NEG1_LOG( sl_unpack(query, ibuf + 24) );
+        EC_NEG1_LOG( fd = open(argv[1], O_RDONLY) );
+        EC_NEG1_LOG( len = read(fd, ibuf, 8192) );
+        close(fd);
+        EC_NEG1_LOG( sl_unpack(query, ibuf + 24) );
 
-    /* Now dump the whole thing */
-    dd_dump(query, 0);
+        /* Now dump the whole thing */
+        dd_dump(query, 0);
+    }
 
 #if 0
+    /* packing  */
     int qlen;
     char buf[MAX_SLQ_DAT];
     EC_NEG1_LOG( qlen = sl_pack(query, buf) );
index d338b590124f06bf90b2fbc7d21912e93dfc4493..d01d59d9b7af5eb62b0928106c447eda215667bd 100644 (file)
@@ -485,7 +485,7 @@ static int sl_unpack_cpx(DALLOC_CTX *query,
     uint unicode_encoding;
     uint8_t mark_exists;
     char *p;
-    int qlen, padding, slen;
+    int qlen, used_in_last_block, slen;
     sl_array_t *sl_arrary;
     sl_dict_t *sl_dict;
 
@@ -506,10 +506,8 @@ static int sl_unpack_cpx(DALLOC_CTX *query,
     case SQ_CPX_TYPE_UTF16_STRING:
         query_data64 = sl_unpack_uint64(buf, offset, encoding);
         qlen = (query_data64 & 0xffff) * 8;
-        if ((padding = 8 - (query_data64 >> 32)) < 0)
-            EC_FAIL;
-        if ((slen = qlen - 8 - padding) < 1)
-            EC_FAIL;
+        used_in_last_block = query_data64 >> 32;
+        slen = qlen - 8 + used_in_last_block;
 
         if (cpx_query_type == SQ_CPX_TYPE_STRING) {
             p = talloc_strndup(query, buf + offset + 8, slen);