]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/spotlight_marshalling.c
Fix string length calculation for empty strings
[netatalk.git] / etc / afpd / spotlight_marshalling.c
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);