title: How can a string value stored in the registry not be null terminated?
body: <p><a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms724911(v=vs.85).aspx" rel="nofollow">Documentation for function</a> <strong>RegQueryValueEx</strong> says that</p>
  
  <blockquote>
    <p>If the data has the REG_SZ, REG_MULTI_SZ or REG_EXPAND_SZ type, the string may not have been stored with the proper terminating null characters.</p>
  </blockquote>
  
  <p><strong>My question is:</strong> based on that statement, if we have a string value in a Windows registry key, what are the cases where the string would be properly terminated and what are the cases where the string would not be? Is a not null terminated string registry value even valid and natively usable by the system?</p>
  
  <p>At the registry level, is there anything we can do to make sure that, once read by the RegQueryValueEx function, the string will be properly terminated in the program?</p>
  
  <p>My guess is that this warning only applies to when the value is programmatically inserted, as opposed to being added manually through the Windows registry editor, in which case the string would for sure be null terminated, is that right?</p>
  
  <p>Please note that the documentation also mentions that function <strong>RegGetValue</strong> can be used to ensure properly terminated strings, but this is not my question here.</p>