project
stringclasses
633 values
commit_id
stringlengths
7
81
target
int64
0
1
func
stringlengths
5
484k
cwe
stringclasses
131 values
big_vul_idx
float64
0
189k
idx
int64
0
522k
hash
stringlengths
34
39
size
float64
1
24k
message
stringlengths
0
11.5k
dataset
stringclasses
1 value
mindrot
1bf477d3cdf1a864646d59820878783d42357a1d
0
enter_non_blocking(void) { in_non_blocking_mode = 1; set_nonblock(fileno(stdin)); }
CWE-264
2,265
12,627
329961352055795089384303047370156189312
null
null
null
mindrot
1bf477d3cdf1a864646d59820878783d42357a1d
0
leave_non_blocking(void) { if (in_non_blocking_mode) { unset_nonblock(fileno(stdin)); in_non_blocking_mode = 0; } }
CWE-264
2,267
12,628
141313044677185185986702359295591896469
null
null
null
mindrot
1bf477d3cdf1a864646d59820878783d42357a1d
0
set_control_persist_exit_time(void) { if (muxserver_sock == -1 || !options.control_persist || options.control_persist_timeout == 0) { /* not using a ControlPersist timeout */ control_persist_exit_time = 0; } else if (channel_still_open()) { /* some client connections are still open */ if (control_persist_exit_time > 0) debug2("%s: cancel scheduled exit", __func__); control_persist_exit_time = 0; } else if (control_persist_exit_time <= 0) { /* a client connection has recently closed */ control_persist_exit_time = monotime() + (time_t)options.control_persist_timeout; debug2("%s: schedule exit in %d seconds", __func__, options.control_persist_timeout); } /* else we are already counting down to the timeout */ }
CWE-264
2,268
12,629
62833982238575625725754676175146687750
null
null
null
mindrot
1bf477d3cdf1a864646d59820878783d42357a1d
0
signal_handler(int sig) { received_signal = sig; quit_pending = 1; }
CWE-264
2,269
12,630
56379792985041788028615944067619108928
null
null
null
mindrot
1bf477d3cdf1a864646d59820878783d42357a1d
0
window_change_handler(int sig) { received_window_change_signal = 1; signal(SIGWINCH, window_change_handler); }
CWE-264
2,270
12,631
194942740893137321051320215468555320116
null
null
null
samba
538d305de91e34a2938f5f219f18bf0e1918763f
0
const char *charset_name(struct smb_iconv_handle *ic, charset_t ch) { switch (ch) { case CH_UTF16: return "UTF-16LE"; case CH_UNIX: return ic->unix_charset; case CH_DOS: return ic->dos_charset; case CH_UTF8: return "UTF8"; case CH_UTF16BE: return "UTF-16BE"; case CH_UTF16MUNGED: return "UTF16_MUNGED"; default: return "ASCII"; } }
CWE-200
2,271
12,632
233192837848886427766249056822235216391
null
null
null
samba
538d305de91e34a2938f5f219f18bf0e1918763f
0
static int close_iconv_handle(struct smb_iconv_handle *data) { unsigned c1, c2; for (c1=0;c1<NUM_CHARSETS;c1++) { for (c2=0;c2<NUM_CHARSETS;c2++) { if (data->conv_handles[c1][c2] != NULL) { if (data->conv_handles[c1][c2] != (smb_iconv_t)-1) { smb_iconv_close(data->conv_handles[c1][c2]); } data->conv_handles[c1][c2] = NULL; } } } return 0; }
CWE-200
2,272
12,633
187027597378025017017488491906687230317
null
null
null
samba
538d305de91e34a2938f5f219f18bf0e1918763f
0
_PUBLIC_ int codepoint_cmpi(codepoint_t c1, codepoint_t c2) { if (c1 == c2 || toupper_m(c1) == toupper_m(c2)) { return 0; } return c1 - c2; }
CWE-200
2,273
12,634
31699061154637392118710589546514833629
null
null
null
samba
538d305de91e34a2938f5f219f18bf0e1918763f
0
smb_iconv_t get_conv_handle(struct smb_iconv_handle *ic, charset_t from, charset_t to) { const char *n1, *n2; if (ic->conv_handles[from][to]) { return ic->conv_handles[from][to]; } n1 = charset_name(ic, from); n2 = charset_name(ic, to); ic->conv_handles[from][to] = smb_iconv_open_ex(ic, n2, n1, ic->use_builtin_handlers); if (ic->conv_handles[from][to] == (smb_iconv_t)-1) { if ((from == CH_DOS || to == CH_DOS) && strcasecmp(charset_name(ic, CH_DOS), "ASCII") != 0) { DEBUG(0,("dos charset '%s' unavailable - using ASCII\n", charset_name(ic, CH_DOS))); ic->dos_charset = "ASCII"; n1 = charset_name(ic, from); n2 = charset_name(ic, to); ic->conv_handles[from][to] = smb_iconv_open_ex(ic, n2, n1, ic->use_builtin_handlers); } } return ic->conv_handles[from][to]; }
CWE-200
2,274
12,635
156692719763921405619931500676710613444
null
null
null
samba
538d305de91e34a2938f5f219f18bf0e1918763f
0
struct smb_iconv_handle *get_iconv_handle(void) { if (global_iconv_handle == NULL) global_iconv_handle = smb_iconv_handle_reinit(talloc_autofree_context(), "ASCII", "UTF-8", true, NULL); return global_iconv_handle; }
CWE-200
2,275
12,636
290845732384704007103473714405137076720
null
null
null
samba
538d305de91e34a2938f5f219f18bf0e1918763f
0
struct smb_iconv_handle *get_iconv_testing_handle(TALLOC_CTX *mem_ctx, const char *dos_charset, const char *unix_charset, bool use_builtin_handlers) { return smb_iconv_handle_reinit(mem_ctx, dos_charset, unix_charset, use_builtin_handlers, NULL); }
CWE-200
2,276
12,637
38740355432323192717707865639793352728
null
null
null
samba
538d305de91e34a2938f5f219f18bf0e1918763f
0
_PUBLIC_ bool islower_m(codepoint_t val) { return (toupper_m(val) != val); }
CWE-200
2,277
12,638
296640697051309850384629543144435096282
null
null
null
samba
538d305de91e34a2938f5f219f18bf0e1918763f
0
_PUBLIC_ bool isupper_m(codepoint_t val) { return (tolower_m(val) != val); }
CWE-200
2,278
12,639
163716729019137168570078711005911471966
null
null
null
samba
538d305de91e34a2938f5f219f18bf0e1918763f
0
_PUBLIC_ codepoint_t next_codepoint_ext(const char *str, size_t len, charset_t src_charset, size_t *size) { return next_codepoint_handle_ext(get_iconv_handle(), str, len, src_charset, size); }
CWE-200
2,280
12,640
135822479671111046003852868231941376149
null
null
null
samba
538d305de91e34a2938f5f219f18bf0e1918763f
0
_PUBLIC_ codepoint_t next_codepoint_handle(struct smb_iconv_handle *ic, const char *str, size_t *size) { /* * We assume that no multi-byte character can take more than 5 bytes * thus avoiding walking all the way down a long string. This is OK as * Unicode codepoints only go up to (U+10ffff), which can always be * encoded in 4 bytes or less. */ return next_codepoint_handle_ext(ic, str, strnlen(str, 5), CH_UNIX, size); }
CWE-200
2,281
12,641
303558994972892862344836979238059540233
null
null
null
samba
538d305de91e34a2938f5f219f18bf0e1918763f
0
_PUBLIC_ ssize_t push_codepoint(char *str, codepoint_t c) { return push_codepoint_handle(get_iconv_handle(), str, c); }
CWE-200
2,282
12,642
119023870062579830498481069786884027673
null
null
null
samba
538d305de91e34a2938f5f219f18bf0e1918763f
0
_PUBLIC_ ssize_t push_codepoint_handle(struct smb_iconv_handle *ic, char *str, codepoint_t c) { smb_iconv_t descriptor; uint8_t buf[4]; size_t ilen, olen; const char *inbuf; if (c < 128) { *str = c; return 1; } descriptor = get_conv_handle(ic, CH_UTF16, CH_UNIX); if (descriptor == (smb_iconv_t)-1) { return -1; } if (c < 0x10000) { ilen = 2; olen = 5; inbuf = (char *)buf; SSVAL(buf, 0, c); smb_iconv(descriptor, &inbuf, &ilen, &str, &olen); if (ilen != 0) { return -1; } return 5 - olen; } c -= 0x10000; buf[0] = (c>>10) & 0xFF; buf[1] = (c>>18) | 0xd8; buf[2] = c & 0xFF; buf[3] = ((c>>8) & 0x3) | 0xdc; ilen = 4; olen = 5; inbuf = (char *)buf; smb_iconv(descriptor, &inbuf, &ilen, &str, &olen); if (ilen != 0) { return -1; } return 5 - olen; }
CWE-200
2,283
12,643
288060792323293437509694342227367978687
null
null
null
samba
538d305de91e34a2938f5f219f18bf0e1918763f
0
_PUBLIC_ struct smb_iconv_handle *smb_iconv_handle_reinit(TALLOC_CTX *mem_ctx, const char *dos_charset, const char *unix_charset, bool use_builtin_handlers, struct smb_iconv_handle *old_ic) { struct smb_iconv_handle *ret; if (old_ic != NULL) { ret = old_ic; close_iconv_handle(ret); talloc_free(ret->child_ctx); ZERO_STRUCTP(ret); } else { ret = talloc_zero(mem_ctx, struct smb_iconv_handle); } if (ret == NULL) { return NULL; } /* we use a child context to allow us to free all ptrs without freeing the structure itself */ ret->child_ctx = talloc_new(ret); if (ret->child_ctx == NULL) { return NULL; } talloc_set_destructor(ret, close_iconv_handle); if (strcasecmp(dos_charset, "UTF8") == 0 || strcasecmp(dos_charset, "UTF-8") == 0) { DEBUG(0,("ERROR: invalid DOS charset: 'dos charset' must not be UTF8, using (default value) CP850 instead\n")); dos_charset = "CP850"; } ret->dos_charset = talloc_strdup(ret->child_ctx, dos_charset); ret->unix_charset = talloc_strdup(ret->child_ctx, unix_charset); ret->use_builtin_handlers = use_builtin_handlers; return ret; }
CWE-200
2,284
12,644
298874279270389167324882822060087587230
null
null
null
samba
538d305de91e34a2938f5f219f18bf0e1918763f
0
void smb_init_locale(void) { /* This is a useful global hook where we can ensure that the * locale is set from the environment. This is needed so that * we can use LOCALE as a codepage */ #ifdef HAVE_SETLOCALE setlocale(LC_ALL, ""); #endif }
CWE-200
2,285
12,645
275665189933891137581536077023124772936
null
null
null
samba
538d305de91e34a2938f5f219f18bf0e1918763f
0
_PUBLIC_ codepoint_t tolower_m(codepoint_t val) { if (val < 128) { return tolower(val); } if (val >= ARRAY_SIZE(lowcase_table)) { return val; } return lowcase_table[val]; }
CWE-200
2,286
12,646
3894238155682092505021790842491224661
null
null
null
samba
538d305de91e34a2938f5f219f18bf0e1918763f
0
_PUBLIC_ codepoint_t toupper_m(codepoint_t val) { if (val < 128) { return toupper(val); } if (val >= ARRAY_SIZE(upcase_table)) { return val; } return upcase_table[val]; }
CWE-200
2,287
12,647
84327013719736200055413109940637840318
null
null
null
samba
7f51ec8c4ed9ba1f53d722e44fb6fb3cde933b72
0
struct ldb_dn *ldb_dn_from_ldb_val(TALLOC_CTX *mem_ctx, struct ldb_context *ldb, const struct ldb_val *strdn) { struct ldb_dn *dn; if (! ldb) return NULL; if (strdn && strdn->data && (strnlen((const char*)strdn->data, strdn->length) != strdn->length)) { /* The RDN must not contain a character with value 0x0 */ return NULL; } dn = talloc_zero(mem_ctx, struct ldb_dn); LDB_DN_NULL_FAILED(dn); dn->ldb = talloc_get_type(ldb, struct ldb_context); if (dn->ldb == NULL) { /* the caller probably got the arguments to ldb_dn_new() mixed up */ talloc_free(dn); return NULL; } if (strdn->data && strdn->length) { const char *data = (const char *)strdn->data; size_t length = strdn->length; if (data[0] == '@') { dn->special = true; } dn->ext_linearized = talloc_strndup(dn, data, length); LDB_DN_NULL_FAILED(dn->ext_linearized); if (data[0] == '<') { const char *p_save, *p = dn->ext_linearized; do { p_save = p; p = strstr(p, ">;"); if (p) { p = p + 2; } } while (p); if (p_save == dn->ext_linearized) { dn->linearized = talloc_strdup(dn, ""); } else { dn->linearized = talloc_strdup(dn, p_save); } LDB_DN_NULL_FAILED(dn->linearized); } else { dn->linearized = dn->ext_linearized; dn->ext_linearized = NULL; } } else { dn->linearized = talloc_strdup(dn, ""); LDB_DN_NULL_FAILED(dn->linearized); } return dn; failed: talloc_free(dn); return NULL; }
CWE-200
2,288
12,648
212838933071052705133807298079791172112
null
null
null
samba
7f51ec8c4ed9ba1f53d722e44fb6fb3cde933b72
0
static void ldb_dn_mark_invalid(struct ldb_dn *dn) { dn->invalid = true; }
CWE-200
2,289
12,649
239027621047138971294319260175836090333
null
null
null
samba
7f51ec8c4ed9ba1f53d722e44fb6fb3cde933b72
0
struct ldb_dn *ldb_dn_new_fmt(TALLOC_CTX *mem_ctx, struct ldb_context *ldb, const char *new_fmt, ...) { char *strdn; va_list ap; if ( (! mem_ctx) || (! ldb)) return NULL; va_start(ap, new_fmt); strdn = talloc_vasprintf(mem_ctx, new_fmt, ap); va_end(ap); if (strdn) { struct ldb_dn *dn = ldb_dn_new(mem_ctx, ldb, strdn); talloc_free(strdn); return dn; } return NULL; }
CWE-200
2,291
12,650
138629595239075554762179194498050473260
null
null
null
samba
a118d4220ed85749c07fb43c1229d9e2fecbea6b
0
_PUBLIC_ size_t count_chars_m(const char *s, char c) { struct smb_iconv_handle *ic = get_iconv_handle(); size_t count = 0; while (*s) { size_t size; codepoint_t c2 = next_codepoint_handle(ic, s, &size); if (c2 == c) count++; s += size; } return count; }
CWE-200
2,292
12,651
139489475137668035034734128772947192801
null
null
null
samba
a118d4220ed85749c07fb43c1229d9e2fecbea6b
0
static ssize_t pull_ascii_string(char *dest, const void *src, size_t dest_len, size_t src_len, int flags) { size_t size = 0; if (flags & (STR_TERMINATE | STR_TERMINATE_ASCII)) { if (src_len == (size_t)-1) { src_len = strlen((const char *)src) + 1; } else { size_t len = strnlen((const char *)src, src_len); if (len < src_len) len++; src_len = len; } } /* We're ignoring the return here.. */ (void)convert_string(CH_DOS, CH_UNIX, src, src_len, dest, dest_len, &size); if (dest_len) dest[MIN(size, dest_len-1)] = 0; return src_len; }
CWE-200
2,293
12,652
228461200795612246192929879982803491085
null
null
null
samba
a118d4220ed85749c07fb43c1229d9e2fecbea6b
0
_PUBLIC_ ssize_t pull_string(char *dest, const void *src, size_t dest_len, size_t src_len, int flags) { if (flags & STR_ASCII) { return pull_ascii_string(dest, src, dest_len, src_len, flags); } else if (flags & STR_UNICODE) { return pull_ucs2(dest, src, dest_len, src_len, flags); } else { smb_panic("pull_string requires either STR_ASCII or STR_UNICODE flag to be set"); return -1; } }
CWE-200
2,294
12,653
300330129343826979593372960272553595139
null
null
null
samba
a118d4220ed85749c07fb43c1229d9e2fecbea6b
0
static size_t pull_ucs2(char *dest, const void *src, size_t dest_len, size_t src_len, int flags) { size_t size = 0; if (ucs2_align(NULL, src, flags)) { src = (const void *)((const char *)src + 1); if (src_len > 0) src_len--; } if (flags & STR_TERMINATE) { if (src_len == (size_t)-1) { src_len = utf16_len(src); } else { src_len = utf16_len_n(src, src_len); } } /* ucs2 is always a multiple of 2 bytes */ if (src_len != (size_t)-1) src_len &= ~1; /* We're ignoring the return here.. */ (void)convert_string(CH_UTF16, CH_UNIX, src, src_len, dest, dest_len, &size); if (dest_len) dest[MIN(size, dest_len-1)] = 0; return src_len; }
CWE-200
2,295
12,654
240090087980032051092699124600426387301
null
null
null
samba
a118d4220ed85749c07fb43c1229d9e2fecbea6b
0
static bool push_ascii_string(void *dest, const char *src, size_t dest_len, int flags, size_t *converted_size) { size_t src_len; bool ret; if (flags & STR_UPPER) { char *tmpbuf = strupper_talloc(NULL, src); if (tmpbuf == NULL) { return false; } ret = push_ascii_string(dest, tmpbuf, dest_len, flags & ~STR_UPPER, converted_size); talloc_free(tmpbuf); return ret; } src_len = strlen(src); if (flags & (STR_TERMINATE | STR_TERMINATE_ASCII)) src_len++; return convert_string(CH_UNIX, CH_DOS, src, src_len, dest, dest_len, converted_size); }
CWE-200
2,296
12,655
226745245022481525911303459204325275344
null
null
null
samba
a118d4220ed85749c07fb43c1229d9e2fecbea6b
0
_PUBLIC_ ssize_t push_string(void *dest, const char *src, size_t dest_len, int flags) { if (flags & STR_ASCII) { size_t size = 0; if (push_ascii_string(dest, src, dest_len, flags, &size)) { return (ssize_t)size; } else { return (ssize_t)-1; } } else if (flags & STR_UNICODE) { return push_ucs2(dest, src, dest_len, flags); } else { smb_panic("push_string requires either STR_ASCII or STR_UNICODE flag to be set"); return -1; } }
CWE-200
2,297
12,656
133391718816535665737855534484580569791
null
null
null
samba
a118d4220ed85749c07fb43c1229d9e2fecbea6b
0
static ssize_t push_ucs2(void *dest, const char *src, size_t dest_len, int flags) { size_t len=0; size_t src_len = strlen(src); size_t size = 0; bool ret; if (flags & STR_UPPER) { char *tmpbuf = strupper_talloc(NULL, src); ssize_t retval; if (tmpbuf == NULL) { return -1; } retval = push_ucs2(dest, tmpbuf, dest_len, flags & ~STR_UPPER); talloc_free(tmpbuf); return retval; } if (flags & STR_TERMINATE) src_len++; if (ucs2_align(NULL, dest, flags)) { *(char *)dest = 0; dest = (void *)((char *)dest + 1); if (dest_len) dest_len--; len++; } /* ucs2 is always a multiple of 2 bytes */ dest_len &= ~1; ret = convert_string(CH_UNIX, CH_UTF16, src, src_len, dest, dest_len, &size); if (ret == false) { return 0; } len += size; return (ssize_t)len; }
CWE-200
2,298
12,657
178918745739087443678144115903081371045
null
null
null
samba
a118d4220ed85749c07fb43c1229d9e2fecbea6b
0
_PUBLIC_ void string_replace_m(char *s, char oldc, char newc) { struct smb_iconv_handle *ic = get_iconv_handle(); while (s && *s) { size_t size; codepoint_t c = next_codepoint_handle(ic, s, &size); if (c == oldc) { *s = newc; } s += size; } }
CWE-200
2,299
12,658
30500282022148325647734401182821074857
null
null
null
samba
a118d4220ed85749c07fb43c1229d9e2fecbea6b
0
_PUBLIC_ char *strlower_talloc(TALLOC_CTX *ctx, const char *src) { struct smb_iconv_handle *iconv_handle = get_iconv_handle(); return strlower_talloc_handle(iconv_handle, ctx, src); }
CWE-200
2,300
12,659
328365277199813897368643269488878531070
null
null
null
samba
a118d4220ed85749c07fb43c1229d9e2fecbea6b
0
_PUBLIC_ char *strupper_talloc(TALLOC_CTX *ctx, const char *src) { return strupper_talloc_n(ctx, src, src?strlen(src):0); }
CWE-200
2,302
12,660
62298516514917346038248444790833194082
null
null
null
samba
a118d4220ed85749c07fb43c1229d9e2fecbea6b
0
_PUBLIC_ char *strupper_talloc_n(TALLOC_CTX *ctx, const char *src, size_t n) { struct smb_iconv_handle *iconv_handle = get_iconv_handle(); return strupper_talloc_n_handle(iconv_handle, ctx, src, n); }
CWE-200
2,303
12,661
98337191942563692586005930220407579942
null
null
null
samba
a118d4220ed85749c07fb43c1229d9e2fecbea6b
0
_PUBLIC_ char *talloc_strdup_upper(TALLOC_CTX *ctx, const char *src) { return strupper_talloc(ctx, src); }
CWE-200
2,304
12,662
94893196964512649930809852211011515010
null
null
null
samba
f36cb71c330a52106e36028b3029d952257baf15
0
static int ldb_dn_escape_internal(char *dst, const char *src, int len) { char c; char *d; int i; d = dst; for (i = 0; i < len; i++){ c = src[i]; switch (c) { case ' ': if (i == 0 || i == len - 1) { /* if at the beginning or end * of the string then escape */ *d++ = '\\'; *d++ = c; } else { /* otherwise don't escape */ *d++ = c; } break; case '#': /* despite the RFC, windows escapes a # anywhere in the string */ case ',': case '+': case '"': case '\\': case '<': case '>': case '?': /* these must be escaped using \c form */ *d++ = '\\'; *d++ = c; break; case ';': case '\r': case '\n': case '=': case '\0': { /* any others get \XX form */ unsigned char v; const char *hexbytes = "0123456789ABCDEF"; v = (const unsigned char)c; *d++ = '\\'; *d++ = hexbytes[v>>4]; *d++ = hexbytes[v&0xF]; break; } default: *d++ = c; } } /* return the length of the resulting string */ return (d - dst); }
CWE-200
2,323
12,681
212050428278128788629085442443267574603
null
null
null
samba
0454b95657846fcecf0f51b6f1194faac02518bd
0
bool ldb_dn_add_base(struct ldb_dn *dn, struct ldb_dn *base) { const char *s; char *t; if ( !base || base->invalid || !dn || dn->invalid) { return false; } if (dn->components) { unsigned int i; if ( ! ldb_dn_validate(base)) { return false; } s = NULL; if (dn->valid_case) { if ( ! (s = ldb_dn_get_casefold(base))) { return false; } } dn->components = talloc_realloc(dn, dn->components, struct ldb_dn_component, dn->comp_num + base->comp_num); if ( ! dn->components) { ldb_dn_mark_invalid(dn); return false; } for (i = 0; i < base->comp_num; dn->comp_num++, i++) { dn->components[dn->comp_num] = ldb_dn_copy_component(dn->components, &base->components[i]); if (dn->components[dn->comp_num].value.data == NULL) { ldb_dn_mark_invalid(dn); return false; } } if (dn->casefold && s) { if (*dn->casefold) { t = talloc_asprintf(dn, "%s,%s", dn->casefold, s); } else { t = talloc_strdup(dn, s); } LDB_FREE(dn->casefold); dn->casefold = t; } } if (dn->linearized) { s = ldb_dn_get_linearized(base); if ( ! s) { return false; } if (*dn->linearized) { t = talloc_asprintf(dn, "%s,%s", dn->linearized, s); } else { t = talloc_strdup(dn, s); } if ( ! t) { ldb_dn_mark_invalid(dn); return false; } LDB_FREE(dn->linearized); dn->linearized = t; } /* Wipe the ext_linearized DN, * the GUID and SID are almost certainly no longer valid */ LDB_FREE(dn->ext_linearized); LDB_FREE(dn->ext_components); dn->ext_comp_num = 0; return true; }
CWE-200
2,324
12,682
122460871743697490560919012866763720117
null
null
null
samba
0454b95657846fcecf0f51b6f1194faac02518bd
0
bool ldb_dn_add_base_fmt(struct ldb_dn *dn, const char *base_fmt, ...) { struct ldb_dn *base; char *base_str; va_list ap; bool ret; if ( !dn || dn->invalid) { return false; } va_start(ap, base_fmt); base_str = talloc_vasprintf(dn, base_fmt, ap); va_end(ap); if (base_str == NULL) { return false; } base = ldb_dn_new(base_str, dn->ldb, base_str); ret = ldb_dn_add_base(dn, base); talloc_free(base_str); return ret; }
CWE-200
2,325
12,683
10498452902837536691376457486532418170
null
null
null
samba
0454b95657846fcecf0f51b6f1194faac02518bd
0
bool ldb_dn_add_child(struct ldb_dn *dn, struct ldb_dn *child) { const char *s; char *t; if ( !child || child->invalid || !dn || dn->invalid) { return false; } if (dn->components) { unsigned int n; unsigned int i, j; if (dn->comp_num == 0) { return false; } if ( ! ldb_dn_validate(child)) { return false; } s = NULL; if (dn->valid_case) { if ( ! (s = ldb_dn_get_casefold(child))) { return false; } } n = dn->comp_num + child->comp_num; dn->components = talloc_realloc(dn, dn->components, struct ldb_dn_component, n); if ( ! dn->components) { ldb_dn_mark_invalid(dn); return false; } for (i = dn->comp_num - 1, j = n - 1; i != (unsigned int) -1; i--, j--) { dn->components[j] = dn->components[i]; } for (i = 0; i < child->comp_num; i++) { dn->components[i] = ldb_dn_copy_component(dn->components, &child->components[i]); if (dn->components[i].value.data == NULL) { ldb_dn_mark_invalid(dn); return false; } } dn->comp_num = n; if (dn->casefold && s) { t = talloc_asprintf(dn, "%s,%s", s, dn->casefold); LDB_FREE(dn->casefold); dn->casefold = t; } } if (dn->linearized) { if (dn->linearized[0] == '\0') { return false; } s = ldb_dn_get_linearized(child); if ( ! s) { return false; } t = talloc_asprintf(dn, "%s,%s", s, dn->linearized); if ( ! t) { ldb_dn_mark_invalid(dn); return false; } LDB_FREE(dn->linearized); dn->linearized = t; } /* Wipe the ext_linearized DN, * the GUID and SID are almost certainly no longer valid */ LDB_FREE(dn->ext_linearized); LDB_FREE(dn->ext_components); dn->ext_comp_num = 0; return true; }
CWE-200
2,326
12,684
19704549953290678319485857119972368152
null
null
null
samba
0454b95657846fcecf0f51b6f1194faac02518bd
0
bool ldb_dn_add_child_fmt(struct ldb_dn *dn, const char *child_fmt, ...) { struct ldb_dn *child; char *child_str; va_list ap; bool ret; if ( !dn || dn->invalid) { return false; } va_start(ap, child_fmt); child_str = talloc_vasprintf(dn, child_fmt, ap); va_end(ap); if (child_str == NULL) { return false; } child = ldb_dn_new(child_str, dn->ldb, child_str); ret = ldb_dn_add_child(dn, child); talloc_free(child_str); return ret; }
CWE-200
2,327
12,685
201408732261746984773447843768387890561
null
null
null
samba
0454b95657846fcecf0f51b6f1194faac02518bd
0
static char *ldb_dn_canonical(TALLOC_CTX *mem_ctx, struct ldb_dn *dn, int ex_format) { unsigned int i; TALLOC_CTX *tmpctx; char *cracked = NULL; const char *format = (ex_format ? "\n" : "/" ); if ( ! ldb_dn_validate(dn)) { return NULL; } tmpctx = talloc_new(mem_ctx); /* Walk backwards down the DN, grabbing 'dc' components at first */ for (i = dn->comp_num - 1; i != (unsigned int) -1; i--) { if (ldb_attr_cmp(dn->components[i].name, "dc") != 0) { break; } if (cracked) { cracked = talloc_asprintf(tmpctx, "%s.%s", ldb_dn_escape_value(tmpctx, dn->components[i].value), cracked); } else { cracked = ldb_dn_escape_value(tmpctx, dn->components[i].value); } if (!cracked) { goto done; } } /* Only domain components? Finish here */ if (i == (unsigned int) -1) { cracked = talloc_strdup_append_buffer(cracked, format); talloc_steal(mem_ctx, cracked); goto done; } /* Now walk backwards appending remaining components */ for (; i > 0; i--) { cracked = talloc_asprintf_append_buffer(cracked, "/%s", ldb_dn_escape_value(tmpctx, dn->components[i].value)); if (!cracked) { goto done; } } /* Last one, possibly a newline for the 'ex' format */ cracked = talloc_asprintf_append_buffer(cracked, "%s%s", format, ldb_dn_escape_value(tmpctx, dn->components[i].value)); talloc_steal(mem_ctx, cracked); done: talloc_free(tmpctx); return cracked; }
CWE-200
2,329
12,686
279077409659946574171798384319030550896
null
null
null
samba
0454b95657846fcecf0f51b6f1194faac02518bd
0
char *ldb_dn_canonical_ex_string(TALLOC_CTX *mem_ctx, struct ldb_dn *dn) { return ldb_dn_canonical(mem_ctx, dn, 1); }
CWE-200
2,330
12,687
273560458587794849985167229151191265164
null
null
null
samba
0454b95657846fcecf0f51b6f1194faac02518bd
0
static bool ldb_dn_casefold_internal(struct ldb_dn *dn) { unsigned int i; int ret; if ( ! dn || dn->invalid) return false; if (dn->valid_case) return true; if (( ! dn->components) && ( ! ldb_dn_explode(dn))) { return false; } for (i = 0; i < dn->comp_num; i++) { const struct ldb_schema_attribute *a; dn->components[i].cf_name = ldb_attr_casefold(dn->components, dn->components[i].name); if (!dn->components[i].cf_name) { goto failed; } a = ldb_schema_attribute_by_name(dn->ldb, dn->components[i].cf_name); ret = a->syntax->canonicalise_fn(dn->ldb, dn->components, &(dn->components[i].value), &(dn->components[i].cf_value)); if (ret != 0) { goto failed; } } dn->valid_case = true; return true; failed: for (i = 0; i < dn->comp_num; i++) { LDB_FREE(dn->components[i].cf_name); LDB_FREE(dn->components[i].cf_value.data); } return false; }
CWE-200
2,332
12,688
107780922011685163478286334336697875725
null
null
null
samba
0454b95657846fcecf0f51b6f1194faac02518bd
0
bool ldb_dn_check_special(struct ldb_dn *dn, const char *check) { if ( ! dn || dn->invalid) return false; return ! strcmp(dn->linearized, check); }
CWE-200
2,333
12,689
168428502425010076200837557231598761491
null
null
null
samba
0454b95657846fcecf0f51b6f1194faac02518bd
0
int ldb_dn_compare_base(struct ldb_dn *base, struct ldb_dn *dn) { int ret; unsigned int n_base, n_dn; if ( ! base || base->invalid) return 1; if ( ! dn || dn->invalid) return -1; if (( ! base->valid_case) || ( ! dn->valid_case)) { if (base->linearized && dn->linearized && dn->special == base->special) { /* try with a normal compare first, if we are lucky * we will avoid exploding and casfolding */ int dif; dif = strlen(dn->linearized) - strlen(base->linearized); if (dif < 0) { return dif; } if (strcmp(base->linearized, &dn->linearized[dif]) == 0) { return 0; } } if ( ! ldb_dn_casefold_internal(base)) { return 1; } if ( ! ldb_dn_casefold_internal(dn)) { return -1; } } /* if base has more components, * they don't have the same base */ if (base->comp_num > dn->comp_num) { return (dn->comp_num - base->comp_num); } if ((dn->comp_num == 0) || (base->comp_num == 0)) { if (dn->special && base->special) { return strcmp(base->linearized, dn->linearized); } else if (dn->special) { return -1; } else if (base->special) { return 1; } else { return 0; } } n_base = base->comp_num - 1; n_dn = dn->comp_num - 1; while (n_base != (unsigned int) -1) { char *b_name = base->components[n_base].cf_name; char *dn_name = dn->components[n_dn].cf_name; char *b_vdata = (char *)base->components[n_base].cf_value.data; char *dn_vdata = (char *)dn->components[n_dn].cf_value.data; size_t b_vlen = base->components[n_base].cf_value.length; size_t dn_vlen = dn->components[n_dn].cf_value.length; /* compare attr names */ ret = strcmp(b_name, dn_name); if (ret != 0) return ret; /* compare attr.cf_value. */ if (b_vlen != dn_vlen) { return b_vlen - dn_vlen; } ret = strncmp(b_vdata, dn_vdata, b_vlen); if (ret != 0) return ret; n_base--; n_dn--; } return 0; }
CWE-200
2,335
12,690
131762818050227624104843894889396001718
null
null
null
samba
0454b95657846fcecf0f51b6f1194faac02518bd
0
struct ldb_dn *ldb_dn_copy(TALLOC_CTX *mem_ctx, struct ldb_dn *dn) { struct ldb_dn *new_dn; if (!dn || dn->invalid) { return NULL; } new_dn = talloc_zero(mem_ctx, struct ldb_dn); if ( !new_dn) { return NULL; } *new_dn = *dn; if (dn->components) { unsigned int i; new_dn->components = talloc_zero_array(new_dn, struct ldb_dn_component, dn->comp_num); if ( ! new_dn->components) { talloc_free(new_dn); return NULL; } for (i = 0; i < dn->comp_num; i++) { new_dn->components[i] = ldb_dn_copy_component(new_dn->components, &dn->components[i]); if ( ! new_dn->components[i].value.data) { talloc_free(new_dn); return NULL; } } } if (dn->ext_components) { unsigned int i; new_dn->ext_components = talloc_zero_array(new_dn, struct ldb_dn_ext_component, dn->ext_comp_num); if ( ! new_dn->ext_components) { talloc_free(new_dn); return NULL; } for (i = 0; i < dn->ext_comp_num; i++) { new_dn->ext_components[i] = ldb_dn_ext_copy_component( new_dn->ext_components, &dn->ext_components[i]); if ( ! new_dn->ext_components[i].value.data) { talloc_free(new_dn); return NULL; } } } if (dn->casefold) { new_dn->casefold = talloc_strdup(new_dn, dn->casefold); if ( ! new_dn->casefold) { talloc_free(new_dn); return NULL; } } if (dn->linearized) { new_dn->linearized = talloc_strdup(new_dn, dn->linearized); if ( ! new_dn->linearized) { talloc_free(new_dn); return NULL; } } if (dn->ext_linearized) { new_dn->ext_linearized = talloc_strdup(new_dn, dn->ext_linearized); if ( ! new_dn->ext_linearized) { talloc_free(new_dn); return NULL; } } return new_dn; }
CWE-200
2,336
12,691
175364972192254491287380977491210638981
null
null
null
samba
0454b95657846fcecf0f51b6f1194faac02518bd
0
static struct ldb_dn_component ldb_dn_copy_component( TALLOC_CTX *mem_ctx, struct ldb_dn_component *src) { struct ldb_dn_component dst; memset(&dst, 0, sizeof(dst)); if (src == NULL) { return dst; } dst.value = ldb_val_dup(mem_ctx, &(src->value)); if (dst.value.data == NULL) { return dst; } dst.name = talloc_strdup(mem_ctx, src->name); if (dst.name == NULL) { LDB_FREE(dst.value.data); return dst; } if (src->cf_value.data) { dst.cf_value = ldb_val_dup(mem_ctx, &(src->cf_value)); if (dst.cf_value.data == NULL) { LDB_FREE(dst.value.data); LDB_FREE(dst.name); return dst; } dst.cf_name = talloc_strdup(mem_ctx, src->cf_name); if (dst.cf_name == NULL) { LDB_FREE(dst.cf_name); LDB_FREE(dst.value.data); LDB_FREE(dst.name); return dst; } } else { dst.cf_value.data = NULL; dst.cf_name = NULL; } return dst; }
CWE-200
2,337
12,692
29163489995826033118221581327327150638
null
null
null
samba
0454b95657846fcecf0f51b6f1194faac02518bd
0
static bool ldb_dn_explode(struct ldb_dn *dn) { char *p, *ex_name = NULL, *ex_value = NULL, *data, *d, *dt, *t; bool trim = true; bool in_extended = true; bool in_ex_name = false; bool in_ex_value = false; bool in_attr = false; bool in_value = false; bool in_quote = false; bool is_oid = false; bool escape = false; unsigned int x; size_t l = 0; int ret; char *parse_dn; bool is_index; if ( ! dn || dn->invalid) return false; if (dn->components) { return true; } if (dn->ext_linearized) { parse_dn = dn->ext_linearized; } else { parse_dn = dn->linearized; } if ( ! parse_dn ) { return false; } is_index = (strncmp(parse_dn, "DN=@INDEX:", 10) == 0); /* Empty DNs */ if (parse_dn[0] == '\0') { return true; } /* Special DNs case */ if (dn->special) { return true; } /* make sure we free this if allocated previously before replacing */ LDB_FREE(dn->components); dn->comp_num = 0; LDB_FREE(dn->ext_components); dn->ext_comp_num = 0; /* in the common case we have 3 or more components */ /* make sure all components are zeroed, other functions depend on it */ dn->components = talloc_zero_array(dn, struct ldb_dn_component, 3); if ( ! dn->components) { return false; } /* Components data space is allocated here once */ data = talloc_array(dn->components, char, strlen(parse_dn) + 1); if (!data) { return false; } p = parse_dn; t = NULL; d = dt = data; while (*p) { if (in_extended) { if (!in_ex_name && !in_ex_value) { if (p[0] == '<') { p++; ex_name = d; in_ex_name = true; continue; } else if (p[0] == '\0') { p++; continue; } else { in_extended = false; in_attr = true; dt = d; continue; } } if (in_ex_name && *p == '=') { *d++ = '\0'; p++; ex_value = d; in_ex_name = false; in_ex_value = true; continue; } if (in_ex_value && *p == '>') { const struct ldb_dn_extended_syntax *ext_syntax; struct ldb_val ex_val = { .data = (uint8_t *)ex_value, .length = d - ex_value }; *d++ = '\0'; p++; in_ex_value = false; /* Process name and ex_value */ dn->ext_components = talloc_realloc(dn, dn->ext_components, struct ldb_dn_ext_component, dn->ext_comp_num + 1); if ( ! dn->ext_components) { /* ouch ! */ goto failed; } ext_syntax = ldb_dn_extended_syntax_by_name(dn->ldb, ex_name); if (!ext_syntax) { /* We don't know about this type of extended DN */ goto failed; } dn->ext_components[dn->ext_comp_num].name = talloc_strdup(dn->ext_components, ex_name); if (!dn->ext_components[dn->ext_comp_num].name) { /* ouch */ goto failed; } ret = ext_syntax->read_fn(dn->ldb, dn->ext_components, &ex_val, &dn->ext_components[dn->ext_comp_num].value); if (ret != LDB_SUCCESS) { ldb_dn_mark_invalid(dn); goto failed; } dn->ext_comp_num++; if (*p == '\0') { /* We have reached the end (extended component only)! */ talloc_free(data); return true; } else if (*p == ';') { p++; continue; } else { ldb_dn_mark_invalid(dn); goto failed; } } *d++ = *p++; continue; } if (in_attr) { if (trim) { if (*p == ' ') { p++; continue; } /* first char */ trim = false; if (!isascii(*p)) { /* attr names must be ascii only */ ldb_dn_mark_invalid(dn); goto failed; } if (isdigit(*p)) { is_oid = true; } else if ( ! isalpha(*p)) { /* not a digit nor an alpha, * invalid attribute name */ ldb_dn_mark_invalid(dn); goto failed; } /* Copy this character across from parse_dn, * now we have trimmed out spaces */ *d++ = *p++; continue; } if (*p == ' ') { p++; /* valid only if we are at the end */ trim = true; continue; } if (trim && (*p != '=')) { /* spaces/tabs are not allowed */ ldb_dn_mark_invalid(dn); goto failed; } if (*p == '=') { /* attribute terminated */ in_attr = false; in_value = true; trim = true; l = 0; /* Terminate this string in d * (which is a copy of parse_dn * with spaces trimmed) */ *d++ = '\0'; dn->components[dn->comp_num].name = talloc_strdup(dn->components, dt); if ( ! dn->components[dn->comp_num].name) { /* ouch */ goto failed; } dt = d; p++; continue; } if (!isascii(*p)) { /* attr names must be ascii only */ ldb_dn_mark_invalid(dn); goto failed; } if (is_oid && ( ! (isdigit(*p) || (*p == '.')))) { /* not a digit nor a dot, * invalid attribute oid */ ldb_dn_mark_invalid(dn); goto failed; } else if ( ! (isalpha(*p) || isdigit(*p) || (*p == '-'))) { /* not ALPHA, DIGIT or HYPHEN */ ldb_dn_mark_invalid(dn); goto failed; } *d++ = *p++; continue; } if (in_value) { if (in_quote) { if (*p == '\"') { if (p[-1] != '\\') { p++; in_quote = false; continue; } } *d++ = *p++; l++; continue; } if (trim) { if (*p == ' ') { p++; continue; } /* first char */ trim = false; if (*p == '\"') { in_quote = true; p++; continue; } } switch (*p) { /* TODO: support ber encoded values case '#': */ case ',': if (escape) { *d++ = *p++; l++; escape = false; continue; } /* ok found value terminator */ if ( t ) { /* trim back */ d -= (p - t); l -= (p - t); } in_attr = true; in_value = false; trim = true; p++; *d++ = '\0'; dn->components[dn->comp_num].value.data = (uint8_t *)talloc_strdup(dn->components, dt); dn->components[dn->comp_num].value.length = l; if ( ! dn->components[dn->comp_num].value.data) { /* ouch ! */ goto failed; } dt = d; dn->comp_num++; if (dn->comp_num > 2) { dn->components = talloc_realloc(dn, dn->components, struct ldb_dn_component, dn->comp_num + 1); if ( ! dn->components) { /* ouch ! */ goto failed; } /* make sure all components are zeroed, other functions depend on this */ memset(&dn->components[dn->comp_num], '\0', sizeof(struct ldb_dn_component)); } continue; case '+': case '=': /* to main compatibility with earlier versions of ldb indexing, we have to accept the base64 encoded binary index values, which contain a '+' or '=' which should normally be escaped */ if (is_index) { if ( t ) t = NULL; *d++ = *p++; l++; break; } /* fall through */ case '\"': case '<': case '>': case ';': /* a string with not escaped specials is invalid (tested) */ if ( ! escape) { ldb_dn_mark_invalid(dn); goto failed; } escape = false; *d++ = *p++; l++; if ( t ) t = NULL; break; case '\\': if ( ! escape) { escape = true; p++; continue; } escape = false; *d++ = *p++; l++; if ( t ) t = NULL; break; default: if (escape) { if (isxdigit(p[0]) && isxdigit(p[1])) { if (sscanf(p, "%02x", &x) != 1) { /* invalid escaping sequence */ ldb_dn_mark_invalid(dn); goto failed; } p += 2; *d++ = (unsigned char)x; } else { *d++ = *p++; } escape = false; l++; if ( t ) t = NULL; break; } if (*p == ' ') { if ( ! t) t = p; } else { if ( t ) t = NULL; } *d++ = *p++; l++; break; } } } if (in_attr || in_quote) { /* invalid dn */ ldb_dn_mark_invalid(dn); goto failed; } /* save last element */ if ( t ) { /* trim back */ d -= (p - t); l -= (p - t); } *d++ = '\0'; dn->components[dn->comp_num].value.length = l; dn->components[dn->comp_num].value.data = (uint8_t *)talloc_strdup(dn->components, dt); if ( ! dn->components[dn->comp_num].value.data) { /* ouch */ goto failed; } dn->comp_num++; talloc_free(data); return true; failed: LDB_FREE(dn->components); /* "data" is implicitly free'd */ dn->comp_num = 0; LDB_FREE(dn->ext_components); dn->ext_comp_num = 0; return false; }
CWE-200
2,338
12,693
223864078406655751088045262263040453339
null
null
null
samba
0454b95657846fcecf0f51b6f1194faac02518bd
0
static struct ldb_dn_ext_component ldb_dn_ext_copy_component( TALLOC_CTX *mem_ctx, struct ldb_dn_ext_component *src) { struct ldb_dn_ext_component dst; memset(&dst, 0, sizeof(dst)); if (src == NULL) { return dst; } dst.value = ldb_val_dup(mem_ctx, &(src->value)); if (dst.value.data == NULL) { return dst; } dst.name = talloc_strdup(mem_ctx, src->name); if (dst.name == NULL) { LDB_FREE(dst.value.data); return dst; } return dst; }
CWE-200
2,339
12,694
75131087058793507116606640436692997560
null
null
null
samba
0454b95657846fcecf0f51b6f1194faac02518bd
0
static int ldb_dn_extended_component_compare(const void *p1, const void *p2) { const struct ldb_dn_ext_component *ec1 = (const struct ldb_dn_ext_component *)p1; const struct ldb_dn_ext_component *ec2 = (const struct ldb_dn_ext_component *)p2; return strcmp(ec1->name, ec2->name); }
CWE-200
2,340
12,695
12905245590376962418622688506051812883
null
null
null
samba
0454b95657846fcecf0f51b6f1194faac02518bd
0
void ldb_dn_extended_filter(struct ldb_dn *dn, const char * const *accept_list) { unsigned int i; for (i=0; i<dn->ext_comp_num; i++) { if (!ldb_attr_in_list(accept_list, dn->ext_components[i].name)) { memmove(&dn->ext_components[i], &dn->ext_components[i+1], (dn->ext_comp_num-(i+1))*sizeof(dn->ext_components[0])); dn->ext_comp_num--; i--; } } LDB_FREE(dn->ext_linearized); }
CWE-200
2,341
12,696
231571898797411041885765433671675327356
null
null
null
samba
0454b95657846fcecf0f51b6f1194faac02518bd
0
int ldb_dn_get_comp_num(struct ldb_dn *dn) { if ( ! ldb_dn_validate(dn)) { return -1; } return dn->comp_num; }
CWE-200
2,343
12,697
133846526528171831956950655849333068492
null
null
null
samba
0454b95657846fcecf0f51b6f1194faac02518bd
0
const struct ldb_val *ldb_dn_get_component_val(struct ldb_dn *dn, unsigned int num) { if ( ! ldb_dn_validate(dn)) { return NULL; } if (num >= dn->comp_num) return NULL; return &dn->components[num].value; }
CWE-200
2,344
12,698
246242880019584753411802710854001310105
null
null
null
samba
0454b95657846fcecf0f51b6f1194faac02518bd
0
int ldb_dn_get_extended_comp_num(struct ldb_dn *dn) { if ( ! ldb_dn_validate(dn)) { return -1; } return dn->ext_comp_num; }
CWE-200
2,345
12,699
322873001028361418260764377172999519627
null
null
null
samba
0454b95657846fcecf0f51b6f1194faac02518bd
0
const struct ldb_val *ldb_dn_get_extended_component(struct ldb_dn *dn, const char *name) { unsigned int i; if ( ! ldb_dn_validate(dn)) { return NULL; } for (i=0; i < dn->ext_comp_num; i++) { if (ldb_attr_cmp(dn->ext_components[i].name, name) == 0) { return &dn->ext_components[i].value; } } return NULL; }
CWE-200
2,346
12,700
192297029846455648379579112876475675648
null
null
null
samba
0454b95657846fcecf0f51b6f1194faac02518bd
0
char *ldb_dn_get_extended_linearized(TALLOC_CTX *mem_ctx, struct ldb_dn *dn, int mode) { const char *linearized = ldb_dn_get_linearized(dn); char *p = NULL; unsigned int i; if (!linearized) { return NULL; } if (!ldb_dn_has_extended(dn)) { return talloc_strdup(mem_ctx, linearized); } if (!ldb_dn_validate(dn)) { return NULL; } /* sort the extended components by name. The idea is to make * the resulting DNs consistent, plus to ensure that we put * 'DELETED' first, so it can be very quickly recognised */ TYPESAFE_QSORT(dn->ext_components, dn->ext_comp_num, ldb_dn_extended_component_compare); for (i = 0; i < dn->ext_comp_num; i++) { const struct ldb_dn_extended_syntax *ext_syntax; const char *name = dn->ext_components[i].name; struct ldb_val ec_val = dn->ext_components[i].value; struct ldb_val val; int ret; ext_syntax = ldb_dn_extended_syntax_by_name(dn->ldb, name); if (!ext_syntax) { return NULL; } if (mode == 1) { ret = ext_syntax->write_clear_fn(dn->ldb, mem_ctx, &ec_val, &val); } else if (mode == 0) { ret = ext_syntax->write_hex_fn(dn->ldb, mem_ctx, &ec_val, &val); } else { ret = -1; } if (ret != LDB_SUCCESS) { return NULL; } if (i == 0) { p = talloc_asprintf(mem_ctx, "<%s=%s>", name, val.data); } else { p = talloc_asprintf_append_buffer(p, ";<%s=%s>", name, val.data); } talloc_free(val.data); if (!p) { return NULL; } } if (dn->ext_comp_num && *linearized) { p = talloc_asprintf_append_buffer(p, ";%s", linearized); } if (!p) { return NULL; } return p; }
CWE-200
2,347
12,701
323902131394816636225736486373693786892
null
null
null
samba
0454b95657846fcecf0f51b6f1194faac02518bd
0
struct ldb_context *ldb_dn_get_ldb_context(struct ldb_dn *dn) { return dn->ldb; }
CWE-200
2,348
12,702
40779579439032523544087414157349629462
null
null
null
samba
0454b95657846fcecf0f51b6f1194faac02518bd
0
const char *ldb_dn_get_linearized(struct ldb_dn *dn) { unsigned int i; size_t len; char *d, *n; if ( ! dn || ( dn->invalid)) return NULL; if (dn->linearized) return dn->linearized; if ( ! dn->components) { ldb_dn_mark_invalid(dn); return NULL; } if (dn->comp_num == 0) { dn->linearized = talloc_strdup(dn, ""); if ( ! dn->linearized) return NULL; return dn->linearized; } /* calculate maximum possible length of DN */ for (len = 0, i = 0; i < dn->comp_num; i++) { /* name len */ len += strlen(dn->components[i].name); /* max escaped data len */ len += (dn->components[i].value.length * 3); len += 2; /* '=' and ',' */ } dn->linearized = talloc_array(dn, char, len); if ( ! dn->linearized) return NULL; d = dn->linearized; for (i = 0; i < dn->comp_num; i++) { /* copy the name */ n = dn->components[i].name; while (*n) *d++ = *n++; *d++ = '='; /* and the value */ d += ldb_dn_escape_internal( d, (char *)dn->components[i].value.data, dn->components[i].value.length); *d++ = ','; } *(--d) = '\0'; /* don't waste more memory than necessary */ dn->linearized = talloc_realloc(dn, dn->linearized, char, (d - dn->linearized + 1)); return dn->linearized; }
CWE-200
2,349
12,703
87077469909249368118260878486277193082
null
null
null
samba
0454b95657846fcecf0f51b6f1194faac02518bd
0
struct ldb_dn *ldb_dn_get_parent(TALLOC_CTX *mem_ctx, struct ldb_dn *dn) { struct ldb_dn *new_dn; new_dn = ldb_dn_copy(mem_ctx, dn); if ( !new_dn ) { return NULL; } if ( ! ldb_dn_remove_child_components(new_dn, 1)) { talloc_free(new_dn); return NULL; } return new_dn; }
CWE-200
2,350
12,704
101481903420330897142896826501457597586
null
null
null
samba
0454b95657846fcecf0f51b6f1194faac02518bd
0
const char *ldb_dn_get_rdn_name(struct ldb_dn *dn) { if ( ! ldb_dn_validate(dn)) { return NULL; } if (dn->comp_num == 0) return NULL; return dn->components[0].name; }
CWE-200
2,351
12,705
218406878174514840980600747769567826443
null
null
null
samba
0454b95657846fcecf0f51b6f1194faac02518bd
0
const struct ldb_val *ldb_dn_get_rdn_val(struct ldb_dn *dn) { if ( ! ldb_dn_validate(dn)) { return NULL; } if (dn->comp_num == 0) return NULL; return &dn->components[0].value; }
CWE-200
2,352
12,706
37699060627756748312721403135227264518
null
null
null
samba
0454b95657846fcecf0f51b6f1194faac02518bd
0
bool ldb_dn_has_extended(struct ldb_dn *dn) { if ( ! dn || dn->invalid) return false; if (dn->ext_linearized && (dn->ext_linearized[0] == '<')) return true; return dn->ext_comp_num != 0; }
CWE-200
2,353
12,707
91248577378259583147731416301522740448
null
null
null
samba
0454b95657846fcecf0f51b6f1194faac02518bd
0
bool ldb_dn_is_null(struct ldb_dn *dn) { if ( ! dn || dn->invalid) return false; if (ldb_dn_has_extended(dn)) return false; if (dn->linearized && (dn->linearized[0] == '\0')) return true; return false; }
CWE-200
2,354
12,708
195645291388965983032641599814317527380
null
null
null
samba
0454b95657846fcecf0f51b6f1194faac02518bd
0
bool ldb_dn_is_special(struct ldb_dn *dn) { if ( ! dn || dn->invalid) return false; return dn->special; }
CWE-200
2,355
12,709
122933801107547604837914535987566383068
null
null
null
samba
0454b95657846fcecf0f51b6f1194faac02518bd
0
bool ldb_dn_is_valid(struct ldb_dn *dn) { if ( ! dn) return false; return ! dn->invalid; }
CWE-200
2,356
12,710
59249999860774241892806348992311825042
null
null
null
samba
0454b95657846fcecf0f51b6f1194faac02518bd
0
bool ldb_dn_remove_base_components(struct ldb_dn *dn, unsigned int num) { unsigned int i; if ( ! ldb_dn_validate(dn)) { return false; } if (dn->comp_num < num) { return false; } /* free components */ for (i = dn->comp_num - num; i < dn->comp_num; i++) { LDB_FREE(dn->components[i].name); LDB_FREE(dn->components[i].value.data); LDB_FREE(dn->components[i].cf_name); LDB_FREE(dn->components[i].cf_value.data); } dn->comp_num -= num; if (dn->valid_case) { for (i = 0; i < dn->comp_num; i++) { LDB_FREE(dn->components[i].cf_name); LDB_FREE(dn->components[i].cf_value.data); } dn->valid_case = false; } LDB_FREE(dn->casefold); LDB_FREE(dn->linearized); /* Wipe the ext_linearized DN, * the GUID and SID are almost certainly no longer valid */ LDB_FREE(dn->ext_linearized); LDB_FREE(dn->ext_components); dn->ext_comp_num = 0; return true; }
CWE-200
2,357
12,711
164254648164907187676868250075979630539
null
null
null
samba
0454b95657846fcecf0f51b6f1194faac02518bd
0
bool ldb_dn_remove_child_components(struct ldb_dn *dn, unsigned int num) { unsigned int i, j; if ( ! ldb_dn_validate(dn)) { return false; } if (dn->comp_num < num) { return false; } for (i = 0, j = num; j < dn->comp_num; i++, j++) { if (i < num) { LDB_FREE(dn->components[i].name); LDB_FREE(dn->components[i].value.data); LDB_FREE(dn->components[i].cf_name); LDB_FREE(dn->components[i].cf_value.data); } dn->components[i] = dn->components[j]; } dn->comp_num -= num; if (dn->valid_case) { for (i = 0; i < dn->comp_num; i++) { LDB_FREE(dn->components[i].cf_name); LDB_FREE(dn->components[i].cf_value.data); } dn->valid_case = false; } LDB_FREE(dn->casefold); LDB_FREE(dn->linearized); /* Wipe the ext_linearized DN, * the GUID and SID are almost certainly no longer valid */ LDB_FREE(dn->ext_linearized); LDB_FREE(dn->ext_components); dn->ext_comp_num = 0; return true; }
CWE-200
2,358
12,712
186093977131029877308196661346967550456
null
null
null
samba
0454b95657846fcecf0f51b6f1194faac02518bd
0
void ldb_dn_remove_extended_components(struct ldb_dn *dn) { LDB_FREE(dn->ext_linearized); LDB_FREE(dn->ext_components); dn->ext_comp_num = 0; }
CWE-200
2,359
12,713
159032294377363833780910475486469429641
null
null
null
samba
0454b95657846fcecf0f51b6f1194faac02518bd
0
bool ldb_dn_replace_components(struct ldb_dn *dn, struct ldb_dn *new_dn) { int i; if ( ! ldb_dn_validate(dn) || ! ldb_dn_validate(new_dn)) { return false; } /* free components */ for (i = 0; i < dn->comp_num; i++) { LDB_FREE(dn->components[i].name); LDB_FREE(dn->components[i].value.data); LDB_FREE(dn->components[i].cf_name); LDB_FREE(dn->components[i].cf_value.data); } dn->components = talloc_realloc(dn, dn->components, struct ldb_dn_component, new_dn->comp_num); if (dn->components == NULL) { ldb_dn_mark_invalid(dn); return false; } dn->comp_num = new_dn->comp_num; dn->valid_case = new_dn->valid_case; for (i = 0; i < dn->comp_num; i++) { dn->components[i] = ldb_dn_copy_component(dn->components, &new_dn->components[i]); if (dn->components[i].name == NULL) { ldb_dn_mark_invalid(dn); return false; } } if (new_dn->linearized == NULL) { dn->linearized = NULL; } else { dn->linearized = talloc_strdup(dn, new_dn->linearized); if (dn->linearized == NULL) { ldb_dn_mark_invalid(dn); return false; } } return true; }
CWE-200
2,360
12,714
102281994284462919187594288978516061465
null
null
null
samba
0454b95657846fcecf0f51b6f1194faac02518bd
0
int ldb_dn_set_component(struct ldb_dn *dn, int num, const char *name, const struct ldb_val val) { char *n; struct ldb_val v; if ( ! ldb_dn_validate(dn)) { return LDB_ERR_OTHER; } if (num >= dn->comp_num) { return LDB_ERR_OTHER; } n = talloc_strdup(dn, name); if ( ! n) { return LDB_ERR_OTHER; } v.length = val.length; v.data = (uint8_t *)talloc_memdup(dn, val.data, v.length+1); if ( ! v.data) { talloc_free(n); return LDB_ERR_OTHER; } talloc_free(dn->components[num].name); talloc_free(dn->components[num].value.data); dn->components[num].name = n; dn->components[num].value = v; if (dn->valid_case) { unsigned int i; for (i = 0; i < dn->comp_num; i++) { LDB_FREE(dn->components[i].cf_name); LDB_FREE(dn->components[i].cf_value.data); } dn->valid_case = false; } LDB_FREE(dn->casefold); LDB_FREE(dn->linearized); /* Wipe the ext_linearized DN, * the GUID and SID are almost certainly no longer valid */ LDB_FREE(dn->ext_linearized); LDB_FREE(dn->ext_components); dn->ext_comp_num = 0; return LDB_SUCCESS; }
CWE-200
2,361
12,715
208292791534531899954855316661302499420
null
null
null
samba
0454b95657846fcecf0f51b6f1194faac02518bd
0
int ldb_dn_set_extended_component(struct ldb_dn *dn, const char *name, const struct ldb_val *val) { struct ldb_dn_ext_component *p; unsigned int i; struct ldb_val v2; if ( ! ldb_dn_validate(dn)) { return LDB_ERR_OTHER; } if (!ldb_dn_extended_syntax_by_name(dn->ldb, name)) { /* We don't know how to handle this type of thing */ return LDB_ERR_INVALID_DN_SYNTAX; } for (i=0; i < dn->ext_comp_num; i++) { if (ldb_attr_cmp(dn->ext_components[i].name, name) == 0) { if (val) { dn->ext_components[i].value = ldb_val_dup(dn->ext_components, val); dn->ext_components[i].name = talloc_strdup(dn->ext_components, name); if (!dn->ext_components[i].name || !dn->ext_components[i].value.data) { ldb_dn_mark_invalid(dn); return LDB_ERR_OPERATIONS_ERROR; } } else { if (i != (dn->ext_comp_num - 1)) { memmove(&dn->ext_components[i], &dn->ext_components[i+1], ((dn->ext_comp_num-1) - i) * sizeof(*dn->ext_components)); } dn->ext_comp_num--; dn->ext_components = talloc_realloc(dn, dn->ext_components, struct ldb_dn_ext_component, dn->ext_comp_num); if (!dn->ext_components) { ldb_dn_mark_invalid(dn); return LDB_ERR_OPERATIONS_ERROR; } } LDB_FREE(dn->ext_linearized); return LDB_SUCCESS; } } if (val == NULL) { /* removing a value that doesn't exist is not an error */ return LDB_SUCCESS; } v2 = *val; p = dn->ext_components = talloc_realloc(dn, dn->ext_components, struct ldb_dn_ext_component, dn->ext_comp_num + 1); if (!dn->ext_components) { ldb_dn_mark_invalid(dn); return LDB_ERR_OPERATIONS_ERROR; } p[dn->ext_comp_num].value = ldb_val_dup(dn->ext_components, &v2); p[dn->ext_comp_num].name = talloc_strdup(p, name); if (!dn->ext_components[i].name || !dn->ext_components[i].value.data) { ldb_dn_mark_invalid(dn); return LDB_ERR_OPERATIONS_ERROR; } dn->ext_components = p; dn->ext_comp_num++; LDB_FREE(dn->ext_linearized); return LDB_SUCCESS; }
CWE-200
2,362
12,716
161159739097554782117890381550749364611
null
null
null
samba
a819d2b440aafa3138d95ff6e8b824da885a70e9
0
static uint16_t smb1cli_alloc_mid(struct smbXcli_conn *conn) { size_t num_pending = talloc_array_length(conn->pending); uint16_t result; if (conn->protocol == PROTOCOL_NONE) { /* * This is what windows sends on the SMB1 Negprot request * and some vendors reuse the SMB1 MID as SMB2 sequence number. */ return 0; } while (true) { size_t i; result = conn->smb1.mid++; if ((result == 0) || (result == 0xffff)) { continue; } for (i=0; i<num_pending; i++) { if (result == smb1cli_req_mid(conn->pending[i])) { break; } } if (i == num_pending) { return result; } } }
CWE-20
2,389
12,735
204298829690863488370271194621934361737
null
null
null
samba
a819d2b440aafa3138d95ff6e8b824da885a70e9
0
bool smb1cli_conn_activate_signing(struct smbXcli_conn *conn, const DATA_BLOB user_session_key, const DATA_BLOB response) { return smb_signing_activate(conn->smb1.signing, user_session_key, response); }
CWE-20
2,390
12,736
201885260934296114311205892683245227104
null
null
null
samba
a819d2b440aafa3138d95ff6e8b824da885a70e9
0
uint32_t smb1cli_conn_capabilities(struct smbXcli_conn *conn) { return conn->smb1.capabilities; }
CWE-20
2,391
12,737
174830473709516855938198448327455654449
null
null
null
samba
a819d2b440aafa3138d95ff6e8b824da885a70e9
0
bool smb1cli_conn_check_signing(struct smbXcli_conn *conn, const uint8_t *buf, uint32_t seqnum) { const uint8_t *hdr = buf + NBT_HDR_SIZE; size_t len = smb_len_nbt(buf); return smb_signing_check_pdu(conn->smb1.signing, hdr, len, seqnum); }
CWE-20
2,392
12,738
262022200984177328108098252287489547952
null
null
null
samba
a819d2b440aafa3138d95ff6e8b824da885a70e9
0
static NTSTATUS smb1cli_conn_dispatch_incoming(struct smbXcli_conn *conn, TALLOC_CTX *tmp_mem, uint8_t *inbuf) { struct tevent_req *req; struct smbXcli_req_state *state; NTSTATUS status; size_t num_pending; size_t i; uint8_t cmd; uint16_t mid; bool oplock_break; uint8_t *inhdr = inbuf + NBT_HDR_SIZE; size_t len = smb_len_tcp(inbuf); struct iovec *iov = NULL; int num_iov = 0; struct tevent_req **chain = NULL; size_t num_chained = 0; size_t num_responses = 0; if (conn->smb1.read_braw_req != NULL) { req = conn->smb1.read_braw_req; conn->smb1.read_braw_req = NULL; state = tevent_req_data(req, struct smbXcli_req_state); smbXcli_req_unset_pending(req); if (state->smb1.recv_iov == NULL) { /* * For requests with more than * one response, we have to readd the * recv_iov array. */ state->smb1.recv_iov = talloc_zero_array(state, struct iovec, 3); if (tevent_req_nomem(state->smb1.recv_iov, req)) { return NT_STATUS_OK; } } state->smb1.recv_iov[0].iov_base = (void *)(inhdr); state->smb1.recv_iov[0].iov_len = len; ZERO_STRUCT(state->smb1.recv_iov[1]); ZERO_STRUCT(state->smb1.recv_iov[2]); state->smb1.recv_cmd = SMBreadBraw; state->smb1.recv_status = NT_STATUS_OK; state->inbuf = talloc_move(state->smb1.recv_iov, &inbuf); tevent_req_done(req); return NT_STATUS_OK; } if ((IVAL(inhdr, 0) != SMB_MAGIC) /* 0xFF"SMB" */ && (SVAL(inhdr, 0) != 0x45ff)) /* 0xFF"E" */ { DEBUG(10, ("Got non-SMB PDU\n")); return NT_STATUS_INVALID_NETWORK_RESPONSE; } /* * If we supported multiple encrytion contexts * here we'd look up based on tid. */ if (common_encryption_on(conn->smb1.trans_enc) && (CVAL(inbuf, 0) == 0)) { uint16_t enc_ctx_num; status = get_enc_ctx_num(inbuf, &enc_ctx_num); if (!NT_STATUS_IS_OK(status)) { DEBUG(10, ("get_enc_ctx_num returned %s\n", nt_errstr(status))); return status; } if (enc_ctx_num != conn->smb1.trans_enc->enc_ctx_num) { DEBUG(10, ("wrong enc_ctx %d, expected %d\n", enc_ctx_num, conn->smb1.trans_enc->enc_ctx_num)); return NT_STATUS_INVALID_HANDLE; } status = common_decrypt_buffer(conn->smb1.trans_enc, (char *)inbuf); if (!NT_STATUS_IS_OK(status)) { DEBUG(10, ("common_decrypt_buffer returned %s\n", nt_errstr(status))); return status; } inhdr = inbuf + NBT_HDR_SIZE; len = smb_len_nbt(inbuf); } mid = SVAL(inhdr, HDR_MID); num_pending = talloc_array_length(conn->pending); for (i=0; i<num_pending; i++) { if (mid == smb1cli_req_mid(conn->pending[i])) { break; } } if (i == num_pending) { /* Dump unexpected reply */ return NT_STATUS_RETRY; } oplock_break = false; if (mid == 0xffff) { /* * Paranoia checks that this is really an oplock break request. */ oplock_break = (len == 51); /* hdr + 8 words */ oplock_break &= ((CVAL(inhdr, HDR_FLG) & FLAG_REPLY) == 0); oplock_break &= (CVAL(inhdr, HDR_COM) == SMBlockingX); oplock_break &= (SVAL(inhdr, HDR_VWV+VWV(6)) == 0); oplock_break &= (SVAL(inhdr, HDR_VWV+VWV(7)) == 0); if (!oplock_break) { /* Dump unexpected reply */ return NT_STATUS_RETRY; } } req = conn->pending[i]; state = tevent_req_data(req, struct smbXcli_req_state); if (!oplock_break /* oplock breaks are not signed */ && !smb_signing_check_pdu(conn->smb1.signing, inhdr, len, state->smb1.seqnum+1)) { DEBUG(10, ("cli_check_sign_mac failed\n")); return NT_STATUS_ACCESS_DENIED; } status = smb1cli_inbuf_parse_chain(inbuf, tmp_mem, &iov, &num_iov); if (!NT_STATUS_IS_OK(status)) { DEBUG(10,("smb1cli_inbuf_parse_chain - %s\n", nt_errstr(status))); return status; } cmd = CVAL(inhdr, HDR_COM); status = smb1cli_pull_raw_error(inhdr); if (NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_SESSION_EXPIRED) && (state->session != NULL) && state->session->disconnect_expired) { /* * this should be a short term hack * until the upper layers have implemented * re-authentication. */ return status; } if (state->smb1.chained_requests == NULL) { if (num_iov != 3) { return NT_STATUS_INVALID_NETWORK_RESPONSE; } smbXcli_req_unset_pending(req); if (state->smb1.recv_iov == NULL) { /* * For requests with more than * one response, we have to readd the * recv_iov array. */ state->smb1.recv_iov = talloc_zero_array(state, struct iovec, 3); if (tevent_req_nomem(state->smb1.recv_iov, req)) { return NT_STATUS_OK; } } state->smb1.recv_cmd = cmd; state->smb1.recv_status = status; state->inbuf = talloc_move(state->smb1.recv_iov, &inbuf); state->smb1.recv_iov[0] = iov[0]; state->smb1.recv_iov[1] = iov[1]; state->smb1.recv_iov[2] = iov[2]; if (talloc_array_length(conn->pending) == 0) { tevent_req_done(req); return NT_STATUS_OK; } tevent_req_defer_callback(req, state->ev); tevent_req_done(req); return NT_STATUS_RETRY; } chain = talloc_move(tmp_mem, &state->smb1.chained_requests); num_chained = talloc_array_length(chain); num_responses = (num_iov - 1)/2; if (num_responses > num_chained) { return NT_STATUS_INVALID_NETWORK_RESPONSE; } for (i=0; i<num_chained; i++) { size_t iov_idx = 1 + (i*2); struct iovec *cur = &iov[iov_idx]; uint8_t *inbuf_ref; req = chain[i]; state = tevent_req_data(req, struct smbXcli_req_state); smbXcli_req_unset_pending(req); /* * as we finish multiple requests here * we need to defer the callbacks as * they could destroy our current stack state. */ tevent_req_defer_callback(req, state->ev); if (i >= num_responses) { tevent_req_nterror(req, NT_STATUS_REQUEST_ABORTED); continue; } if (state->smb1.recv_iov == NULL) { /* * For requests with more than * one response, we have to readd the * recv_iov array. */ state->smb1.recv_iov = talloc_zero_array(state, struct iovec, 3); if (tevent_req_nomem(state->smb1.recv_iov, req)) { continue; } } state->smb1.recv_cmd = cmd; if (i == (num_responses - 1)) { /* * The last request in the chain gets the status */ state->smb1.recv_status = status; } else { cmd = CVAL(cur[0].iov_base, 0); state->smb1.recv_status = NT_STATUS_OK; } state->inbuf = inbuf; /* * Note: here we use talloc_reference() in a way * that does not expose it to the caller. */ inbuf_ref = talloc_reference(state->smb1.recv_iov, inbuf); if (tevent_req_nomem(inbuf_ref, req)) { continue; } /* copy the related buffers */ state->smb1.recv_iov[0] = iov[0]; state->smb1.recv_iov[1] = cur[0]; state->smb1.recv_iov[2] = cur[1]; tevent_req_done(req); } return NT_STATUS_RETRY; }
CWE-20
2,393
12,739
46181715122753451121756024845804853208
null
null
null
samba
a819d2b440aafa3138d95ff6e8b824da885a70e9
0
bool smb1cli_conn_encryption_on(struct smbXcli_conn *conn) { return common_encryption_on(conn->smb1.trans_enc); }
CWE-20
2,394
12,740
5292687706818517417791126525222233979
null
null
null
samba
a819d2b440aafa3138d95ff6e8b824da885a70e9
0
uint32_t smb1cli_conn_max_xmit(struct smbXcli_conn *conn) { return conn->smb1.max_xmit; }
CWE-20
2,395
12,741
63643193421288040535043993882399789306
null
null
null
samba
a819d2b440aafa3138d95ff6e8b824da885a70e9
0
bool smb1cli_conn_req_possible(struct smbXcli_conn *conn) { size_t pending = talloc_array_length(conn->pending); uint16_t possible = conn->smb1.server.max_mux; if (pending >= possible) { return false; } return true; }
CWE-20
2,396
12,742
94629268927691500047843888721878493208
null
null
null
samba
a819d2b440aafa3138d95ff6e8b824da885a70e9
0
const uint8_t *smb1cli_conn_server_challenge(struct smbXcli_conn *conn) { return conn->smb1.server.challenge; }
CWE-20
2,397
12,743
58544462666111345877049019753558175935
null
null
null
samba
a819d2b440aafa3138d95ff6e8b824da885a70e9
0
bool smb1cli_conn_server_lockread(struct smbXcli_conn *conn) { return conn->smb1.server.lockread; }
CWE-20
2,398
12,744
304677867656514348621241096291821399959
null
null
null
samba
a819d2b440aafa3138d95ff6e8b824da885a70e9
0
bool smb1cli_conn_server_readbraw(struct smbXcli_conn *conn) { return conn->smb1.server.readbraw; }
CWE-20
2,399
12,745
211006793568394708469320082655503760099
null
null
null
samba
a819d2b440aafa3138d95ff6e8b824da885a70e9
0
uint16_t smb1cli_conn_server_security_mode(struct smbXcli_conn *conn) { return conn->smb1.server.security_mode; }
CWE-20
2,400
12,746
238605098158201780006465375324361911569
null
null
null
samba
a819d2b440aafa3138d95ff6e8b824da885a70e9
0
uint32_t smb1cli_conn_server_session_key(struct smbXcli_conn *conn) { return conn->smb1.server.session_key; }
CWE-20
2,401
12,747
240785564631895761856436141768556279971
null
null
null
samba
a819d2b440aafa3138d95ff6e8b824da885a70e9
0
int smb1cli_conn_server_time_zone(struct smbXcli_conn *conn) { return conn->smb1.server.time_zone; }
CWE-20
2,402
12,748
251158075899434369160187254417255524575
null
null
null
samba
a819d2b440aafa3138d95ff6e8b824da885a70e9
0
bool smb1cli_conn_server_writebraw(struct smbXcli_conn *conn) { return conn->smb1.server.writebraw; }
CWE-20
2,403
12,749
226929024658337872607614883467748242525
null
null
null
samba
a819d2b440aafa3138d95ff6e8b824da885a70e9
0
bool smb1cli_conn_server_writeunlock(struct smbXcli_conn *conn) { return conn->smb1.server.writeunlock; }
CWE-20
2,404
12,750
197887190349775894184237358826548564265
null
null
null
samba
a819d2b440aafa3138d95ff6e8b824da885a70e9
0
bool smb1cli_conn_signing_is_active(struct smbXcli_conn *conn) { return smb_signing_is_active(conn->smb1.signing); }
CWE-20
2,406
12,751
137308875913382634208913656114670716185
null
null
null
samba
a819d2b440aafa3138d95ff6e8b824da885a70e9
0
static NTSTATUS smb1cli_conn_signv(struct smbXcli_conn *conn, struct iovec *iov, int iov_count, uint32_t *seqnum, bool one_way_seqnum) { TALLOC_CTX *frame = NULL; uint8_t *buf; /* * Obvious optimization: Make cli_calculate_sign_mac work with struct * iovec directly. MD5Update would do that just fine. */ if (iov_count < 4) { return NT_STATUS_INVALID_PARAMETER_MIX; } if (iov[0].iov_len != NBT_HDR_SIZE) { return NT_STATUS_INVALID_PARAMETER_MIX; } if (iov[1].iov_len != (MIN_SMB_SIZE-sizeof(uint16_t))) { return NT_STATUS_INVALID_PARAMETER_MIX; } if (iov[2].iov_len > (0xFF * sizeof(uint16_t))) { return NT_STATUS_INVALID_PARAMETER_MIX; } if (iov[3].iov_len != sizeof(uint16_t)) { return NT_STATUS_INVALID_PARAMETER_MIX; } frame = talloc_stackframe(); buf = smbXcli_iov_concat(frame, &iov[1], iov_count - 1); if (buf == NULL) { return NT_STATUS_NO_MEMORY; } *seqnum = smb_signing_next_seqnum(conn->smb1.signing, one_way_seqnum); smb_signing_sign_pdu(conn->smb1.signing, buf, talloc_get_size(buf), *seqnum); memcpy(iov[1].iov_base, buf, iov[1].iov_len); TALLOC_FREE(frame); return NT_STATUS_OK; }
CWE-20
2,407
12,752
114935928721618711531763041788451964661
null
null
null
samba
a819d2b440aafa3138d95ff6e8b824da885a70e9
0
static NTSTATUS smb1cli_inbuf_parse_chain(uint8_t *buf, TALLOC_CTX *mem_ctx, struct iovec **piov, int *pnum_iov) { struct iovec *iov; int num_iov; size_t buflen; size_t taken; size_t remaining; uint8_t *hdr; uint8_t cmd; uint32_t wct_ofs; NTSTATUS status; size_t min_size = MIN_SMB_SIZE; buflen = smb_len_tcp(buf); taken = 0; hdr = buf + NBT_HDR_SIZE; status = smb1cli_pull_raw_error(hdr); if (NT_STATUS_IS_ERR(status)) { /* * This is an ugly hack to support OS/2 * which skips the byte_count in the DATA block * on some error responses. * * See bug #9096 */ min_size -= sizeof(uint16_t); } if (buflen < min_size) { return NT_STATUS_INVALID_NETWORK_RESPONSE; } /* * This returns iovec elements in the following order: * * - SMB header * * - Parameter Block * - Data Block * * - Parameter Block * - Data Block * * - Parameter Block * - Data Block */ num_iov = 1; iov = talloc_array(mem_ctx, struct iovec, num_iov); if (iov == NULL) { return NT_STATUS_NO_MEMORY; } iov[0].iov_base = hdr; iov[0].iov_len = HDR_WCT; taken += HDR_WCT; cmd = CVAL(hdr, HDR_COM); wct_ofs = HDR_WCT; while (true) { size_t len = buflen - taken; struct iovec *cur; struct iovec *iov_tmp; uint8_t wct; uint32_t bcc_ofs; uint16_t bcc; size_t needed; /* * we need at least WCT */ needed = sizeof(uint8_t); if (len < needed) { DEBUG(10, ("%s: %d bytes left, expected at least %d\n", __location__, (int)len, (int)needed)); goto inval; } /* * Now we check if the specified words are there */ wct = CVAL(hdr, wct_ofs); needed += wct * sizeof(uint16_t); if (len < needed) { DEBUG(10, ("%s: %d bytes left, expected at least %d\n", __location__, (int)len, (int)needed)); goto inval; } if ((num_iov == 1) && (len == needed) && NT_STATUS_IS_ERR(status)) { /* * This is an ugly hack to support OS/2 * which skips the byte_count in the DATA block * on some error responses. * * See bug #9096 */ iov_tmp = talloc_realloc(mem_ctx, iov, struct iovec, num_iov + 2); if (iov_tmp == NULL) { TALLOC_FREE(iov); return NT_STATUS_NO_MEMORY; } iov = iov_tmp; cur = &iov[num_iov]; num_iov += 2; cur[0].iov_len = 0; cur[0].iov_base = hdr + (wct_ofs + sizeof(uint8_t)); cur[1].iov_len = 0; cur[1].iov_base = cur[0].iov_base; taken += needed; break; } /* * we need at least BCC */ needed += sizeof(uint16_t); if (len < needed) { DEBUG(10, ("%s: %d bytes left, expected at least %d\n", __location__, (int)len, (int)needed)); goto inval; } /* * Now we check if the specified bytes are there */ bcc_ofs = wct_ofs + sizeof(uint8_t) + wct * sizeof(uint16_t); bcc = SVAL(hdr, bcc_ofs); needed += bcc * sizeof(uint8_t); if (len < needed) { DEBUG(10, ("%s: %d bytes left, expected at least %d\n", __location__, (int)len, (int)needed)); goto inval; } /* * we allocate 2 iovec structures for words and bytes */ iov_tmp = talloc_realloc(mem_ctx, iov, struct iovec, num_iov + 2); if (iov_tmp == NULL) { TALLOC_FREE(iov); return NT_STATUS_NO_MEMORY; } iov = iov_tmp; cur = &iov[num_iov]; num_iov += 2; cur[0].iov_len = wct * sizeof(uint16_t); cur[0].iov_base = hdr + (wct_ofs + sizeof(uint8_t)); cur[1].iov_len = bcc * sizeof(uint8_t); cur[1].iov_base = hdr + (bcc_ofs + sizeof(uint16_t)); taken += needed; if (!smb1cli_is_andx_req(cmd)) { /* * If the current command does not have AndX chanining * we are done. */ break; } if (wct == 0 && bcc == 0) { /* * An empty response also ends the chain, * most likely with an error. */ break; } if (wct < 2) { DEBUG(10, ("%s: wct[%d] < 2 for cmd[0x%02X]\n", __location__, (int)wct, (int)cmd)); goto inval; } cmd = CVAL(cur[0].iov_base, 0); if (cmd == 0xFF) { /* * If it is the end of the chain we are also done. */ break; } wct_ofs = SVAL(cur[0].iov_base, 2); if (wct_ofs < taken) { return NT_STATUS_INVALID_NETWORK_RESPONSE; } if (wct_ofs > buflen) { return NT_STATUS_INVALID_NETWORK_RESPONSE; } /* * we consumed everything up to the start of the next * parameter block. */ taken = wct_ofs; } remaining = buflen - taken; if (remaining > 0 && num_iov >= 3) { /* * The last DATA block gets the remaining * bytes, this is needed to support * CAP_LARGE_WRITEX and CAP_LARGE_READX. */ iov[num_iov-1].iov_len += remaining; } *piov = iov; *pnum_iov = num_iov; return NT_STATUS_OK; inval: TALLOC_FREE(iov); return NT_STATUS_INVALID_NETWORK_RESPONSE; }
CWE-20
2,408
12,753
110587393966376012569882284802019913279
null
null
null
samba
a819d2b440aafa3138d95ff6e8b824da885a70e9
0
bool smb1cli_is_andx_req(uint8_t cmd) { switch (cmd) { case SMBtconX: case SMBlockingX: case SMBopenX: case SMBreadX: case SMBwriteX: case SMBsesssetupX: case SMBulogoffX: case SMBntcreateX: return true; break; default: break; } return false; }
CWE-20
2,409
12,754
274160366099693148715615858068837025519
null
null
null
samba
a819d2b440aafa3138d95ff6e8b824da885a70e9
0
static NTSTATUS smb1cli_pull_raw_error(const uint8_t *hdr) { uint32_t flags2 = SVAL(hdr, HDR_FLG2); NTSTATUS status = NT_STATUS(IVAL(hdr, HDR_RCLS)); if (NT_STATUS_IS_OK(status)) { return NT_STATUS_OK; } if (flags2 & FLAGS2_32_BIT_ERROR_CODES) { return status; } return NT_STATUS_DOS(CVAL(hdr, HDR_RCLS), SVAL(hdr, HDR_ERR)); }
CWE-20
2,410
12,755
57318061298813303597370617776861830741
null
null
null
samba
a819d2b440aafa3138d95ff6e8b824da885a70e9
0
static bool smb1cli_req_cancel(struct tevent_req *req) { struct smbXcli_req_state *state = tevent_req_data(req, struct smbXcli_req_state); uint8_t flags; uint16_t flags2; uint32_t pid; uint16_t mid; struct tevent_req *subreq; NTSTATUS status; flags = CVAL(state->smb1.hdr, HDR_FLG); flags2 = SVAL(state->smb1.hdr, HDR_FLG2); pid = SVAL(state->smb1.hdr, HDR_PID); pid |= SVAL(state->smb1.hdr, HDR_PIDHIGH)<<16; mid = SVAL(state->smb1.hdr, HDR_MID); subreq = smb1cli_req_create(state, state->ev, state->conn, SMBntcancel, flags, 0, flags2, 0, 0, /* timeout */ pid, state->tcon, state->session, 0, NULL, /* vwv */ 0, NULL); /* bytes */ if (subreq == NULL) { return false; } smb1cli_req_set_mid(subreq, mid); status = smb1cli_req_chain_submit(&subreq, 1); if (!NT_STATUS_IS_OK(status)) { TALLOC_FREE(subreq); return false; } smb1cli_req_set_mid(subreq, 0); tevent_req_set_callback(subreq, smb1cli_req_cancel_done, NULL); return true; }
CWE-20
2,411
12,756
150168360769532124236477598222306733774
null
null
null
samba
a819d2b440aafa3138d95ff6e8b824da885a70e9
0
static void smb1cli_req_cancel_done(struct tevent_req *subreq) { /* we do not care about the result */ TALLOC_FREE(subreq); }
CWE-20
2,412
12,757
210687384798576454442343570020981497707
null
null
null
samba
a819d2b440aafa3138d95ff6e8b824da885a70e9
0
struct tevent_req *smb1cli_req_create(TALLOC_CTX *mem_ctx, struct tevent_context *ev, struct smbXcli_conn *conn, uint8_t smb_command, uint8_t additional_flags, uint8_t clear_flags, uint16_t additional_flags2, uint16_t clear_flags2, uint32_t timeout_msec, uint32_t pid, struct smbXcli_tcon *tcon, struct smbXcli_session *session, uint8_t wct, uint16_t *vwv, int iov_count, struct iovec *bytes_iov) { struct tevent_req *req; struct smbXcli_req_state *state; uint8_t flags = 0; uint16_t flags2 = 0; uint16_t uid = 0; uint16_t tid = 0; ssize_t num_bytes; if (iov_count > MAX_SMB_IOV) { /* * Should not happen :-) */ return NULL; } req = tevent_req_create(mem_ctx, &state, struct smbXcli_req_state); if (req == NULL) { return NULL; } state->ev = ev; state->conn = conn; state->session = session; state->tcon = tcon; if (session) { uid = session->smb1.session_id; } if (tcon) { tid = tcon->smb1.tcon_id; if (tcon->fs_attributes & FILE_CASE_SENSITIVE_SEARCH) { clear_flags |= FLAG_CASELESS_PATHNAMES; } else { /* Default setting, case insensitive. */ additional_flags |= FLAG_CASELESS_PATHNAMES; } if (smbXcli_conn_dfs_supported(conn) && smbXcli_tcon_is_dfs_share(tcon)) { additional_flags2 |= FLAGS2_DFS_PATHNAMES; } } state->smb1.recv_cmd = 0xFF; state->smb1.recv_status = NT_STATUS_INTERNAL_ERROR; state->smb1.recv_iov = talloc_zero_array(state, struct iovec, 3); if (state->smb1.recv_iov == NULL) { TALLOC_FREE(req); return NULL; } smb1cli_req_flags(conn->protocol, conn->smb1.capabilities, smb_command, additional_flags, clear_flags, &flags, additional_flags2, clear_flags2, &flags2); SIVAL(state->smb1.hdr, 0, SMB_MAGIC); SCVAL(state->smb1.hdr, HDR_COM, smb_command); SIVAL(state->smb1.hdr, HDR_RCLS, NT_STATUS_V(NT_STATUS_OK)); SCVAL(state->smb1.hdr, HDR_FLG, flags); SSVAL(state->smb1.hdr, HDR_FLG2, flags2); SSVAL(state->smb1.hdr, HDR_PIDHIGH, pid >> 16); SSVAL(state->smb1.hdr, HDR_TID, tid); SSVAL(state->smb1.hdr, HDR_PID, pid); SSVAL(state->smb1.hdr, HDR_UID, uid); SSVAL(state->smb1.hdr, HDR_MID, 0); /* this comes later */ SCVAL(state->smb1.hdr, HDR_WCT, wct); state->smb1.vwv = vwv; num_bytes = iov_buflen(bytes_iov, iov_count); if (num_bytes == -1) { /* * I'd love to add a check for num_bytes<=UINT16_MAX here, but * the smbclient->samba connections can lie and transfer more. */ TALLOC_FREE(req); return NULL; } SSVAL(state->smb1.bytecount_buf, 0, num_bytes); state->smb1.iov[0].iov_base = (void *)state->length_hdr; state->smb1.iov[0].iov_len = sizeof(state->length_hdr); state->smb1.iov[1].iov_base = (void *)state->smb1.hdr; state->smb1.iov[1].iov_len = sizeof(state->smb1.hdr); state->smb1.iov[2].iov_base = (void *)state->smb1.vwv; state->smb1.iov[2].iov_len = wct * sizeof(uint16_t); state->smb1.iov[3].iov_base = (void *)state->smb1.bytecount_buf; state->smb1.iov[3].iov_len = sizeof(uint16_t); if (iov_count != 0) { memcpy(&state->smb1.iov[4], bytes_iov, iov_count * sizeof(*bytes_iov)); } state->smb1.iov_count = iov_count + 4; if (timeout_msec > 0) { struct timeval endtime; endtime = timeval_current_ofs_msec(timeout_msec); if (!tevent_req_set_endtime(req, ev, endtime)) { return req; } } switch (smb_command) { case SMBtranss: case SMBtranss2: case SMBnttranss: state->one_way = true; break; case SMBntcancel: state->one_way = true; state->smb1.one_way_seqnum = true; break; case SMBlockingX: if ((wct == 8) && (CVAL(vwv+3, 0) == LOCKING_ANDX_OPLOCK_RELEASE)) { state->one_way = true; } break; } return req; }
CWE-20
2,414
12,758
264188815832074331380455924399597412708
null
null
null
samba
a819d2b440aafa3138d95ff6e8b824da885a70e9
0
static void smb1cli_req_flags(enum protocol_types protocol, uint32_t smb1_capabilities, uint8_t smb_command, uint8_t additional_flags, uint8_t clear_flags, uint8_t *_flags, uint16_t additional_flags2, uint16_t clear_flags2, uint16_t *_flags2) { uint8_t flags = 0; uint16_t flags2 = 0; if (protocol >= PROTOCOL_LANMAN1) { flags |= FLAG_CASELESS_PATHNAMES; flags |= FLAG_CANONICAL_PATHNAMES; } if (protocol >= PROTOCOL_LANMAN2) { flags2 |= FLAGS2_LONG_PATH_COMPONENTS; flags2 |= FLAGS2_EXTENDED_ATTRIBUTES; } if (protocol >= PROTOCOL_NT1) { flags2 |= FLAGS2_IS_LONG_NAME; if (smb1_capabilities & CAP_UNICODE) { flags2 |= FLAGS2_UNICODE_STRINGS; } if (smb1_capabilities & CAP_STATUS32) { flags2 |= FLAGS2_32_BIT_ERROR_CODES; } if (smb1_capabilities & CAP_EXTENDED_SECURITY) { flags2 |= FLAGS2_EXTENDED_SECURITY; } } flags |= additional_flags; flags &= ~clear_flags; flags2 |= additional_flags2; flags2 &= ~clear_flags2; *_flags = flags; *_flags2 = flags2; }
CWE-20
2,415
12,759
316474052158599143740306232288351212400
null
null
null
samba
a819d2b440aafa3138d95ff6e8b824da885a70e9
0
uint16_t smb1cli_req_mid(struct tevent_req *req) { struct smbXcli_req_state *state = tevent_req_data(req, struct smbXcli_req_state); if (state->smb1.mid != 0) { return state->smb1.mid; } return SVAL(state->smb1.hdr, HDR_MID); }
CWE-20
2,416
12,760
47148140031953099790959599558726616259
null
null
null
samba
a819d2b440aafa3138d95ff6e8b824da885a70e9
0
NTSTATUS smb1cli_req_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, struct iovec **piov, uint8_t **phdr, uint8_t *pwct, uint16_t **pvwv, uint32_t *pvwv_offset, uint32_t *pnum_bytes, uint8_t **pbytes, uint32_t *pbytes_offset, uint8_t **pinbuf, const struct smb1cli_req_expected_response *expected, size_t num_expected) { struct smbXcli_req_state *state = tevent_req_data(req, struct smbXcli_req_state); NTSTATUS status = NT_STATUS_OK; struct iovec *recv_iov = NULL; uint8_t *hdr = NULL; uint8_t wct = 0; uint32_t vwv_offset = 0; uint16_t *vwv = NULL; uint32_t num_bytes = 0; uint32_t bytes_offset = 0; uint8_t *bytes = NULL; size_t i; bool found_status = false; bool found_size = false; if (piov != NULL) { *piov = NULL; } if (phdr != NULL) { *phdr = 0; } if (pwct != NULL) { *pwct = 0; } if (pvwv != NULL) { *pvwv = NULL; } if (pvwv_offset != NULL) { *pvwv_offset = 0; } if (pnum_bytes != NULL) { *pnum_bytes = 0; } if (pbytes != NULL) { *pbytes = NULL; } if (pbytes_offset != NULL) { *pbytes_offset = 0; } if (pinbuf != NULL) { *pinbuf = NULL; } if (state->inbuf != NULL) { recv_iov = state->smb1.recv_iov; state->smb1.recv_iov = NULL; if (state->smb1.recv_cmd != SMBreadBraw) { hdr = (uint8_t *)recv_iov[0].iov_base; wct = recv_iov[1].iov_len/2; vwv = (uint16_t *)recv_iov[1].iov_base; vwv_offset = PTR_DIFF(vwv, hdr); num_bytes = recv_iov[2].iov_len; bytes = (uint8_t *)recv_iov[2].iov_base; bytes_offset = PTR_DIFF(bytes, hdr); } } if (tevent_req_is_nterror(req, &status)) { for (i=0; i < num_expected; i++) { if (NT_STATUS_EQUAL(status, expected[i].status)) { found_status = true; break; } } if (found_status) { return NT_STATUS_UNEXPECTED_NETWORK_ERROR; } return status; } if (num_expected == 0) { found_status = true; found_size = true; } status = state->smb1.recv_status; for (i=0; i < num_expected; i++) { if (!NT_STATUS_EQUAL(status, expected[i].status)) { continue; } found_status = true; if (expected[i].wct == 0) { found_size = true; break; } if (expected[i].wct == wct) { found_size = true; break; } } if (!found_status) { return status; } if (!found_size) { return NT_STATUS_INVALID_NETWORK_RESPONSE; } if (piov != NULL) { *piov = talloc_move(mem_ctx, &recv_iov); } if (phdr != NULL) { *phdr = hdr; } if (pwct != NULL) { *pwct = wct; } if (pvwv != NULL) { *pvwv = vwv; } if (pvwv_offset != NULL) { *pvwv_offset = vwv_offset; } if (pnum_bytes != NULL) { *pnum_bytes = num_bytes; } if (pbytes != NULL) { *pbytes = bytes; } if (pbytes_offset != NULL) { *pbytes_offset = bytes_offset; } if (pinbuf != NULL) { *pinbuf = state->inbuf; } return status; }
CWE-20
2,417
12,761
221733160059626459380624673310898822465
null
null
null
samba
a819d2b440aafa3138d95ff6e8b824da885a70e9
0
struct tevent_req *smb1cli_req_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, struct smbXcli_conn *conn, uint8_t smb_command, uint8_t additional_flags, uint8_t clear_flags, uint16_t additional_flags2, uint16_t clear_flags2, uint32_t timeout_msec, uint32_t pid, struct smbXcli_tcon *tcon, struct smbXcli_session *session, uint8_t wct, uint16_t *vwv, uint32_t num_bytes, const uint8_t *bytes) { struct tevent_req *req; struct iovec iov; NTSTATUS status; iov.iov_base = discard_const_p(void, bytes); iov.iov_len = num_bytes; req = smb1cli_req_create(mem_ctx, ev, conn, smb_command, additional_flags, clear_flags, additional_flags2, clear_flags2, timeout_msec, pid, tcon, session, wct, vwv, 1, &iov); if (req == NULL) { return NULL; } if (!tevent_req_is_in_progress(req)) { return tevent_req_post(req, ev); } status = smb1cli_req_chain_submit(&req, 1); if (tevent_req_nterror(req, status)) { return tevent_req_post(req, ev); } return req; }
CWE-20
2,418
12,762
26790042890875296396539053350398389816
null
null
null