diff options
author | Gerald Carter <jerry@samba.org> | 2000-08-04 12:42:19 +0000 |
---|---|---|
committer | Gerald Carter <jerry@samba.org> | 2000-08-04 12:42:19 +0000 |
commit | 394795e28b00eb95759938770cd24ee7c75ed39d (patch) | |
tree | 7a1f8e5b5df2b88259a06248df4b14b6cc9a1884 /source3/rpc_parse | |
parent | 553579bf6fd7c9dfecddddc1f6272b523bce69d9 (diff) | |
download | samba-394795e28b00eb95759938770cd24ee7c75ed39d.tar.gz samba-394795e28b00eb95759938770cd24ee7c75ed39d.tar.bz2 samba-394795e28b00eb95759938770cd24ee7c75ed39d.zip |
After talking with Jeremy and JF (and staring at packet traces between
NT <-> NT), I've come to realize that UNISTR2 strings should be NULL
terminated.
jerry
(This used to be commit c8f9e54beafcb0c0668f1510e7693dbf22485aa8)
Diffstat (limited to 'source3/rpc_parse')
-rw-r--r-- | source3/rpc_parse/parse_misc.c | 54 |
1 files changed, 52 insertions, 2 deletions
diff --git a/source3/rpc_parse/parse_misc.c b/source3/rpc_parse/parse_misc.c index 276e66a113..c0b700c908 100644 --- a/source3/rpc_parse/parse_misc.c +++ b/source3/rpc_parse/parse_misc.c @@ -852,14 +852,14 @@ void init_unistr2(UNISTR2 *str, const char *buf, size_t len) str->undoc = 0; str->uni_str_len = (uint32)len; - if (!parse_misc_talloc) + if (!parse_misc_talloc) parse_misc_talloc = talloc_init(); if (len < MAX_UNISTRLEN) len = MAX_UNISTRLEN; len *= sizeof(uint16); - str->buffer = (uint16 *)talloc(parse_misc_talloc, len); + str->buffer = (uint16 *)talloc(parse_misc_talloc, len); if (str->buffer == NULL) smb_panic("init_unistr2: malloc fail\n"); @@ -868,6 +868,56 @@ void init_unistr2(UNISTR2 *str, const char *buf, size_t len) } /******************************************************************* + Inits a UNISTR2 structure from a UNISTR +********************************************************************/ +void init_unistr2_from_unistr (UNISTR2 *to, UNISTR *from) +{ + + BOOL found; + uint32 i = 0; + + if ((to == NULL) || (from == NULL) || (from->buffer == NULL)) + return; + + ZERO_STRUCTP (to); + + /* get the length; UNISTR **are** NULL terminated */ + found = False; + while (!found) + { + if ((from->buffer)[i]=='\0' && (from->buffer)[(2*i)+1]=='\0') + found = True; + else + i++; + } + i++; + + if (!found) + { + DEBUG(0,("init_unistr2_from_unistr: non-null terminiated UNISTR!\n")); + return; + } + + /* set up string lengths. */ + to->uni_max_len = i; + to->undoc = 0; + to->uni_str_len = i; + + if (!parse_misc_talloc) + parse_misc_talloc = talloc_init(); + + to->buffer = (uint16 *)talloc(parse_misc_talloc, sizeof(uint16)*(to->uni_str_len)); + if (to->buffer == NULL) + smb_panic("init_unistr2_from_unistr: malloc fail\n"); + + for (i=0; i < to->uni_str_len; i++) + to->buffer[i] = from->buffer[i]; + + return; +} + + +/******************************************************************* Reads or writes a UNISTR2 structure. XXXX NOTE: UNISTR2 structures need NOT be null-terminated. the uni_str_len member tells you how long the string is; |