s3:registry: fix the test for a REG_SZ blob possibly being a zero terminated ucs2...
authorMichael Adam <obnox@samba.org>
Thu, 29 Sep 2011 16:06:56 +0000 (18:06 +0200)
committerMichael Adam <obnox@samba.org>
Tue, 11 Oct 2011 13:21:19 +0000 (15:21 +0200)
1. catch data blobs with odd number of bytes (not an ucs2 string at all)
2. test the right ucs2 character to be 0
   (prevent out-of bounds access/potential segfault)

source3/registry/reg_format.c

index c9f823349709bea2c82bb5296c480dee6421f193..78e5e820a34c941984863ad33bbd01677c3d7c3e 100644 (file)
@@ -328,7 +328,16 @@ done:
 static bool is_zero_terminated_ucs2(const uint8_t* data, size_t len) {
        const size_t idx = len/sizeof(smb_ucs2_t);
        const smb_ucs2_t *str = (const smb_ucs2_t*)data;
-       return (idx > 0) && (str[idx] == 0);
+
+       if ((len % sizeof(smb_ucs2_t)) != 0) {
+               return false;
+       }
+
+       if (idx == 0) {
+               return false;
+       }
+
+       return (str[idx-1] == 0);
 }
 
 int reg_format_value(struct reg_format* f, const char* name, uint32_t type,