idx
int64 | func_before
string | Vulnerability Classification
string | vul
int64 | func_after
string | patch
string | CWE ID
string | lines_before
string | lines_after
string |
|---|---|---|---|---|---|---|---|---|
1,800
|
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 */
}
|
Bypass
| 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 */
}
|
@@ -1,4 +1,4 @@
-/* $OpenBSD: clientloop.c,v 1.273 2015/05/04 06:10:48 djm Exp $ */
+/* $OpenBSD: clientloop.c,v 1.274 2015/07/01 02:26:31 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -163,7 +163,7 @@ static int connection_in; /* Connection to server (input). */
static int connection_out; /* Connection to server (output). */
static int need_rekeying; /* Set to non-zero if rekeying is requested. */
static int session_closed; /* In SSH2: login session closed. */
-static int x11_refuse_time; /* If >0, refuse x11 opens after this time. */
+static u_int x11_refuse_time; /* If >0, refuse x11 opens after this time. */
static void client_init_dispatch(void);
int session_ident = -1;
@@ -298,7 +298,8 @@ client_x11_display_valid(const char *display)
return 1;
}
-#define SSH_X11_PROTO "MIT-MAGIC-COOKIE-1"
+#define SSH_X11_PROTO "MIT-MAGIC-COOKIE-1"
+#define X11_TIMEOUT_SLACK 60
void
client_x11_get_proto(const char *display, const char *xauth_path,
u_int trusted, u_int timeout, char **_proto, char **_data)
@@ -311,7 +312,7 @@ client_x11_get_proto(const char *display, const char *xauth_path,
int got_data = 0, generated = 0, do_unlink = 0, i;
char *xauthdir, *xauthfile;
struct stat st;
- u_int now;
+ u_int now, x11_timeout_real;
xauthdir = xauthfile = NULL;
*_proto = proto;
@@ -344,6 +345,15 @@ client_x11_get_proto(const char *display, const char *xauth_path,
xauthdir = xmalloc(PATH_MAX);
xauthfile = xmalloc(PATH_MAX);
mktemp_proto(xauthdir, PATH_MAX);
+ /*
+ * The authentication cookie should briefly outlive
+ * ssh's willingness to forward X11 connections to
+ * avoid nasty fail-open behaviour in the X server.
+ */
+ if (timeout >= UINT_MAX - X11_TIMEOUT_SLACK)
+ x11_timeout_real = UINT_MAX;
+ else
+ x11_timeout_real = timeout + X11_TIMEOUT_SLACK;
if (mkdtemp(xauthdir) != NULL) {
do_unlink = 1;
snprintf(xauthfile, PATH_MAX, "%s/xauthfile",
@@ -351,17 +361,20 @@ client_x11_get_proto(const char *display, const char *xauth_path,
snprintf(cmd, sizeof(cmd),
"%s -f %s generate %s " SSH_X11_PROTO
" untrusted timeout %u 2>" _PATH_DEVNULL,
- xauth_path, xauthfile, display, timeout);
+ xauth_path, xauthfile, display,
+ x11_timeout_real);
debug2("x11_get_proto: %s", cmd);
- if (system(cmd) == 0)
- generated = 1;
if (x11_refuse_time == 0) {
now = monotime() + 1;
if (UINT_MAX - timeout < now)
x11_refuse_time = UINT_MAX;
else
x11_refuse_time = now + timeout;
+ channel_set_x11_refuse_time(
+ x11_refuse_time);
}
+ if (system(cmd) == 0)
+ generated = 1;
}
}
@@ -1889,7 +1902,7 @@ client_request_x11(const char *request_type, int rchan)
"malicious server.");
return NULL;
}
- if (x11_refuse_time != 0 && monotime() >= x11_refuse_time) {
+ if (x11_refuse_time != 0 && (u_int)monotime() >= x11_refuse_time) {
verbose("Rejected X11 connection after ForwardX11Timeout "
"expired");
return NULL;
|
CWE-264
| null | null |
1,801
|
signal_handler(int sig)
{
received_signal = sig;
quit_pending = 1;
}
|
Bypass
| 0
|
signal_handler(int sig)
{
received_signal = sig;
quit_pending = 1;
}
|
@@ -1,4 +1,4 @@
-/* $OpenBSD: clientloop.c,v 1.273 2015/05/04 06:10:48 djm Exp $ */
+/* $OpenBSD: clientloop.c,v 1.274 2015/07/01 02:26:31 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -163,7 +163,7 @@ static int connection_in; /* Connection to server (input). */
static int connection_out; /* Connection to server (output). */
static int need_rekeying; /* Set to non-zero if rekeying is requested. */
static int session_closed; /* In SSH2: login session closed. */
-static int x11_refuse_time; /* If >0, refuse x11 opens after this time. */
+static u_int x11_refuse_time; /* If >0, refuse x11 opens after this time. */
static void client_init_dispatch(void);
int session_ident = -1;
@@ -298,7 +298,8 @@ client_x11_display_valid(const char *display)
return 1;
}
-#define SSH_X11_PROTO "MIT-MAGIC-COOKIE-1"
+#define SSH_X11_PROTO "MIT-MAGIC-COOKIE-1"
+#define X11_TIMEOUT_SLACK 60
void
client_x11_get_proto(const char *display, const char *xauth_path,
u_int trusted, u_int timeout, char **_proto, char **_data)
@@ -311,7 +312,7 @@ client_x11_get_proto(const char *display, const char *xauth_path,
int got_data = 0, generated = 0, do_unlink = 0, i;
char *xauthdir, *xauthfile;
struct stat st;
- u_int now;
+ u_int now, x11_timeout_real;
xauthdir = xauthfile = NULL;
*_proto = proto;
@@ -344,6 +345,15 @@ client_x11_get_proto(const char *display, const char *xauth_path,
xauthdir = xmalloc(PATH_MAX);
xauthfile = xmalloc(PATH_MAX);
mktemp_proto(xauthdir, PATH_MAX);
+ /*
+ * The authentication cookie should briefly outlive
+ * ssh's willingness to forward X11 connections to
+ * avoid nasty fail-open behaviour in the X server.
+ */
+ if (timeout >= UINT_MAX - X11_TIMEOUT_SLACK)
+ x11_timeout_real = UINT_MAX;
+ else
+ x11_timeout_real = timeout + X11_TIMEOUT_SLACK;
if (mkdtemp(xauthdir) != NULL) {
do_unlink = 1;
snprintf(xauthfile, PATH_MAX, "%s/xauthfile",
@@ -351,17 +361,20 @@ client_x11_get_proto(const char *display, const char *xauth_path,
snprintf(cmd, sizeof(cmd),
"%s -f %s generate %s " SSH_X11_PROTO
" untrusted timeout %u 2>" _PATH_DEVNULL,
- xauth_path, xauthfile, display, timeout);
+ xauth_path, xauthfile, display,
+ x11_timeout_real);
debug2("x11_get_proto: %s", cmd);
- if (system(cmd) == 0)
- generated = 1;
if (x11_refuse_time == 0) {
now = monotime() + 1;
if (UINT_MAX - timeout < now)
x11_refuse_time = UINT_MAX;
else
x11_refuse_time = now + timeout;
+ channel_set_x11_refuse_time(
+ x11_refuse_time);
}
+ if (system(cmd) == 0)
+ generated = 1;
}
}
@@ -1889,7 +1902,7 @@ client_request_x11(const char *request_type, int rchan)
"malicious server.");
return NULL;
}
- if (x11_refuse_time != 0 && monotime() >= x11_refuse_time) {
+ if (x11_refuse_time != 0 && (u_int)monotime() >= x11_refuse_time) {
verbose("Rejected X11 connection after ForwardX11Timeout "
"expired");
return NULL;
|
CWE-264
| null | null |
1,802
|
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";
}
}
|
+Info
| 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";
}
}
|
@@ -16669,7 +16669,10 @@ _PUBLIC_ codepoint_t next_codepoint_handle_ext(
size_t olen;
char *outbuf;
- if ((str[0] & 0x80) == 0) {
+
+ if (((str[0] & 0x80) == 0) && (src_charset == CH_DOS ||
+ src_charset == CH_UNIX ||
+ src_charset == CH_UTF8)) {
*bytes_consumed = 1;
return (codepoint_t)str[0];
}
|
CWE-200
| null | null |
1,803
|
_PUBLIC_ int codepoint_cmpi(codepoint_t c1, codepoint_t c2)
{
if (c1 == c2 ||
toupper_m(c1) == toupper_m(c2)) {
return 0;
}
return c1 - c2;
}
|
+Info
| 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;
}
|
@@ -16669,7 +16669,10 @@ _PUBLIC_ codepoint_t next_codepoint_handle_ext(
size_t olen;
char *outbuf;
- if ((str[0] & 0x80) == 0) {
+
+ if (((str[0] & 0x80) == 0) && (src_charset == CH_DOS ||
+ src_charset == CH_UNIX ||
+ src_charset == CH_UTF8)) {
*bytes_consumed = 1;
return (codepoint_t)str[0];
}
|
CWE-200
| null | null |
1,804
|
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;
}
|
+Info
| 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;
}
|
@@ -16669,7 +16669,10 @@ _PUBLIC_ codepoint_t next_codepoint_handle_ext(
size_t olen;
char *outbuf;
- if ((str[0] & 0x80) == 0) {
+
+ if (((str[0] & 0x80) == 0) && (src_charset == CH_DOS ||
+ src_charset == CH_UNIX ||
+ src_charset == CH_UTF8)) {
*bytes_consumed = 1;
return (codepoint_t)str[0];
}
|
CWE-200
| null | null |
1,805
|
_PUBLIC_ bool islower_m(codepoint_t val)
{
return (toupper_m(val) != val);
}
|
+Info
| 0
|
_PUBLIC_ bool islower_m(codepoint_t val)
{
return (toupper_m(val) != val);
}
|
@@ -16669,7 +16669,10 @@ _PUBLIC_ codepoint_t next_codepoint_handle_ext(
size_t olen;
char *outbuf;
- if ((str[0] & 0x80) == 0) {
+
+ if (((str[0] & 0x80) == 0) && (src_charset == CH_DOS ||
+ src_charset == CH_UNIX ||
+ src_charset == CH_UTF8)) {
*bytes_consumed = 1;
return (codepoint_t)str[0];
}
|
CWE-200
| null | null |
1,806
|
_PUBLIC_ bool isupper_m(codepoint_t val)
{
return (tolower_m(val) != val);
}
|
+Info
| 0
|
_PUBLIC_ bool isupper_m(codepoint_t val)
{
return (tolower_m(val) != val);
}
|
@@ -16669,7 +16669,10 @@ _PUBLIC_ codepoint_t next_codepoint_handle_ext(
size_t olen;
char *outbuf;
- if ((str[0] & 0x80) == 0) {
+
+ if (((str[0] & 0x80) == 0) && (src_charset == CH_DOS ||
+ src_charset == CH_UNIX ||
+ src_charset == CH_UTF8)) {
*bytes_consumed = 1;
return (codepoint_t)str[0];
}
|
CWE-200
| null | null |
1,807
|
_PUBLIC_ codepoint_t next_codepoint(const char *str, size_t *size)
{
return next_codepoint_handle(get_iconv_handle(), str, size);
}
|
+Info
| 0
|
_PUBLIC_ codepoint_t next_codepoint(const char *str, size_t *size)
{
return next_codepoint_handle(get_iconv_handle(), str, size);
}
|
@@ -16669,7 +16669,10 @@ _PUBLIC_ codepoint_t next_codepoint_handle_ext(
size_t olen;
char *outbuf;
- if ((str[0] & 0x80) == 0) {
+
+ if (((str[0] & 0x80) == 0) && (src_charset == CH_DOS ||
+ src_charset == CH_UNIX ||
+ src_charset == CH_UTF8)) {
*bytes_consumed = 1;
return (codepoint_t)str[0];
}
|
CWE-200
| null | null |
1,808
|
_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);
}
|
+Info
| 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);
}
|
@@ -16669,7 +16669,10 @@ _PUBLIC_ codepoint_t next_codepoint_handle_ext(
size_t olen;
char *outbuf;
- if ((str[0] & 0x80) == 0) {
+
+ if (((str[0] & 0x80) == 0) && (src_charset == CH_DOS ||
+ src_charset == CH_UNIX ||
+ src_charset == CH_UTF8)) {
*bytes_consumed = 1;
return (codepoint_t)str[0];
}
|
CWE-200
| null | null |
1,809
|
_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);
}
|
+Info
| 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);
}
|
@@ -16669,7 +16669,10 @@ _PUBLIC_ codepoint_t next_codepoint_handle_ext(
size_t olen;
char *outbuf;
- if ((str[0] & 0x80) == 0) {
+
+ if (((str[0] & 0x80) == 0) && (src_charset == CH_DOS ||
+ src_charset == CH_UNIX ||
+ src_charset == CH_UTF8)) {
*bytes_consumed = 1;
return (codepoint_t)str[0];
}
|
CWE-200
| null | null |
1,810
|
_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;
}
|
+Info
| 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;
}
|
@@ -16669,7 +16669,10 @@ _PUBLIC_ codepoint_t next_codepoint_handle_ext(
size_t olen;
char *outbuf;
- if ((str[0] & 0x80) == 0) {
+
+ if (((str[0] & 0x80) == 0) && (src_charset == CH_DOS ||
+ src_charset == CH_UNIX ||
+ src_charset == CH_UTF8)) {
*bytes_consumed = 1;
return (codepoint_t)str[0];
}
|
CWE-200
| null | null |
1,811
|
_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;
}
|
+Info
| 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;
}
|
@@ -16669,7 +16669,10 @@ _PUBLIC_ codepoint_t next_codepoint_handle_ext(
size_t olen;
char *outbuf;
- if ((str[0] & 0x80) == 0) {
+
+ if (((str[0] & 0x80) == 0) && (src_charset == CH_DOS ||
+ src_charset == CH_UNIX ||
+ src_charset == CH_UTF8)) {
*bytes_consumed = 1;
return (codepoint_t)str[0];
}
|
CWE-200
| null | null |
1,812
|
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
}
|
+Info
| 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
}
|
@@ -16669,7 +16669,10 @@ _PUBLIC_ codepoint_t next_codepoint_handle_ext(
size_t olen;
char *outbuf;
- if ((str[0] & 0x80) == 0) {
+
+ if (((str[0] & 0x80) == 0) && (src_charset == CH_DOS ||
+ src_charset == CH_UNIX ||
+ src_charset == CH_UTF8)) {
*bytes_consumed = 1;
return (codepoint_t)str[0];
}
|
CWE-200
| null | null |
1,813
|
_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];
}
|
+Info
| 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];
}
|
@@ -16669,7 +16669,10 @@ _PUBLIC_ codepoint_t next_codepoint_handle_ext(
size_t olen;
char *outbuf;
- if ((str[0] & 0x80) == 0) {
+
+ if (((str[0] & 0x80) == 0) && (src_charset == CH_DOS ||
+ src_charset == CH_UNIX ||
+ src_charset == CH_UTF8)) {
*bytes_consumed = 1;
return (codepoint_t)str[0];
}
|
CWE-200
| null | null |
1,814
|
_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];
}
|
+Info
| 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];
}
|
@@ -16669,7 +16669,10 @@ _PUBLIC_ codepoint_t next_codepoint_handle_ext(
size_t olen;
char *outbuf;
- if ((str[0] & 0x80) == 0) {
+
+ if (((str[0] & 0x80) == 0) && (src_charset == CH_DOS ||
+ src_charset == CH_UNIX ||
+ src_charset == CH_UTF8)) {
*bytes_consumed = 1;
return (codepoint_t)str[0];
}
|
CWE-200
| null | null |
1,815
|
static void ldb_dn_mark_invalid(struct ldb_dn *dn)
{
dn->invalid = true;
}
|
+Info
| 0
|
static void ldb_dn_mark_invalid(struct ldb_dn *dn)
{
dn->invalid = true;
}
|
@@ -189,33 +189,23 @@ struct ldb_dn *ldb_dn_new_fmt(TALLOC_CTX *mem_ctx,
/* see RFC2253 section 2.4 */
static int ldb_dn_escape_internal(char *dst, const char *src, int len)
{
- const char *p, *s;
+ char c;
char *d;
- size_t l;
-
- p = s = src;
+ int i;
d = dst;
- while (p - src < len) {
- p += strcspn(p, ",=\n\r+<>#;\\\" ");
-
- if (p - src == len) /* found no escapable chars */
- break;
-
- /* copy the part of the string before the stop */
- memcpy(d, s, p - s);
- d += (p - s); /* move to current position */
-
- switch (*p) {
+ for (i = 0; i < len; i++){
+ c = src[i];
+ switch (c) {
case ' ':
- if (p == src || (p-src)==(len-1)) {
+ if (i == 0 || i == len - 1) {
/* if at the beginning or end
* of the string then escape */
*d++ = '\\';
- *d++ = *p++;
+ *d++ = c;
} else {
/* otherwise don't escape */
- *d++ = *p++;
+ *d++ = c;
}
break;
@@ -231,30 +221,30 @@ static int ldb_dn_escape_internal(char *dst, const char *src, int len)
case '?':
/* these must be escaped using \c form */
*d++ = '\\';
- *d++ = *p++;
+ *d++ = c;
break;
- default: {
+ case ';':
+ case '\r':
+ case '\n':
+ case '=':
+ case '\0': {
/* any others get \XX form */
unsigned char v;
const char *hexbytes = "0123456789ABCDEF";
- v = *(const unsigned char *)p;
+ v = (const unsigned char)c;
*d++ = '\\';
*d++ = hexbytes[v>>4];
*d++ = hexbytes[v&0xF];
- p++;
break;
}
+ default:
+ *d++ = c;
}
- s = p; /* move forward */
}
- /* copy the last part (with zero) and return */
- l = len - (s - src);
- memcpy(d, s, l + 1);
-
/* return the length of the resulting string */
- return (l + (d - dst));
+ return (d - dst);
}
char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
|
CWE-200
| null | null |
1,816
|
struct ldb_dn *ldb_dn_new(TALLOC_CTX *mem_ctx,
struct ldb_context *ldb,
const char *strdn)
{
struct ldb_val blob;
blob.data = discard_const_p(uint8_t, strdn);
blob.length = strdn ? strlen(strdn) : 0;
return ldb_dn_from_ldb_val(mem_ctx, ldb, &blob);
}
|
+Info
| 0
|
struct ldb_dn *ldb_dn_new(TALLOC_CTX *mem_ctx,
struct ldb_context *ldb,
const char *strdn)
{
struct ldb_val blob;
blob.data = discard_const_p(uint8_t, strdn);
blob.length = strdn ? strlen(strdn) : 0;
return ldb_dn_from_ldb_val(mem_ctx, ldb, &blob);
}
|
@@ -189,33 +189,23 @@ struct ldb_dn *ldb_dn_new_fmt(TALLOC_CTX *mem_ctx,
/* see RFC2253 section 2.4 */
static int ldb_dn_escape_internal(char *dst, const char *src, int len)
{
- const char *p, *s;
+ char c;
char *d;
- size_t l;
-
- p = s = src;
+ int i;
d = dst;
- while (p - src < len) {
- p += strcspn(p, ",=\n\r+<>#;\\\" ");
-
- if (p - src == len) /* found no escapable chars */
- break;
-
- /* copy the part of the string before the stop */
- memcpy(d, s, p - s);
- d += (p - s); /* move to current position */
-
- switch (*p) {
+ for (i = 0; i < len; i++){
+ c = src[i];
+ switch (c) {
case ' ':
- if (p == src || (p-src)==(len-1)) {
+ if (i == 0 || i == len - 1) {
/* if at the beginning or end
* of the string then escape */
*d++ = '\\';
- *d++ = *p++;
+ *d++ = c;
} else {
/* otherwise don't escape */
- *d++ = *p++;
+ *d++ = c;
}
break;
@@ -231,30 +221,30 @@ static int ldb_dn_escape_internal(char *dst, const char *src, int len)
case '?':
/* these must be escaped using \c form */
*d++ = '\\';
- *d++ = *p++;
+ *d++ = c;
break;
- default: {
+ case ';':
+ case '\r':
+ case '\n':
+ case '=':
+ case '\0': {
/* any others get \XX form */
unsigned char v;
const char *hexbytes = "0123456789ABCDEF";
- v = *(const unsigned char *)p;
+ v = (const unsigned char)c;
*d++ = '\\';
*d++ = hexbytes[v>>4];
*d++ = hexbytes[v&0xF];
- p++;
break;
}
+ default:
+ *d++ = c;
}
- s = p; /* move forward */
}
- /* copy the last part (with zero) and return */
- l = len - (s - src);
- memcpy(d, s, l + 1);
-
/* return the length of the resulting string */
- return (l + (d - dst));
+ return (d - dst);
}
char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
|
CWE-200
| null | null |
1,817
|
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;
}
|
+Info
| 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;
}
|
@@ -189,33 +189,23 @@ struct ldb_dn *ldb_dn_new_fmt(TALLOC_CTX *mem_ctx,
/* see RFC2253 section 2.4 */
static int ldb_dn_escape_internal(char *dst, const char *src, int len)
{
- const char *p, *s;
+ char c;
char *d;
- size_t l;
-
- p = s = src;
+ int i;
d = dst;
- while (p - src < len) {
- p += strcspn(p, ",=\n\r+<>#;\\\" ");
-
- if (p - src == len) /* found no escapable chars */
- break;
-
- /* copy the part of the string before the stop */
- memcpy(d, s, p - s);
- d += (p - s); /* move to current position */
-
- switch (*p) {
+ for (i = 0; i < len; i++){
+ c = src[i];
+ switch (c) {
case ' ':
- if (p == src || (p-src)==(len-1)) {
+ if (i == 0 || i == len - 1) {
/* if at the beginning or end
* of the string then escape */
*d++ = '\\';
- *d++ = *p++;
+ *d++ = c;
} else {
/* otherwise don't escape */
- *d++ = *p++;
+ *d++ = c;
}
break;
@@ -231,30 +221,30 @@ static int ldb_dn_escape_internal(char *dst, const char *src, int len)
case '?':
/* these must be escaped using \c form */
*d++ = '\\';
- *d++ = *p++;
+ *d++ = c;
break;
- default: {
+ case ';':
+ case '\r':
+ case '\n':
+ case '=':
+ case '\0': {
/* any others get \XX form */
unsigned char v;
const char *hexbytes = "0123456789ABCDEF";
- v = *(const unsigned char *)p;
+ v = (const unsigned char)c;
*d++ = '\\';
*d++ = hexbytes[v>>4];
*d++ = hexbytes[v&0xF];
- p++;
break;
}
+ default:
+ *d++ = c;
}
- s = p; /* move forward */
}
- /* copy the last part (with zero) and return */
- l = len - (s - src);
- memcpy(d, s, l + 1);
-
/* return the length of the resulting string */
- return (l + (d - dst));
+ return (d - dst);
}
char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
|
CWE-200
| null | null |
1,818
|
_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;
}
|
+Info
| 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;
}
|
@@ -110,11 +110,12 @@ _PUBLIC_ char *strupper_talloc_n_handle(struct smb_iconv_handle *iconv_handle,
return NULL;
}
- while (n-- && *src) {
+ while (n && *src) {
size_t c_size;
codepoint_t c = next_codepoint_handle_ext(iconv_handle, src, n,
CH_UNIX, &c_size);
src += c_size;
+ n -= c_size;
c = toupper_m(c);
|
CWE-200
| null | null |
1,819
|
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;
}
|
+Info
| 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;
}
|
@@ -110,11 +110,12 @@ _PUBLIC_ char *strupper_talloc_n_handle(struct smb_iconv_handle *iconv_handle,
return NULL;
}
- while (n-- && *src) {
+ while (n && *src) {
size_t c_size;
codepoint_t c = next_codepoint_handle_ext(iconv_handle, src, n,
CH_UNIX, &c_size);
src += c_size;
+ n -= c_size;
c = toupper_m(c);
|
CWE-200
| null | null |
1,820
|
_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;
}
}
|
+Info
| 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;
}
}
|
@@ -110,11 +110,12 @@ _PUBLIC_ char *strupper_talloc_n_handle(struct smb_iconv_handle *iconv_handle,
return NULL;
}
- while (n-- && *src) {
+ while (n && *src) {
size_t c_size;
codepoint_t c = next_codepoint_handle_ext(iconv_handle, src, n,
CH_UNIX, &c_size);
src += c_size;
+ n -= c_size;
c = toupper_m(c);
|
CWE-200
| null | null |
1,821
|
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);
}
|
+Info
| 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);
}
|
@@ -110,11 +110,12 @@ _PUBLIC_ char *strupper_talloc_n_handle(struct smb_iconv_handle *iconv_handle,
return NULL;
}
- while (n-- && *src) {
+ while (n && *src) {
size_t c_size;
codepoint_t c = next_codepoint_handle_ext(iconv_handle, src, n,
CH_UNIX, &c_size);
src += c_size;
+ n -= c_size;
c = toupper_m(c);
|
CWE-200
| null | null |
1,822
|
_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;
}
}
|
+Info
| 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;
}
}
|
@@ -110,11 +110,12 @@ _PUBLIC_ char *strupper_talloc_n_handle(struct smb_iconv_handle *iconv_handle,
return NULL;
}
- while (n-- && *src) {
+ while (n && *src) {
size_t c_size;
codepoint_t c = next_codepoint_handle_ext(iconv_handle, src, n,
CH_UNIX, &c_size);
src += c_size;
+ n -= c_size;
c = toupper_m(c);
|
CWE-200
| null | null |
1,823
|
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;
}
|
+Info
| 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;
}
|
@@ -110,11 +110,12 @@ _PUBLIC_ char *strupper_talloc_n_handle(struct smb_iconv_handle *iconv_handle,
return NULL;
}
- while (n-- && *src) {
+ while (n && *src) {
size_t c_size;
codepoint_t c = next_codepoint_handle_ext(iconv_handle, src, n,
CH_UNIX, &c_size);
src += c_size;
+ n -= c_size;
c = toupper_m(c);
|
CWE-200
| null | null |
1,824
|
_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);
}
|
+Info
| 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);
}
|
@@ -110,11 +110,12 @@ _PUBLIC_ char *strupper_talloc_n_handle(struct smb_iconv_handle *iconv_handle,
return NULL;
}
- while (n-- && *src) {
+ while (n && *src) {
size_t c_size;
codepoint_t c = next_codepoint_handle_ext(iconv_handle, src, n,
CH_UNIX, &c_size);
src += c_size;
+ n -= c_size;
c = toupper_m(c);
|
CWE-200
| null | null |
1,825
|
_PUBLIC_ char *strlower_talloc_handle(struct smb_iconv_handle *iconv_handle,
TALLOC_CTX *ctx, const char *src)
{
size_t size=0;
char *dest;
if(src == NULL) {
return NULL;
}
/* this takes advantage of the fact that upper/lower can't
change the length of a character by more than 1 byte */
dest = talloc_array(ctx, char, 2*(strlen(src))+1);
if (dest == NULL) {
return NULL;
}
while (*src) {
size_t c_size;
codepoint_t c = next_codepoint_handle(iconv_handle, src, &c_size);
src += c_size;
c = tolower_m(c);
c_size = push_codepoint_handle(iconv_handle, dest+size, c);
if (c_size == -1) {
talloc_free(dest);
return NULL;
}
size += c_size;
}
dest[size] = 0;
/* trim it so talloc_append_string() works */
dest = talloc_realloc(ctx, dest, char, size+1);
talloc_set_name_const(dest, dest);
return dest;
}
|
+Info
| 0
|
_PUBLIC_ char *strlower_talloc_handle(struct smb_iconv_handle *iconv_handle,
TALLOC_CTX *ctx, const char *src)
{
size_t size=0;
char *dest;
if(src == NULL) {
return NULL;
}
/* this takes advantage of the fact that upper/lower can't
change the length of a character by more than 1 byte */
dest = talloc_array(ctx, char, 2*(strlen(src))+1);
if (dest == NULL) {
return NULL;
}
while (*src) {
size_t c_size;
codepoint_t c = next_codepoint_handle(iconv_handle, src, &c_size);
src += c_size;
c = tolower_m(c);
c_size = push_codepoint_handle(iconv_handle, dest+size, c);
if (c_size == -1) {
talloc_free(dest);
return NULL;
}
size += c_size;
}
dest[size] = 0;
/* trim it so talloc_append_string() works */
dest = talloc_realloc(ctx, dest, char, size+1);
talloc_set_name_const(dest, dest);
return dest;
}
|
@@ -110,11 +110,12 @@ _PUBLIC_ char *strupper_talloc_n_handle(struct smb_iconv_handle *iconv_handle,
return NULL;
}
- while (n-- && *src) {
+ while (n && *src) {
size_t c_size;
codepoint_t c = next_codepoint_handle_ext(iconv_handle, src, n,
CH_UNIX, &c_size);
src += c_size;
+ n -= c_size;
c = toupper_m(c);
|
CWE-200
| null | null |
1,826
|
_PUBLIC_ char *strupper_talloc(TALLOC_CTX *ctx, const char *src)
{
return strupper_talloc_n(ctx, src, src?strlen(src):0);
}
|
+Info
| 0
|
_PUBLIC_ char *strupper_talloc(TALLOC_CTX *ctx, const char *src)
{
return strupper_talloc_n(ctx, src, src?strlen(src):0);
}
|
@@ -110,11 +110,12 @@ _PUBLIC_ char *strupper_talloc_n_handle(struct smb_iconv_handle *iconv_handle,
return NULL;
}
- while (n-- && *src) {
+ while (n && *src) {
size_t c_size;
codepoint_t c = next_codepoint_handle_ext(iconv_handle, src, n,
CH_UNIX, &c_size);
src += c_size;
+ n -= c_size;
c = toupper_m(c);
|
CWE-200
| null | null |
1,827
|
_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);
}
|
+Info
| 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);
}
|
@@ -110,11 +110,12 @@ _PUBLIC_ char *strupper_talloc_n_handle(struct smb_iconv_handle *iconv_handle,
return NULL;
}
- while (n-- && *src) {
+ while (n && *src) {
size_t c_size;
codepoint_t c = next_codepoint_handle_ext(iconv_handle, src, n,
CH_UNIX, &c_size);
src += c_size;
+ n -= c_size;
c = toupper_m(c);
|
CWE-200
| null | null |
1,828
|
_PUBLIC_ char *talloc_strdup_upper(TALLOC_CTX *ctx, const char *src)
{
return strupper_talloc(ctx, src);
}
|
+Info
| 0
|
_PUBLIC_ char *talloc_strdup_upper(TALLOC_CTX *ctx, const char *src)
{
return strupper_talloc(ctx, src);
}
|
@@ -110,11 +110,12 @@ _PUBLIC_ char *strupper_talloc_n_handle(struct smb_iconv_handle *iconv_handle,
return NULL;
}
- while (n-- && *src) {
+ while (n && *src) {
size_t c_size;
codepoint_t c = next_codepoint_handle_ext(iconv_handle, src, n,
CH_UNIX, &c_size);
src += c_size;
+ n -= c_size;
c = toupper_m(c);
|
CWE-200
| null | null |
1,829
|
_PUBLIC_ int strcasecmp_m(const char *s1, const char *s2)
{
struct smb_iconv_handle *iconv_handle = get_iconv_handle();
return strcasecmp_m_handle(iconv_handle, s1, s2);
}
|
+Info
| 0
|
_PUBLIC_ int strcasecmp_m(const char *s1, const char *s2)
{
struct smb_iconv_handle *iconv_handle = get_iconv_handle();
return strcasecmp_m_handle(iconv_handle, s1, s2);
}
|
@@ -210,7 +210,8 @@ _PUBLIC_ size_t strlen_m_ext_handle(struct smb_iconv_handle *ic,
while (*s) {
size_t c_size;
- codepoint_t c = next_codepoint_handle_ext(ic, s, src_charset, &c_size);
+ codepoint_t c = next_codepoint_handle_ext(ic, s, strnlen(s, 5),
+ src_charset, &c_size);
s += c_size;
switch (dst_charset) {
|
CWE-200
| null | null |
1,830
|
_PUBLIC_ int strcasecmp_m_handle(struct smb_iconv_handle *iconv_handle,
const char *s1, const char *s2)
{
codepoint_t c1=0, c2=0;
size_t size1, size2;
/* handle null ptr comparisons to simplify the use in qsort */
if (s1 == s2) return 0;
if (s1 == NULL) return -1;
if (s2 == NULL) return 1;
while (*s1 && *s2) {
c1 = next_codepoint_handle(iconv_handle, s1, &size1);
c2 = next_codepoint_handle(iconv_handle, s2, &size2);
if (c1 == INVALID_CODEPOINT ||
c2 == INVALID_CODEPOINT) {
return strcasecmp(s1, s2);
}
s1 += size1;
s2 += size2;
if (c1 == c2) {
continue;
}
if (toupper_m(c1) != toupper_m(c2)) {
return c1 - c2;
}
}
return *s1 - *s2;
}
|
+Info
| 0
|
_PUBLIC_ int strcasecmp_m_handle(struct smb_iconv_handle *iconv_handle,
const char *s1, const char *s2)
{
codepoint_t c1=0, c2=0;
size_t size1, size2;
/* handle null ptr comparisons to simplify the use in qsort */
if (s1 == s2) return 0;
if (s1 == NULL) return -1;
if (s2 == NULL) return 1;
while (*s1 && *s2) {
c1 = next_codepoint_handle(iconv_handle, s1, &size1);
c2 = next_codepoint_handle(iconv_handle, s2, &size2);
if (c1 == INVALID_CODEPOINT ||
c2 == INVALID_CODEPOINT) {
return strcasecmp(s1, s2);
}
s1 += size1;
s2 += size2;
if (c1 == c2) {
continue;
}
if (toupper_m(c1) != toupper_m(c2)) {
return c1 - c2;
}
}
return *s1 - *s2;
}
|
@@ -210,7 +210,8 @@ _PUBLIC_ size_t strlen_m_ext_handle(struct smb_iconv_handle *ic,
while (*s) {
size_t c_size;
- codepoint_t c = next_codepoint_handle_ext(ic, s, src_charset, &c_size);
+ codepoint_t c = next_codepoint_handle_ext(ic, s, strnlen(s, 5),
+ src_charset, &c_size);
s += c_size;
switch (dst_charset) {
|
CWE-200
| null | null |
1,831
|
_PUBLIC_ char *strchr_m(const char *src, char c)
{
const char *s;
struct smb_iconv_handle *ic = get_iconv_handle();
if (src == NULL) {
return NULL;
}
/* characters below 0x3F are guaranteed to not appear in
non-initial position in multi-byte charsets */
if ((c & 0xC0) == 0) {
return strchr(src, c);
}
/* this is quite a common operation, so we want it to be
fast. We optimise for the ascii case, knowing that all our
supported multi-byte character sets are ascii-compatible
(ie. they match for the first 128 chars) */
for (s = src; *s && !(((unsigned char)s[0]) & 0x80); s++) {
if (*s == c)
return discard_const_p(char, s);
}
if (!*s)
return NULL;
#ifdef BROKEN_UNICODE_COMPOSE_CHARACTERS
/* With compose characters we must restart from the beginning. JRA. */
s = src;
#endif
while (*s) {
size_t size;
codepoint_t c2 = next_codepoint_handle(ic, s, &size);
if (c2 == c) {
return discard_const_p(char, s);
}
s += size;
}
return NULL;
}
|
+Info
| 0
|
_PUBLIC_ char *strchr_m(const char *src, char c)
{
const char *s;
struct smb_iconv_handle *ic = get_iconv_handle();
if (src == NULL) {
return NULL;
}
/* characters below 0x3F are guaranteed to not appear in
non-initial position in multi-byte charsets */
if ((c & 0xC0) == 0) {
return strchr(src, c);
}
/* this is quite a common operation, so we want it to be
fast. We optimise for the ascii case, knowing that all our
supported multi-byte character sets are ascii-compatible
(ie. they match for the first 128 chars) */
for (s = src; *s && !(((unsigned char)s[0]) & 0x80); s++) {
if (*s == c)
return discard_const_p(char, s);
}
if (!*s)
return NULL;
#ifdef BROKEN_UNICODE_COMPOSE_CHARACTERS
/* With compose characters we must restart from the beginning. JRA. */
s = src;
#endif
while (*s) {
size_t size;
codepoint_t c2 = next_codepoint_handle(ic, s, &size);
if (c2 == c) {
return discard_const_p(char, s);
}
s += size;
}
return NULL;
}
|
@@ -210,7 +210,8 @@ _PUBLIC_ size_t strlen_m_ext_handle(struct smb_iconv_handle *ic,
while (*s) {
size_t c_size;
- codepoint_t c = next_codepoint_handle_ext(ic, s, src_charset, &c_size);
+ codepoint_t c = next_codepoint_handle_ext(ic, s, strnlen(s, 5),
+ src_charset, &c_size);
s += c_size;
switch (dst_charset) {
|
CWE-200
| null | null |
1,832
|
_PUBLIC_ bool strcsequal(const char *s1,const char *s2)
{
if (s1 == s2)
return true;
if (!s1 || !s2)
return false;
return strcmp(s1,s2) == 0;
}
|
+Info
| 0
|
_PUBLIC_ bool strcsequal(const char *s1,const char *s2)
{
if (s1 == s2)
return true;
if (!s1 || !s2)
return false;
return strcmp(s1,s2) == 0;
}
|
@@ -210,7 +210,8 @@ _PUBLIC_ size_t strlen_m_ext_handle(struct smb_iconv_handle *ic,
while (*s) {
size_t c_size;
- codepoint_t c = next_codepoint_handle_ext(ic, s, src_charset, &c_size);
+ codepoint_t c = next_codepoint_handle_ext(ic, s, strnlen(s, 5),
+ src_charset, &c_size);
s += c_size;
switch (dst_charset) {
|
CWE-200
| null | null |
1,833
|
_PUBLIC_ bool strequal_m(const char *s1, const char *s2)
{
return strcasecmp_m(s1,s2) == 0;
}
|
+Info
| 0
|
_PUBLIC_ bool strequal_m(const char *s1, const char *s2)
{
return strcasecmp_m(s1,s2) == 0;
}
|
@@ -210,7 +210,8 @@ _PUBLIC_ size_t strlen_m_ext_handle(struct smb_iconv_handle *ic,
while (*s) {
size_t c_size;
- codepoint_t c = next_codepoint_handle_ext(ic, s, src_charset, &c_size);
+ codepoint_t c = next_codepoint_handle_ext(ic, s, strnlen(s, 5),
+ src_charset, &c_size);
s += c_size;
switch (dst_charset) {
|
CWE-200
| null | null |
1,834
|
_PUBLIC_ bool strhaslower(const char *string)
{
struct smb_iconv_handle *ic = get_iconv_handle();
return strhaslower_handle(ic, string);
}
|
+Info
| 0
|
_PUBLIC_ bool strhaslower(const char *string)
{
struct smb_iconv_handle *ic = get_iconv_handle();
return strhaslower_handle(ic, string);
}
|
@@ -210,7 +210,8 @@ _PUBLIC_ size_t strlen_m_ext_handle(struct smb_iconv_handle *ic,
while (*s) {
size_t c_size;
- codepoint_t c = next_codepoint_handle_ext(ic, s, src_charset, &c_size);
+ codepoint_t c = next_codepoint_handle_ext(ic, s, strnlen(s, 5),
+ src_charset, &c_size);
s += c_size;
switch (dst_charset) {
|
CWE-200
| null | null |
1,835
|
_PUBLIC_ bool strhaslower_handle(struct smb_iconv_handle *ic,
const char *string)
{
while (*string) {
size_t c_size;
codepoint_t s;
codepoint_t t;
s = next_codepoint_handle(ic, string, &c_size);
string += c_size;
t = toupper_m(s);
if (s != t) {
return true; /* that means it has lower case chars */
}
}
return false;
}
|
+Info
| 0
|
_PUBLIC_ bool strhaslower_handle(struct smb_iconv_handle *ic,
const char *string)
{
while (*string) {
size_t c_size;
codepoint_t s;
codepoint_t t;
s = next_codepoint_handle(ic, string, &c_size);
string += c_size;
t = toupper_m(s);
if (s != t) {
return true; /* that means it has lower case chars */
}
}
return false;
}
|
@@ -210,7 +210,8 @@ _PUBLIC_ size_t strlen_m_ext_handle(struct smb_iconv_handle *ic,
while (*s) {
size_t c_size;
- codepoint_t c = next_codepoint_handle_ext(ic, s, src_charset, &c_size);
+ codepoint_t c = next_codepoint_handle_ext(ic, s, strnlen(s, 5),
+ src_charset, &c_size);
s += c_size;
switch (dst_charset) {
|
CWE-200
| null | null |
1,836
|
_PUBLIC_ bool strhasupper(const char *string)
{
struct smb_iconv_handle *ic = get_iconv_handle();
return strhasupper_handle(ic, string);
}
|
+Info
| 0
|
_PUBLIC_ bool strhasupper(const char *string)
{
struct smb_iconv_handle *ic = get_iconv_handle();
return strhasupper_handle(ic, string);
}
|
@@ -210,7 +210,8 @@ _PUBLIC_ size_t strlen_m_ext_handle(struct smb_iconv_handle *ic,
while (*s) {
size_t c_size;
- codepoint_t c = next_codepoint_handle_ext(ic, s, src_charset, &c_size);
+ codepoint_t c = next_codepoint_handle_ext(ic, s, strnlen(s, 5),
+ src_charset, &c_size);
s += c_size;
switch (dst_charset) {
|
CWE-200
| null | null |
1,837
|
_PUBLIC_ bool strhasupper_handle(struct smb_iconv_handle *ic,
const char *string)
{
while (*string) {
size_t c_size;
codepoint_t s;
codepoint_t t;
s = next_codepoint_handle(ic, string, &c_size);
string += c_size;
t = tolower_m(s);
if (s != t) {
return true; /* that means it has upper case chars */
}
}
return false;
}
|
+Info
| 0
|
_PUBLIC_ bool strhasupper_handle(struct smb_iconv_handle *ic,
const char *string)
{
while (*string) {
size_t c_size;
codepoint_t s;
codepoint_t t;
s = next_codepoint_handle(ic, string, &c_size);
string += c_size;
t = tolower_m(s);
if (s != t) {
return true; /* that means it has upper case chars */
}
}
return false;
}
|
@@ -210,7 +210,8 @@ _PUBLIC_ size_t strlen_m_ext_handle(struct smb_iconv_handle *ic,
while (*s) {
size_t c_size;
- codepoint_t c = next_codepoint_handle_ext(ic, s, src_charset, &c_size);
+ codepoint_t c = next_codepoint_handle_ext(ic, s, strnlen(s, 5),
+ src_charset, &c_size);
s += c_size;
switch (dst_charset) {
|
CWE-200
| null | null |
1,838
|
_PUBLIC_ size_t strlen_m(const char *s)
{
return strlen_m_ext(s, CH_UNIX, CH_UTF16LE);
}
|
+Info
| 0
|
_PUBLIC_ size_t strlen_m(const char *s)
{
return strlen_m_ext(s, CH_UNIX, CH_UTF16LE);
}
|
@@ -210,7 +210,8 @@ _PUBLIC_ size_t strlen_m_ext_handle(struct smb_iconv_handle *ic,
while (*s) {
size_t c_size;
- codepoint_t c = next_codepoint_handle_ext(ic, s, src_charset, &c_size);
+ codepoint_t c = next_codepoint_handle_ext(ic, s, strnlen(s, 5),
+ src_charset, &c_size);
s += c_size;
switch (dst_charset) {
|
CWE-200
| null | null |
1,839
|
_PUBLIC_ size_t strlen_m_ext(const char *s, charset_t src_charset, charset_t dst_charset)
{
struct smb_iconv_handle *ic = get_iconv_handle();
return strlen_m_ext_handle(ic, s, src_charset, dst_charset);
}
|
+Info
| 0
|
_PUBLIC_ size_t strlen_m_ext(const char *s, charset_t src_charset, charset_t dst_charset)
{
struct smb_iconv_handle *ic = get_iconv_handle();
return strlen_m_ext_handle(ic, s, src_charset, dst_charset);
}
|
@@ -210,7 +210,8 @@ _PUBLIC_ size_t strlen_m_ext_handle(struct smb_iconv_handle *ic,
while (*s) {
size_t c_size;
- codepoint_t c = next_codepoint_handle_ext(ic, s, src_charset, &c_size);
+ codepoint_t c = next_codepoint_handle_ext(ic, s, strnlen(s, 5),
+ src_charset, &c_size);
s += c_size;
switch (dst_charset) {
|
CWE-200
| null | null |
1,840
|
_PUBLIC_ size_t strlen_m_ext_term(const char *s, const charset_t src_charset,
const charset_t dst_charset)
{
if (!s) {
return 0;
}
return strlen_m_ext(s, src_charset, dst_charset) + 1;
}
|
+Info
| 0
|
_PUBLIC_ size_t strlen_m_ext_term(const char *s, const charset_t src_charset,
const charset_t dst_charset)
{
if (!s) {
return 0;
}
return strlen_m_ext(s, src_charset, dst_charset) + 1;
}
|
@@ -210,7 +210,8 @@ _PUBLIC_ size_t strlen_m_ext_handle(struct smb_iconv_handle *ic,
while (*s) {
size_t c_size;
- codepoint_t c = next_codepoint_handle_ext(ic, s, src_charset, &c_size);
+ codepoint_t c = next_codepoint_handle_ext(ic, s, strnlen(s, 5),
+ src_charset, &c_size);
s += c_size;
switch (dst_charset) {
|
CWE-200
| null | null |
1,841
|
_PUBLIC_ size_t strlen_m_ext_term_null(const char *s,
const charset_t src_charset,
const charset_t dst_charset)
{
size_t len;
if (!s) {
return 0;
}
len = strlen_m_ext(s, src_charset, dst_charset);
if (len == 0) {
return 0;
}
return len+1;
}
|
+Info
| 0
|
_PUBLIC_ size_t strlen_m_ext_term_null(const char *s,
const charset_t src_charset,
const charset_t dst_charset)
{
size_t len;
if (!s) {
return 0;
}
len = strlen_m_ext(s, src_charset, dst_charset);
if (len == 0) {
return 0;
}
return len+1;
}
|
@@ -210,7 +210,8 @@ _PUBLIC_ size_t strlen_m_ext_handle(struct smb_iconv_handle *ic,
while (*s) {
size_t c_size;
- codepoint_t c = next_codepoint_handle_ext(ic, s, src_charset, &c_size);
+ codepoint_t c = next_codepoint_handle_ext(ic, s, strnlen(s, 5),
+ src_charset, &c_size);
s += c_size;
switch (dst_charset) {
|
CWE-200
| null | null |
1,842
|
_PUBLIC_ size_t strlen_m_term(const char *s)
{
return strlen_m_ext_term(s, CH_UNIX, CH_UTF16LE);
}
|
+Info
| 0
|
_PUBLIC_ size_t strlen_m_term(const char *s)
{
return strlen_m_ext_term(s, CH_UNIX, CH_UTF16LE);
}
|
@@ -210,7 +210,8 @@ _PUBLIC_ size_t strlen_m_ext_handle(struct smb_iconv_handle *ic,
while (*s) {
size_t c_size;
- codepoint_t c = next_codepoint_handle_ext(ic, s, src_charset, &c_size);
+ codepoint_t c = next_codepoint_handle_ext(ic, s, strnlen(s, 5),
+ src_charset, &c_size);
s += c_size;
switch (dst_charset) {
|
CWE-200
| null | null |
1,843
|
_PUBLIC_ size_t strlen_m_term_null(const char *s)
{
return strlen_m_ext_term_null(s, CH_UNIX, CH_UTF16LE);
}
|
+Info
| 0
|
_PUBLIC_ size_t strlen_m_term_null(const char *s)
{
return strlen_m_ext_term_null(s, CH_UNIX, CH_UTF16LE);
}
|
@@ -210,7 +210,8 @@ _PUBLIC_ size_t strlen_m_ext_handle(struct smb_iconv_handle *ic,
while (*s) {
size_t c_size;
- codepoint_t c = next_codepoint_handle_ext(ic, s, src_charset, &c_size);
+ codepoint_t c = next_codepoint_handle_ext(ic, s, strnlen(s, 5),
+ src_charset, &c_size);
s += c_size;
switch (dst_charset) {
|
CWE-200
| null | null |
1,844
|
_PUBLIC_ int strncasecmp_m(const char *s1, const char *s2, size_t n)
{
struct smb_iconv_handle *iconv_handle = get_iconv_handle();
return strncasecmp_m_handle(iconv_handle, s1, s2, n);
}
|
+Info
| 0
|
_PUBLIC_ int strncasecmp_m(const char *s1, const char *s2, size_t n)
{
struct smb_iconv_handle *iconv_handle = get_iconv_handle();
return strncasecmp_m_handle(iconv_handle, s1, s2, n);
}
|
@@ -210,7 +210,8 @@ _PUBLIC_ size_t strlen_m_ext_handle(struct smb_iconv_handle *ic,
while (*s) {
size_t c_size;
- codepoint_t c = next_codepoint_handle_ext(ic, s, src_charset, &c_size);
+ codepoint_t c = next_codepoint_handle_ext(ic, s, strnlen(s, 5),
+ src_charset, &c_size);
s += c_size;
switch (dst_charset) {
|
CWE-200
| null | null |
1,845
|
_PUBLIC_ char *strrchr_m(const char *s, char c)
{
struct smb_iconv_handle *ic;
char *ret = NULL;
if (s == NULL) {
return NULL;
}
/* characters below 0x3F are guaranteed to not appear in
non-initial position in multi-byte charsets */
if ((c & 0xC0) == 0) {
return strrchr(s, c);
}
/* this is quite a common operation, so we want it to be
fast. We optimise for the ascii case, knowing that all our
supported multi-byte character sets are ascii-compatible
(ie. they match for the first 128 chars). Also, in Samba
we only search for ascii characters in 'c' and that
in all mb character sets with a compound character
containing c, if 'c' is not a match at position
p, then p[-1] > 0x7f. JRA. */
{
size_t len = strlen(s);
const char *cp = s;
bool got_mb = false;
if (len == 0)
return NULL;
cp += (len - 1);
do {
if (c == *cp) {
/* Could be a match. Part of a multibyte ? */
if ((cp > s) &&
(((unsigned char)cp[-1]) & 0x80)) {
/* Yep - go slow :-( */
got_mb = true;
break;
}
/* No - we have a match ! */
return discard_const_p(char , cp);
}
} while (cp-- != s);
if (!got_mb)
return NULL;
}
ic = get_iconv_handle();
while (*s) {
size_t size;
codepoint_t c2 = next_codepoint_handle(ic, s, &size);
if (c2 == c) {
ret = discard_const_p(char, s);
}
s += size;
}
return ret;
}
|
+Info
| 0
|
_PUBLIC_ char *strrchr_m(const char *s, char c)
{
struct smb_iconv_handle *ic;
char *ret = NULL;
if (s == NULL) {
return NULL;
}
/* characters below 0x3F are guaranteed to not appear in
non-initial position in multi-byte charsets */
if ((c & 0xC0) == 0) {
return strrchr(s, c);
}
/* this is quite a common operation, so we want it to be
fast. We optimise for the ascii case, knowing that all our
supported multi-byte character sets are ascii-compatible
(ie. they match for the first 128 chars). Also, in Samba
we only search for ascii characters in 'c' and that
in all mb character sets with a compound character
containing c, if 'c' is not a match at position
p, then p[-1] > 0x7f. JRA. */
{
size_t len = strlen(s);
const char *cp = s;
bool got_mb = false;
if (len == 0)
return NULL;
cp += (len - 1);
do {
if (c == *cp) {
/* Could be a match. Part of a multibyte ? */
if ((cp > s) &&
(((unsigned char)cp[-1]) & 0x80)) {
/* Yep - go slow :-( */
got_mb = true;
break;
}
/* No - we have a match ! */
return discard_const_p(char , cp);
}
} while (cp-- != s);
if (!got_mb)
return NULL;
}
ic = get_iconv_handle();
while (*s) {
size_t size;
codepoint_t c2 = next_codepoint_handle(ic, s, &size);
if (c2 == c) {
ret = discard_const_p(char, s);
}
s += size;
}
return ret;
}
|
@@ -210,7 +210,8 @@ _PUBLIC_ size_t strlen_m_ext_handle(struct smb_iconv_handle *ic,
while (*s) {
size_t c_size;
- codepoint_t c = next_codepoint_handle_ext(ic, s, src_charset, &c_size);
+ codepoint_t c = next_codepoint_handle_ext(ic, s, strnlen(s, 5),
+ src_charset, &c_size);
s += c_size;
switch (dst_charset) {
|
CWE-200
| null | null |
1,846
|
char *strstr_m(const char *src, const char *findstr)
{
smb_ucs2_t *p;
smb_ucs2_t *src_w, *find_w;
const char *s;
char *s2;
char *retp;
size_t converted_size, findstr_len = 0;
TALLOC_CTX *frame; /* Only set up in the iconv case */
/* for correctness */
if (!findstr[0]) {
return discard_const_p(char, src);
}
/* Samba does single character findstr calls a *lot*. */
if (findstr[1] == '\0')
return strchr_m(src, *findstr);
/* We optimise for the ascii case, knowing that all our
supported multi-byte character sets are ascii-compatible
(ie. they match for the first 128 chars) */
for (s = src; *s && !(((unsigned char)s[0]) & 0x80); s++) {
if (*s == *findstr) {
if (!findstr_len)
findstr_len = strlen(findstr);
if (strncmp(s, findstr, findstr_len) == 0) {
return discard_const_p(char, s);
}
}
}
if (!*s)
return NULL;
#if 1 /* def BROKEN_UNICODE_COMPOSE_CHARACTERS */
/* 'make check' fails unless we do this */
/* With compose characters we must restart from the beginning. JRA. */
s = src;
#endif
frame = talloc_stackframe();
if (!push_ucs2_talloc(frame, &src_w, src, &converted_size)) {
DBG_WARNING("src malloc fail\n");
TALLOC_FREE(frame);
return NULL;
}
if (!push_ucs2_talloc(frame, &find_w, findstr, &converted_size)) {
DBG_WARNING("find malloc fail\n");
TALLOC_FREE(frame);
return NULL;
}
p = strstr_w(src_w, find_w);
if (!p) {
TALLOC_FREE(frame);
return NULL;
}
*p = 0;
if (!pull_ucs2_talloc(frame, &s2, src_w, &converted_size)) {
TALLOC_FREE(frame);
DEBUG(0,("strstr_m: dest malloc fail\n"));
return NULL;
}
retp = discard_const_p(char, (s+strlen(s2)));
TALLOC_FREE(frame);
return retp;
}
|
+Info
| 0
|
char *strstr_m(const char *src, const char *findstr)
{
smb_ucs2_t *p;
smb_ucs2_t *src_w, *find_w;
const char *s;
char *s2;
char *retp;
size_t converted_size, findstr_len = 0;
TALLOC_CTX *frame; /* Only set up in the iconv case */
/* for correctness */
if (!findstr[0]) {
return discard_const_p(char, src);
}
/* Samba does single character findstr calls a *lot*. */
if (findstr[1] == '\0')
return strchr_m(src, *findstr);
/* We optimise for the ascii case, knowing that all our
supported multi-byte character sets are ascii-compatible
(ie. they match for the first 128 chars) */
for (s = src; *s && !(((unsigned char)s[0]) & 0x80); s++) {
if (*s == *findstr) {
if (!findstr_len)
findstr_len = strlen(findstr);
if (strncmp(s, findstr, findstr_len) == 0) {
return discard_const_p(char, s);
}
}
}
if (!*s)
return NULL;
#if 1 /* def BROKEN_UNICODE_COMPOSE_CHARACTERS */
/* 'make check' fails unless we do this */
/* With compose characters we must restart from the beginning. JRA. */
s = src;
#endif
frame = talloc_stackframe();
if (!push_ucs2_talloc(frame, &src_w, src, &converted_size)) {
DBG_WARNING("src malloc fail\n");
TALLOC_FREE(frame);
return NULL;
}
if (!push_ucs2_talloc(frame, &find_w, findstr, &converted_size)) {
DBG_WARNING("find malloc fail\n");
TALLOC_FREE(frame);
return NULL;
}
p = strstr_w(src_w, find_w);
if (!p) {
TALLOC_FREE(frame);
return NULL;
}
*p = 0;
if (!pull_ucs2_talloc(frame, &s2, src_w, &converted_size)) {
TALLOC_FREE(frame);
DEBUG(0,("strstr_m: dest malloc fail\n"));
return NULL;
}
retp = discard_const_p(char, (s+strlen(s2)));
TALLOC_FREE(frame);
return retp;
}
|
@@ -210,7 +210,8 @@ _PUBLIC_ size_t strlen_m_ext_handle(struct smb_iconv_handle *ic,
while (*s) {
size_t c_size;
- codepoint_t c = next_codepoint_handle_ext(ic, s, src_charset, &c_size);
+ codepoint_t c = next_codepoint_handle_ext(ic, s, strnlen(s, 5),
+ src_charset, &c_size);
s += c_size;
switch (dst_charset) {
|
CWE-200
| null | null |
1,847
|
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);
}
|
+Info
| 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);
}
|
@@ -586,12 +586,15 @@ static bool ldb_dn_explode(struct ldb_dn *dn)
p++;
*d++ = '\0';
- dn->components[dn->comp_num].value.data = (uint8_t *)talloc_strdup(dn->components, dt);
+ dn->components[dn->comp_num].value.data = \
+ (uint8_t *)talloc_memdup(dn->components, dt, l + 1);
dn->components[dn->comp_num].value.length = l;
if ( ! dn->components[dn->comp_num].value.data) {
/* ouch ! */
goto failed;
}
+ talloc_set_name_const(dn->components[dn->comp_num].value.data,
+ (const char *)dn->components[dn->comp_num].value.data);
dt = d;
@@ -707,11 +710,13 @@ static bool ldb_dn_explode(struct ldb_dn *dn)
*d++ = '\0';
dn->components[dn->comp_num].value.length = l;
dn->components[dn->comp_num].value.data =
- (uint8_t *)talloc_strdup(dn->components, dt);
+ (uint8_t *)talloc_memdup(dn->components, dt, l + 1);
if ( ! dn->components[dn->comp_num].value.data) {
/* ouch */
goto failed;
}
+ talloc_set_name_const(dn->components[dn->comp_num].value.data,
+ (const char *)dn->components[dn->comp_num].value.data);
dn->comp_num++;
|
CWE-200
| null | null |
1,848
|
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;
}
|
+Info
| 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;
}
|
@@ -250,7 +250,7 @@ static int ldb_dn_escape_internal(char *dst, const char *src, int len)
char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
{
char *dst;
-
+ size_t len;
if (!value.length)
return NULL;
@@ -261,10 +261,14 @@ char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
return NULL;
}
- ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
-
- dst = talloc_realloc(mem_ctx, dst, char, strlen(dst) + 1);
+ len = ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
+ dst = talloc_realloc(mem_ctx, dst, char, len + 1);
+ if ( ! dst) {
+ talloc_free(dst);
+ return NULL;
+ }
+ dst[len] = '\0';
return dst;
}
|
CWE-200
| null | null |
1,849
|
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;
}
|
+Info
| 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;
}
|
@@ -250,7 +250,7 @@ static int ldb_dn_escape_internal(char *dst, const char *src, int len)
char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
{
char *dst;
-
+ size_t len;
if (!value.length)
return NULL;
@@ -261,10 +261,14 @@ char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
return NULL;
}
- ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
-
- dst = talloc_realloc(mem_ctx, dst, char, strlen(dst) + 1);
+ len = ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
+ dst = talloc_realloc(mem_ctx, dst, char, len + 1);
+ if ( ! dst) {
+ talloc_free(dst);
+ return NULL;
+ }
+ dst[len] = '\0';
return dst;
}
|
CWE-200
| null | null |
1,850
|
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;
}
|
+Info
| 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;
}
|
@@ -250,7 +250,7 @@ static int ldb_dn_escape_internal(char *dst, const char *src, int len)
char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
{
char *dst;
-
+ size_t len;
if (!value.length)
return NULL;
@@ -261,10 +261,14 @@ char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
return NULL;
}
- ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
-
- dst = talloc_realloc(mem_ctx, dst, char, strlen(dst) + 1);
+ len = ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
+ dst = talloc_realloc(mem_ctx, dst, char, len + 1);
+ if ( ! dst) {
+ talloc_free(dst);
+ return NULL;
+ }
+ dst[len] = '\0';
return dst;
}
|
CWE-200
| null | null |
1,851
|
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;
}
|
+Info
| 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;
}
|
@@ -250,7 +250,7 @@ static int ldb_dn_escape_internal(char *dst, const char *src, int len)
char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
{
char *dst;
-
+ size_t len;
if (!value.length)
return NULL;
@@ -261,10 +261,14 @@ char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
return NULL;
}
- ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
-
- dst = talloc_realloc(mem_ctx, dst, char, strlen(dst) + 1);
+ len = ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
+ dst = talloc_realloc(mem_ctx, dst, char, len + 1);
+ if ( ! dst) {
+ talloc_free(dst);
+ return NULL;
+ }
+ dst[len] = '\0';
return dst;
}
|
CWE-200
| null | null |
1,852
|
char *ldb_dn_alloc_linearized(TALLOC_CTX *mem_ctx, struct ldb_dn *dn)
{
return talloc_strdup(mem_ctx, ldb_dn_get_linearized(dn));
}
|
+Info
| 0
|
char *ldb_dn_alloc_linearized(TALLOC_CTX *mem_ctx, struct ldb_dn *dn)
{
return talloc_strdup(mem_ctx, ldb_dn_get_linearized(dn));
}
|
@@ -250,7 +250,7 @@ static int ldb_dn_escape_internal(char *dst, const char *src, int len)
char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
{
char *dst;
-
+ size_t len;
if (!value.length)
return NULL;
@@ -261,10 +261,14 @@ char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
return NULL;
}
- ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
-
- dst = talloc_realloc(mem_ctx, dst, char, strlen(dst) + 1);
+ len = ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
+ dst = talloc_realloc(mem_ctx, dst, char, len + 1);
+ if ( ! dst) {
+ talloc_free(dst);
+ return NULL;
+ }
+ dst[len] = '\0';
return dst;
}
|
CWE-200
| null | null |
1,853
|
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;
}
|
+Info
| 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;
}
|
@@ -250,7 +250,7 @@ static int ldb_dn_escape_internal(char *dst, const char *src, int len)
char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
{
char *dst;
-
+ size_t len;
if (!value.length)
return NULL;
@@ -261,10 +261,14 @@ char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
return NULL;
}
- ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
-
- dst = talloc_realloc(mem_ctx, dst, char, strlen(dst) + 1);
+ len = ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
+ dst = talloc_realloc(mem_ctx, dst, char, len + 1);
+ if ( ! dst) {
+ talloc_free(dst);
+ return NULL;
+ }
+ dst[len] = '\0';
return dst;
}
|
CWE-200
| null | null |
1,854
|
char *ldb_dn_canonical_ex_string(TALLOC_CTX *mem_ctx, struct ldb_dn *dn) {
return ldb_dn_canonical(mem_ctx, dn, 1);
}
|
+Info
| 0
|
char *ldb_dn_canonical_ex_string(TALLOC_CTX *mem_ctx, struct ldb_dn *dn) {
return ldb_dn_canonical(mem_ctx, dn, 1);
}
|
@@ -250,7 +250,7 @@ static int ldb_dn_escape_internal(char *dst, const char *src, int len)
char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
{
char *dst;
-
+ size_t len;
if (!value.length)
return NULL;
@@ -261,10 +261,14 @@ char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
return NULL;
}
- ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
-
- dst = talloc_realloc(mem_ctx, dst, char, strlen(dst) + 1);
+ len = ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
+ dst = talloc_realloc(mem_ctx, dst, char, len + 1);
+ if ( ! dst) {
+ talloc_free(dst);
+ return NULL;
+ }
+ dst[len] = '\0';
return dst;
}
|
CWE-200
| null | null |
1,855
|
char *ldb_dn_canonical_string(TALLOC_CTX *mem_ctx, struct ldb_dn *dn) {
return ldb_dn_canonical(mem_ctx, dn, 0);
}
|
+Info
| 0
|
char *ldb_dn_canonical_string(TALLOC_CTX *mem_ctx, struct ldb_dn *dn) {
return ldb_dn_canonical(mem_ctx, dn, 0);
}
|
@@ -250,7 +250,7 @@ static int ldb_dn_escape_internal(char *dst, const char *src, int len)
char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
{
char *dst;
-
+ size_t len;
if (!value.length)
return NULL;
@@ -261,10 +261,14 @@ char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
return NULL;
}
- ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
-
- dst = talloc_realloc(mem_ctx, dst, char, strlen(dst) + 1);
+ len = ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
+ dst = talloc_realloc(mem_ctx, dst, char, len + 1);
+ if ( ! dst) {
+ talloc_free(dst);
+ return NULL;
+ }
+ dst[len] = '\0';
return dst;
}
|
CWE-200
| null | null |
1,856
|
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;
}
|
+Info
| 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;
}
|
@@ -250,7 +250,7 @@ static int ldb_dn_escape_internal(char *dst, const char *src, int len)
char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
{
char *dst;
-
+ size_t len;
if (!value.length)
return NULL;
@@ -261,10 +261,14 @@ char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
return NULL;
}
- ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
-
- dst = talloc_realloc(mem_ctx, dst, char, strlen(dst) + 1);
+ len = ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
+ dst = talloc_realloc(mem_ctx, dst, char, len + 1);
+ if ( ! dst) {
+ talloc_free(dst);
+ return NULL;
+ }
+ dst[len] = '\0';
return dst;
}
|
CWE-200
| null | null |
1,857
|
bool ldb_dn_check_special(struct ldb_dn *dn, const char *check)
{
if ( ! dn || dn->invalid) return false;
return ! strcmp(dn->linearized, check);
}
|
+Info
| 0
|
bool ldb_dn_check_special(struct ldb_dn *dn, const char *check)
{
if ( ! dn || dn->invalid) return false;
return ! strcmp(dn->linearized, check);
}
|
@@ -250,7 +250,7 @@ static int ldb_dn_escape_internal(char *dst, const char *src, int len)
char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
{
char *dst;
-
+ size_t len;
if (!value.length)
return NULL;
@@ -261,10 +261,14 @@ char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
return NULL;
}
- ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
-
- dst = talloc_realloc(mem_ctx, dst, char, strlen(dst) + 1);
+ len = ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
+ dst = talloc_realloc(mem_ctx, dst, char, len + 1);
+ if ( ! dst) {
+ talloc_free(dst);
+ return NULL;
+ }
+ dst[len] = '\0';
return dst;
}
|
CWE-200
| null | null |
1,858
|
int ldb_dn_compare(struct ldb_dn *dn0, struct ldb_dn *dn1)
{
unsigned int i;
int ret;
if (( ! dn0) || dn0->invalid || ! dn1 || dn1->invalid) {
return -1;
}
if (( ! dn0->valid_case) || ( ! dn1->valid_case)) {
if (dn0->linearized && dn1->linearized) {
/* try with a normal compare first, if we are lucky
* we will avoid exploding and casfolding */
if (strcmp(dn0->linearized, dn1->linearized) == 0) {
return 0;
}
}
if ( ! ldb_dn_casefold_internal(dn0)) {
return 1;
}
if ( ! ldb_dn_casefold_internal(dn1)) {
return -1;
}
}
if (dn0->comp_num != dn1->comp_num) {
return (dn1->comp_num - dn0->comp_num);
}
if (dn0->comp_num == 0) {
if (dn0->special && dn1->special) {
return strcmp(dn0->linearized, dn1->linearized);
} else if (dn0->special) {
return 1;
} else if (dn1->special) {
return -1;
} else {
return 0;
}
}
for (i = 0; i < dn0->comp_num; i++) {
char *dn0_name = dn0->components[i].cf_name;
char *dn1_name = dn1->components[i].cf_name;
char *dn0_vdata = (char *)dn0->components[i].cf_value.data;
char *dn1_vdata = (char *)dn1->components[i].cf_value.data;
size_t dn0_vlen = dn0->components[i].cf_value.length;
size_t dn1_vlen = dn1->components[i].cf_value.length;
/* compare attr names */
ret = strcmp(dn0_name, dn1_name);
if (ret != 0) {
return ret;
}
/* compare attr.cf_value. */
if (dn0_vlen != dn1_vlen) {
return dn0_vlen - dn1_vlen;
}
ret = strncmp(dn0_vdata, dn1_vdata, dn0_vlen);
if (ret != 0) {
return ret;
}
}
return 0;
}
|
+Info
| 0
|
int ldb_dn_compare(struct ldb_dn *dn0, struct ldb_dn *dn1)
{
unsigned int i;
int ret;
if (( ! dn0) || dn0->invalid || ! dn1 || dn1->invalid) {
return -1;
}
if (( ! dn0->valid_case) || ( ! dn1->valid_case)) {
if (dn0->linearized && dn1->linearized) {
/* try with a normal compare first, if we are lucky
* we will avoid exploding and casfolding */
if (strcmp(dn0->linearized, dn1->linearized) == 0) {
return 0;
}
}
if ( ! ldb_dn_casefold_internal(dn0)) {
return 1;
}
if ( ! ldb_dn_casefold_internal(dn1)) {
return -1;
}
}
if (dn0->comp_num != dn1->comp_num) {
return (dn1->comp_num - dn0->comp_num);
}
if (dn0->comp_num == 0) {
if (dn0->special && dn1->special) {
return strcmp(dn0->linearized, dn1->linearized);
} else if (dn0->special) {
return 1;
} else if (dn1->special) {
return -1;
} else {
return 0;
}
}
for (i = 0; i < dn0->comp_num; i++) {
char *dn0_name = dn0->components[i].cf_name;
char *dn1_name = dn1->components[i].cf_name;
char *dn0_vdata = (char *)dn0->components[i].cf_value.data;
char *dn1_vdata = (char *)dn1->components[i].cf_value.data;
size_t dn0_vlen = dn0->components[i].cf_value.length;
size_t dn1_vlen = dn1->components[i].cf_value.length;
/* compare attr names */
ret = strcmp(dn0_name, dn1_name);
if (ret != 0) {
return ret;
}
/* compare attr.cf_value. */
if (dn0_vlen != dn1_vlen) {
return dn0_vlen - dn1_vlen;
}
ret = strncmp(dn0_vdata, dn1_vdata, dn0_vlen);
if (ret != 0) {
return ret;
}
}
return 0;
}
|
@@ -250,7 +250,7 @@ static int ldb_dn_escape_internal(char *dst, const char *src, int len)
char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
{
char *dst;
-
+ size_t len;
if (!value.length)
return NULL;
@@ -261,10 +261,14 @@ char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
return NULL;
}
- ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
-
- dst = talloc_realloc(mem_ctx, dst, char, strlen(dst) + 1);
+ len = ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
+ dst = talloc_realloc(mem_ctx, dst, char, len + 1);
+ if ( ! dst) {
+ talloc_free(dst);
+ return NULL;
+ }
+ dst[len] = '\0';
return dst;
}
|
CWE-200
| null | null |
1,859
|
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;
}
|
+Info
| 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;
}
|
@@ -250,7 +250,7 @@ static int ldb_dn_escape_internal(char *dst, const char *src, int len)
char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
{
char *dst;
-
+ size_t len;
if (!value.length)
return NULL;
@@ -261,10 +261,14 @@ char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
return NULL;
}
- ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
-
- dst = talloc_realloc(mem_ctx, dst, char, strlen(dst) + 1);
+ len = ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
+ dst = talloc_realloc(mem_ctx, dst, char, len + 1);
+ if ( ! dst) {
+ talloc_free(dst);
+ return NULL;
+ }
+ dst[len] = '\0';
return dst;
}
|
CWE-200
| null | null |
1,860
|
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;
}
|
+Info
| 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;
}
|
@@ -250,7 +250,7 @@ static int ldb_dn_escape_internal(char *dst, const char *src, int len)
char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
{
char *dst;
-
+ size_t len;
if (!value.length)
return NULL;
@@ -261,10 +261,14 @@ char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
return NULL;
}
- ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
-
- dst = talloc_realloc(mem_ctx, dst, char, strlen(dst) + 1);
+ len = ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
+ dst = talloc_realloc(mem_ctx, dst, char, len + 1);
+ if ( ! dst) {
+ talloc_free(dst);
+ return NULL;
+ }
+ dst[len] = '\0';
return dst;
}
|
CWE-200
| null | null |
1,861
|
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;
}
|
+Info
| 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;
}
|
@@ -250,7 +250,7 @@ static int ldb_dn_escape_internal(char *dst, const char *src, int len)
char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
{
char *dst;
-
+ size_t len;
if (!value.length)
return NULL;
@@ -261,10 +261,14 @@ char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
return NULL;
}
- ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
-
- dst = talloc_realloc(mem_ctx, dst, char, strlen(dst) + 1);
+ len = ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
+ dst = talloc_realloc(mem_ctx, dst, char, len + 1);
+ if ( ! dst) {
+ talloc_free(dst);
+ return NULL;
+ }
+ dst[len] = '\0';
return dst;
}
|
CWE-200
| null | null |
1,862
|
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;
}
|
+Info
| 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;
}
|
@@ -250,7 +250,7 @@ static int ldb_dn_escape_internal(char *dst, const char *src, int len)
char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
{
char *dst;
-
+ size_t len;
if (!value.length)
return NULL;
@@ -261,10 +261,14 @@ char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
return NULL;
}
- ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
-
- dst = talloc_realloc(mem_ctx, dst, char, strlen(dst) + 1);
+ len = ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
+ dst = talloc_realloc(mem_ctx, dst, char, len + 1);
+ if ( ! dst) {
+ talloc_free(dst);
+ return NULL;
+ }
+ dst[len] = '\0';
return dst;
}
|
CWE-200
| null | null |
1,863
|
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);
}
|
+Info
| 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);
}
|
@@ -250,7 +250,7 @@ static int ldb_dn_escape_internal(char *dst, const char *src, int len)
char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
{
char *dst;
-
+ size_t len;
if (!value.length)
return NULL;
@@ -261,10 +261,14 @@ char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
return NULL;
}
- ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
-
- dst = talloc_realloc(mem_ctx, dst, char, strlen(dst) + 1);
+ len = ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
+ dst = talloc_realloc(mem_ctx, dst, char, len + 1);
+ if ( ! dst) {
+ talloc_free(dst);
+ return NULL;
+ }
+ dst[len] = '\0';
return dst;
}
|
CWE-200
| null | null |
1,864
|
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);
}
|
+Info
| 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);
}
|
@@ -250,7 +250,7 @@ static int ldb_dn_escape_internal(char *dst, const char *src, int len)
char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
{
char *dst;
-
+ size_t len;
if (!value.length)
return NULL;
@@ -261,10 +261,14 @@ char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
return NULL;
}
- ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
-
- dst = talloc_realloc(mem_ctx, dst, char, strlen(dst) + 1);
+ len = ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
+ dst = talloc_realloc(mem_ctx, dst, char, len + 1);
+ if ( ! dst) {
+ talloc_free(dst);
+ return NULL;
+ }
+ dst[len] = '\0';
return dst;
}
|
CWE-200
| null | null |
1,865
|
const char *ldb_dn_get_casefold(struct ldb_dn *dn)
{
unsigned int i;
size_t len;
char *d, *n;
if (dn->casefold) return dn->casefold;
if (dn->special) {
dn->casefold = talloc_strdup(dn, dn->linearized);
if (!dn->casefold) return NULL;
dn->valid_case = true;
return dn->casefold;
}
if ( ! ldb_dn_casefold_internal(dn)) {
return NULL;
}
if (dn->comp_num == 0) {
dn->casefold = talloc_strdup(dn, "");
return dn->casefold;
}
/* calculate maximum possible length of DN */
for (len = 0, i = 0; i < dn->comp_num; i++) {
/* name len */
len += strlen(dn->components[i].cf_name);
/* max escaped data len */
len += (dn->components[i].cf_value.length * 3);
len += 2; /* '=' and ',' */
}
dn->casefold = talloc_array(dn, char, len);
if ( ! dn->casefold) return NULL;
d = dn->casefold;
for (i = 0; i < dn->comp_num; i++) {
/* copy the name */
n = dn->components[i].cf_name;
while (*n) *d++ = *n++;
*d++ = '=';
/* and the value */
d += ldb_dn_escape_internal( d,
(char *)dn->components[i].cf_value.data,
dn->components[i].cf_value.length);
*d++ = ',';
}
*(--d) = '\0';
/* don't waste more memory than necessary */
dn->casefold = talloc_realloc(dn, dn->casefold,
char, strlen(dn->casefold) + 1);
return dn->casefold;
}
|
+Info
| 0
|
const char *ldb_dn_get_casefold(struct ldb_dn *dn)
{
unsigned int i;
size_t len;
char *d, *n;
if (dn->casefold) return dn->casefold;
if (dn->special) {
dn->casefold = talloc_strdup(dn, dn->linearized);
if (!dn->casefold) return NULL;
dn->valid_case = true;
return dn->casefold;
}
if ( ! ldb_dn_casefold_internal(dn)) {
return NULL;
}
if (dn->comp_num == 0) {
dn->casefold = talloc_strdup(dn, "");
return dn->casefold;
}
/* calculate maximum possible length of DN */
for (len = 0, i = 0; i < dn->comp_num; i++) {
/* name len */
len += strlen(dn->components[i].cf_name);
/* max escaped data len */
len += (dn->components[i].cf_value.length * 3);
len += 2; /* '=' and ',' */
}
dn->casefold = talloc_array(dn, char, len);
if ( ! dn->casefold) return NULL;
d = dn->casefold;
for (i = 0; i < dn->comp_num; i++) {
/* copy the name */
n = dn->components[i].cf_name;
while (*n) *d++ = *n++;
*d++ = '=';
/* and the value */
d += ldb_dn_escape_internal( d,
(char *)dn->components[i].cf_value.data,
dn->components[i].cf_value.length);
*d++ = ',';
}
*(--d) = '\0';
/* don't waste more memory than necessary */
dn->casefold = talloc_realloc(dn, dn->casefold,
char, strlen(dn->casefold) + 1);
return dn->casefold;
}
|
@@ -250,7 +250,7 @@ static int ldb_dn_escape_internal(char *dst, const char *src, int len)
char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
{
char *dst;
-
+ size_t len;
if (!value.length)
return NULL;
@@ -261,10 +261,14 @@ char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
return NULL;
}
- ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
-
- dst = talloc_realloc(mem_ctx, dst, char, strlen(dst) + 1);
+ len = ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
+ dst = talloc_realloc(mem_ctx, dst, char, len + 1);
+ if ( ! dst) {
+ talloc_free(dst);
+ return NULL;
+ }
+ dst[len] = '\0';
return dst;
}
|
CWE-200
| null | null |
1,866
|
int ldb_dn_get_comp_num(struct ldb_dn *dn)
{
if ( ! ldb_dn_validate(dn)) {
return -1;
}
return dn->comp_num;
}
|
+Info
| 0
|
int ldb_dn_get_comp_num(struct ldb_dn *dn)
{
if ( ! ldb_dn_validate(dn)) {
return -1;
}
return dn->comp_num;
}
|
@@ -250,7 +250,7 @@ static int ldb_dn_escape_internal(char *dst, const char *src, int len)
char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
{
char *dst;
-
+ size_t len;
if (!value.length)
return NULL;
@@ -261,10 +261,14 @@ char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
return NULL;
}
- ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
-
- dst = talloc_realloc(mem_ctx, dst, char, strlen(dst) + 1);
+ len = ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
+ dst = talloc_realloc(mem_ctx, dst, char, len + 1);
+ if ( ! dst) {
+ talloc_free(dst);
+ return NULL;
+ }
+ dst[len] = '\0';
return dst;
}
|
CWE-200
| null | null |
1,867
|
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;
}
|
+Info
| 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;
}
|
@@ -250,7 +250,7 @@ static int ldb_dn_escape_internal(char *dst, const char *src, int len)
char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
{
char *dst;
-
+ size_t len;
if (!value.length)
return NULL;
@@ -261,10 +261,14 @@ char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
return NULL;
}
- ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
-
- dst = talloc_realloc(mem_ctx, dst, char, strlen(dst) + 1);
+ len = ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
+ dst = talloc_realloc(mem_ctx, dst, char, len + 1);
+ if ( ! dst) {
+ talloc_free(dst);
+ return NULL;
+ }
+ dst[len] = '\0';
return dst;
}
|
CWE-200
| null | null |
1,868
|
int ldb_dn_get_extended_comp_num(struct ldb_dn *dn)
{
if ( ! ldb_dn_validate(dn)) {
return -1;
}
return dn->ext_comp_num;
}
|
+Info
| 0
|
int ldb_dn_get_extended_comp_num(struct ldb_dn *dn)
{
if ( ! ldb_dn_validate(dn)) {
return -1;
}
return dn->ext_comp_num;
}
|
@@ -250,7 +250,7 @@ static int ldb_dn_escape_internal(char *dst, const char *src, int len)
char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
{
char *dst;
-
+ size_t len;
if (!value.length)
return NULL;
@@ -261,10 +261,14 @@ char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
return NULL;
}
- ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
-
- dst = talloc_realloc(mem_ctx, dst, char, strlen(dst) + 1);
+ len = ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
+ dst = talloc_realloc(mem_ctx, dst, char, len + 1);
+ if ( ! dst) {
+ talloc_free(dst);
+ return NULL;
+ }
+ dst[len] = '\0';
return dst;
}
|
CWE-200
| null | null |
1,869
|
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;
}
|
+Info
| 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;
}
|
@@ -250,7 +250,7 @@ static int ldb_dn_escape_internal(char *dst, const char *src, int len)
char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
{
char *dst;
-
+ size_t len;
if (!value.length)
return NULL;
@@ -261,10 +261,14 @@ char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
return NULL;
}
- ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
-
- dst = talloc_realloc(mem_ctx, dst, char, strlen(dst) + 1);
+ len = ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
+ dst = talloc_realloc(mem_ctx, dst, char, len + 1);
+ if ( ! dst) {
+ talloc_free(dst);
+ return NULL;
+ }
+ dst[len] = '\0';
return dst;
}
|
CWE-200
| null | null |
1,870
|
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;
}
|
+Info
| 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;
}
|
@@ -250,7 +250,7 @@ static int ldb_dn_escape_internal(char *dst, const char *src, int len)
char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
{
char *dst;
-
+ size_t len;
if (!value.length)
return NULL;
@@ -261,10 +261,14 @@ char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
return NULL;
}
- ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
-
- dst = talloc_realloc(mem_ctx, dst, char, strlen(dst) + 1);
+ len = ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
+ dst = talloc_realloc(mem_ctx, dst, char, len + 1);
+ if ( ! dst) {
+ talloc_free(dst);
+ return NULL;
+ }
+ dst[len] = '\0';
return dst;
}
|
CWE-200
| null | null |
1,871
|
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;
}
|
+Info
| 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;
}
|
@@ -250,7 +250,7 @@ static int ldb_dn_escape_internal(char *dst, const char *src, int len)
char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
{
char *dst;
-
+ size_t len;
if (!value.length)
return NULL;
@@ -261,10 +261,14 @@ char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
return NULL;
}
- ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
-
- dst = talloc_realloc(mem_ctx, dst, char, strlen(dst) + 1);
+ len = ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
+ dst = talloc_realloc(mem_ctx, dst, char, len + 1);
+ if ( ! dst) {
+ talloc_free(dst);
+ return NULL;
+ }
+ dst[len] = '\0';
return dst;
}
|
CWE-200
| null | null |
1,872
|
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;
}
|
+Info
| 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;
}
|
@@ -250,7 +250,7 @@ static int ldb_dn_escape_internal(char *dst, const char *src, int len)
char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
{
char *dst;
-
+ size_t len;
if (!value.length)
return NULL;
@@ -261,10 +261,14 @@ char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
return NULL;
}
- ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
-
- dst = talloc_realloc(mem_ctx, dst, char, strlen(dst) + 1);
+ len = ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
+ dst = talloc_realloc(mem_ctx, dst, char, len + 1);
+ if ( ! dst) {
+ talloc_free(dst);
+ return NULL;
+ }
+ dst[len] = '\0';
return dst;
}
|
CWE-200
| null | null |
1,873
|
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;
}
|
+Info
| 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;
}
|
@@ -250,7 +250,7 @@ static int ldb_dn_escape_internal(char *dst, const char *src, int len)
char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
{
char *dst;
-
+ size_t len;
if (!value.length)
return NULL;
@@ -261,10 +261,14 @@ char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
return NULL;
}
- ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
-
- dst = talloc_realloc(mem_ctx, dst, char, strlen(dst) + 1);
+ len = ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
+ dst = talloc_realloc(mem_ctx, dst, char, len + 1);
+ if ( ! dst) {
+ talloc_free(dst);
+ return NULL;
+ }
+ dst[len] = '\0';
return dst;
}
|
CWE-200
| null | null |
1,874
|
bool ldb_dn_is_special(struct ldb_dn *dn)
{
if ( ! dn || dn->invalid) return false;
return dn->special;
}
|
+Info
| 0
|
bool ldb_dn_is_special(struct ldb_dn *dn)
{
if ( ! dn || dn->invalid) return false;
return dn->special;
}
|
@@ -250,7 +250,7 @@ static int ldb_dn_escape_internal(char *dst, const char *src, int len)
char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
{
char *dst;
-
+ size_t len;
if (!value.length)
return NULL;
@@ -261,10 +261,14 @@ char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
return NULL;
}
- ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
-
- dst = talloc_realloc(mem_ctx, dst, char, strlen(dst) + 1);
+ len = ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
+ dst = talloc_realloc(mem_ctx, dst, char, len + 1);
+ if ( ! dst) {
+ talloc_free(dst);
+ return NULL;
+ }
+ dst[len] = '\0';
return dst;
}
|
CWE-200
| null | null |
1,875
|
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;
}
|
+Info
| 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;
}
|
@@ -250,7 +250,7 @@ static int ldb_dn_escape_internal(char *dst, const char *src, int len)
char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
{
char *dst;
-
+ size_t len;
if (!value.length)
return NULL;
@@ -261,10 +261,14 @@ char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
return NULL;
}
- ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
-
- dst = talloc_realloc(mem_ctx, dst, char, strlen(dst) + 1);
+ len = ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
+ dst = talloc_realloc(mem_ctx, dst, char, len + 1);
+ if ( ! dst) {
+ talloc_free(dst);
+ return NULL;
+ }
+ dst[len] = '\0';
return dst;
}
|
CWE-200
| null | null |
1,876
|
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;
}
|
+Info
| 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;
}
|
@@ -250,7 +250,7 @@ static int ldb_dn_escape_internal(char *dst, const char *src, int len)
char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
{
char *dst;
-
+ size_t len;
if (!value.length)
return NULL;
@@ -261,10 +261,14 @@ char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
return NULL;
}
- ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
-
- dst = talloc_realloc(mem_ctx, dst, char, strlen(dst) + 1);
+ len = ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
+ dst = talloc_realloc(mem_ctx, dst, char, len + 1);
+ if ( ! dst) {
+ talloc_free(dst);
+ return NULL;
+ }
+ dst[len] = '\0';
return dst;
}
|
CWE-200
| null | null |
1,877
|
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;
}
|
+Info
| 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;
}
|
@@ -250,7 +250,7 @@ static int ldb_dn_escape_internal(char *dst, const char *src, int len)
char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
{
char *dst;
-
+ size_t len;
if (!value.length)
return NULL;
@@ -261,10 +261,14 @@ char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
return NULL;
}
- ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
-
- dst = talloc_realloc(mem_ctx, dst, char, strlen(dst) + 1);
+ len = ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
+ dst = talloc_realloc(mem_ctx, dst, char, len + 1);
+ if ( ! dst) {
+ talloc_free(dst);
+ return NULL;
+ }
+ dst[len] = '\0';
return dst;
}
|
CWE-200
| null | null |
1,878
|
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;
}
|
+Info
| 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;
}
|
@@ -250,7 +250,7 @@ static int ldb_dn_escape_internal(char *dst, const char *src, int len)
char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
{
char *dst;
-
+ size_t len;
if (!value.length)
return NULL;
@@ -261,10 +261,14 @@ char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value)
return NULL;
}
- ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
-
- dst = talloc_realloc(mem_ctx, dst, char, strlen(dst) + 1);
+ len = ldb_dn_escape_internal(dst, (const char *)value.data, value.length);
+ dst = talloc_realloc(mem_ctx, dst, char, len + 1);
+ if ( ! dst) {
+ talloc_free(dst);
+ return NULL;
+ }
+ dst[len] = '\0';
return dst;
}
|
CWE-200
| null | null |
1,879
|
do_call_operator(op_proc_t op_proc, i_ctx_t *i_ctx_p)
{
int code;
code = op_proc(i_ctx_p);
if (gs_debug_c(gs_debug_flag_validate_clumps))
ivalidate_clean_spaces(i_ctx_p);
return code; /* A good place for a conditional breakpoint. */
}
|
Bypass +Info
| 0
|
do_call_operator(op_proc_t op_proc, i_ctx_t *i_ctx_p)
{
int code;
code = op_proc(i_ctx_p);
if (gs_debug_c(gs_debug_flag_validate_clumps))
ivalidate_clean_spaces(i_ctx_p);
return code; /* A good place for a conditional breakpoint. */
}
|
@@ -142,7 +142,6 @@ static int oparray_pop(i_ctx_t *);
static int oparray_cleanup(i_ctx_t *);
static int zerrorexec(i_ctx_t *);
static int zfinderrorobject(i_ctx_t *);
-static int errorexec_find(i_ctx_t *, ref *);
static int errorexec_pop(i_ctx_t *);
static int errorexec_cleanup(i_ctx_t *);
static int zsetstackprotect(i_ctx_t *);
@@ -761,7 +760,7 @@ copy_stack(i_ctx_t *i_ctx_p, const ref_stack_t * pstack, int skip, ref * arr)
{
uint size = ref_stack_count(pstack) - skip;
uint save_space = ialloc_space(idmemory);
- int code;
+ int code, i;
if (size > 65535)
size = 65535;
@@ -770,6 +769,15 @@ copy_stack(i_ctx_t *i_ctx_p, const ref_stack_t * pstack, int skip, ref * arr)
if (code >= 0)
code = ref_stack_store(pstack, arr, size, 0, 1, true, idmemory,
"copy_stack");
+ /* If we are copying the exec stack, try to replace any oparrays with
+ * with the operator than references them
+ */
+ if (pstack == &e_stack) {
+ for (i = 0; i < size; i++) {
+ if (errorexec_find(i_ctx_p, &arr->value.refs[i]) < 0)
+ make_null(&arr->value.refs[i]);
+ }
+ }
ialloc_set_space(idmemory, save_space);
return code;
}
@@ -1934,7 +1942,7 @@ zfinderrorobject(i_ctx_t *i_ctx_p)
* .errorexec with errobj != null, store it in *perror_object and return 1,
* otherwise return 0;
*/
-static int
+int
errorexec_find(i_ctx_t *i_ctx_p, ref *perror_object)
{
long i;
|
CWE-200
| null | null |
1,880
|
do_call_operator_verbose(op_proc_t op_proc, i_ctx_t *i_ctx_p)
{
int code;
#ifndef SHOW_STACK_DEPTHS
if_debug1m('!', imemory, "[!]operator %s\n", op_get_name_string(op_proc));
#else
if_debug3m('!', imemory, "[!][es=%d os=%d]operator %s\n",
esp-i_ctx_p->exec_stack.stack.bot,
osp-i_ctx_p->op_stack.stack.bot,
op_get_name_string(op_proc));
#endif
code = do_call_operator(op_proc, i_ctx_p);
#if defined(SHOW_STACK_DEPTHS)
if_debug2m('!', imemory, "[!][es=%d os=%d]\n",
esp-i_ctx_p->exec_stack.stack.bot,
osp-i_ctx_p->op_stack.stack.bot);
#endif
if (gs_debug_c(gs_debug_flag_validate_clumps))
ivalidate_clean_spaces(i_ctx_p);
return code; /* A good place for a conditional breakpoint. */
}
|
Bypass +Info
| 0
|
do_call_operator_verbose(op_proc_t op_proc, i_ctx_t *i_ctx_p)
{
int code;
#ifndef SHOW_STACK_DEPTHS
if_debug1m('!', imemory, "[!]operator %s\n", op_get_name_string(op_proc));
#else
if_debug3m('!', imemory, "[!][es=%d os=%d]operator %s\n",
esp-i_ctx_p->exec_stack.stack.bot,
osp-i_ctx_p->op_stack.stack.bot,
op_get_name_string(op_proc));
#endif
code = do_call_operator(op_proc, i_ctx_p);
#if defined(SHOW_STACK_DEPTHS)
if_debug2m('!', imemory, "[!][es=%d os=%d]\n",
esp-i_ctx_p->exec_stack.stack.bot,
osp-i_ctx_p->op_stack.stack.bot);
#endif
if (gs_debug_c(gs_debug_flag_validate_clumps))
ivalidate_clean_spaces(i_ctx_p);
return code; /* A good place for a conditional breakpoint. */
}
|
@@ -142,7 +142,6 @@ static int oparray_pop(i_ctx_t *);
static int oparray_cleanup(i_ctx_t *);
static int zerrorexec(i_ctx_t *);
static int zfinderrorobject(i_ctx_t *);
-static int errorexec_find(i_ctx_t *, ref *);
static int errorexec_pop(i_ctx_t *);
static int errorexec_cleanup(i_ctx_t *);
static int zsetstackprotect(i_ctx_t *);
@@ -761,7 +760,7 @@ copy_stack(i_ctx_t *i_ctx_p, const ref_stack_t * pstack, int skip, ref * arr)
{
uint size = ref_stack_count(pstack) - skip;
uint save_space = ialloc_space(idmemory);
- int code;
+ int code, i;
if (size > 65535)
size = 65535;
@@ -770,6 +769,15 @@ copy_stack(i_ctx_t *i_ctx_p, const ref_stack_t * pstack, int skip, ref * arr)
if (code >= 0)
code = ref_stack_store(pstack, arr, size, 0, 1, true, idmemory,
"copy_stack");
+ /* If we are copying the exec stack, try to replace any oparrays with
+ * with the operator than references them
+ */
+ if (pstack == &e_stack) {
+ for (i = 0; i < size; i++) {
+ if (errorexec_find(i_ctx_p, &arr->value.refs[i]) < 0)
+ make_null(&arr->value.refs[i]);
+ }
+ }
ialloc_set_space(idmemory, save_space);
return code;
}
@@ -1934,7 +1942,7 @@ zfinderrorobject(i_ctx_t *i_ctx_p)
* .errorexec with errobj != null, store it in *perror_object and return 1,
* otherwise return 0;
*/
-static int
+int
errorexec_find(i_ctx_t *i_ctx_p, ref *perror_object)
{
long i;
|
CWE-200
| null | null |
1,881
|
gs_interp_alloc_stacks(gs_ref_memory_t *mem, gs_context_state_t * pcst)
{
int code;
gs_ref_memory_t *smem =
(gs_ref_memory_t *)gs_memory_stable((gs_memory_t *)mem);
ref stk;
#define REFS_SIZE_OSTACK OS_REFS_SIZE(MAX_OSTACK)
#define REFS_SIZE_ESTACK ES_REFS_SIZE(MAX_ESTACK)
#define REFS_SIZE_DSTACK DS_REFS_SIZE(MAX_DSTACK)
code = gs_alloc_ref_array(smem, &stk, 0,
REFS_SIZE_OSTACK + REFS_SIZE_ESTACK +
REFS_SIZE_DSTACK, "gs_interp_alloc_stacks");
if (code < 0)
return code;
{
ref_stack_t *pos = &pcst->op_stack.stack;
r_set_size(&stk, REFS_SIZE_OSTACK);
code = ref_stack_init(pos, &stk, OS_GUARD_UNDER, OS_GUARD_OVER, NULL,
smem, NULL);
if (code < 0)
return code;
ref_stack_set_error_codes(pos, gs_error_stackunderflow, gs_error_stackoverflow);
ref_stack_set_max_count(pos, MAX_OSTACK);
stk.value.refs += REFS_SIZE_OSTACK;
}
{
ref_stack_t *pes = &pcst->exec_stack.stack;
ref euop;
r_set_size(&stk, REFS_SIZE_ESTACK);
make_oper(&euop, 0, estack_underflow);
code = ref_stack_init(pes, &stk, ES_GUARD_UNDER, ES_GUARD_OVER, &euop,
smem, NULL);
if (code < 0)
return code;
ref_stack_set_error_codes(pes, gs_error_ExecStackUnderflow,
gs_error_execstackoverflow);
/**************** E-STACK EXPANSION IS NYI. ****************/
ref_stack_allow_expansion(pes, false);
ref_stack_set_max_count(pes, MAX_ESTACK);
stk.value.refs += REFS_SIZE_ESTACK;
}
{
ref_stack_t *pds = &pcst->dict_stack.stack;
r_set_size(&stk, REFS_SIZE_DSTACK);
code = ref_stack_init(pds, &stk, 0, 0, NULL, smem, NULL);
if (code < 0)
return code;
ref_stack_set_error_codes(pds, gs_error_dictstackunderflow,
gs_error_dictstackoverflow);
ref_stack_set_max_count(pds, MAX_DSTACK);
}
#undef REFS_SIZE_OSTACK
#undef REFS_SIZE_ESTACK
#undef REFS_SIZE_DSTACK
return 0;
}
|
Bypass +Info
| 0
|
gs_interp_alloc_stacks(gs_ref_memory_t *mem, gs_context_state_t * pcst)
{
int code;
gs_ref_memory_t *smem =
(gs_ref_memory_t *)gs_memory_stable((gs_memory_t *)mem);
ref stk;
#define REFS_SIZE_OSTACK OS_REFS_SIZE(MAX_OSTACK)
#define REFS_SIZE_ESTACK ES_REFS_SIZE(MAX_ESTACK)
#define REFS_SIZE_DSTACK DS_REFS_SIZE(MAX_DSTACK)
code = gs_alloc_ref_array(smem, &stk, 0,
REFS_SIZE_OSTACK + REFS_SIZE_ESTACK +
REFS_SIZE_DSTACK, "gs_interp_alloc_stacks");
if (code < 0)
return code;
{
ref_stack_t *pos = &pcst->op_stack.stack;
r_set_size(&stk, REFS_SIZE_OSTACK);
code = ref_stack_init(pos, &stk, OS_GUARD_UNDER, OS_GUARD_OVER, NULL,
smem, NULL);
if (code < 0)
return code;
ref_stack_set_error_codes(pos, gs_error_stackunderflow, gs_error_stackoverflow);
ref_stack_set_max_count(pos, MAX_OSTACK);
stk.value.refs += REFS_SIZE_OSTACK;
}
{
ref_stack_t *pes = &pcst->exec_stack.stack;
ref euop;
r_set_size(&stk, REFS_SIZE_ESTACK);
make_oper(&euop, 0, estack_underflow);
code = ref_stack_init(pes, &stk, ES_GUARD_UNDER, ES_GUARD_OVER, &euop,
smem, NULL);
if (code < 0)
return code;
ref_stack_set_error_codes(pes, gs_error_ExecStackUnderflow,
gs_error_execstackoverflow);
/**************** E-STACK EXPANSION IS NYI. ****************/
ref_stack_allow_expansion(pes, false);
ref_stack_set_max_count(pes, MAX_ESTACK);
stk.value.refs += REFS_SIZE_ESTACK;
}
{
ref_stack_t *pds = &pcst->dict_stack.stack;
r_set_size(&stk, REFS_SIZE_DSTACK);
code = ref_stack_init(pds, &stk, 0, 0, NULL, smem, NULL);
if (code < 0)
return code;
ref_stack_set_error_codes(pds, gs_error_dictstackunderflow,
gs_error_dictstackoverflow);
ref_stack_set_max_count(pds, MAX_DSTACK);
}
#undef REFS_SIZE_OSTACK
#undef REFS_SIZE_ESTACK
#undef REFS_SIZE_DSTACK
return 0;
}
|
@@ -142,7 +142,6 @@ static int oparray_pop(i_ctx_t *);
static int oparray_cleanup(i_ctx_t *);
static int zerrorexec(i_ctx_t *);
static int zfinderrorobject(i_ctx_t *);
-static int errorexec_find(i_ctx_t *, ref *);
static int errorexec_pop(i_ctx_t *);
static int errorexec_cleanup(i_ctx_t *);
static int zsetstackprotect(i_ctx_t *);
@@ -761,7 +760,7 @@ copy_stack(i_ctx_t *i_ctx_p, const ref_stack_t * pstack, int skip, ref * arr)
{
uint size = ref_stack_count(pstack) - skip;
uint save_space = ialloc_space(idmemory);
- int code;
+ int code, i;
if (size > 65535)
size = 65535;
@@ -770,6 +769,15 @@ copy_stack(i_ctx_t *i_ctx_p, const ref_stack_t * pstack, int skip, ref * arr)
if (code >= 0)
code = ref_stack_store(pstack, arr, size, 0, 1, true, idmemory,
"copy_stack");
+ /* If we are copying the exec stack, try to replace any oparrays with
+ * with the operator than references them
+ */
+ if (pstack == &e_stack) {
+ for (i = 0; i < size; i++) {
+ if (errorexec_find(i_ctx_p, &arr->value.refs[i]) < 0)
+ make_null(&arr->value.refs[i]);
+ }
+ }
ialloc_set_space(idmemory, save_space);
return code;
}
@@ -1934,7 +1942,7 @@ zfinderrorobject(i_ctx_t *i_ctx_p)
* .errorexec with errobj != null, store it in *perror_object and return 1,
* otherwise return 0;
*/
-static int
+int
errorexec_find(i_ctx_t *i_ctx_p, ref *perror_object)
{
long i;
|
CWE-200
| null | null |
1,882
|
gs_interp_make_oper(ref * opref, op_proc_t proc, int idx)
{
int i;
for (i = num_special_ops; i > 0 && proc != interp1_op_defs[i].proc; --i)
DO_NOTHING;
if (i > 0)
make_tasv(opref, tx_op + (i - 1), a_executable, i, opproc, proc);
else
make_tasv(opref, t_operator, a_executable, idx, opproc, proc);
}
|
Bypass +Info
| 0
|
gs_interp_make_oper(ref * opref, op_proc_t proc, int idx)
{
int i;
for (i = num_special_ops; i > 0 && proc != interp1_op_defs[i].proc; --i)
DO_NOTHING;
if (i > 0)
make_tasv(opref, tx_op + (i - 1), a_executable, i, opproc, proc);
else
make_tasv(opref, t_operator, a_executable, idx, opproc, proc);
}
|
@@ -142,7 +142,6 @@ static int oparray_pop(i_ctx_t *);
static int oparray_cleanup(i_ctx_t *);
static int zerrorexec(i_ctx_t *);
static int zfinderrorobject(i_ctx_t *);
-static int errorexec_find(i_ctx_t *, ref *);
static int errorexec_pop(i_ctx_t *);
static int errorexec_cleanup(i_ctx_t *);
static int zsetstackprotect(i_ctx_t *);
@@ -761,7 +760,7 @@ copy_stack(i_ctx_t *i_ctx_p, const ref_stack_t * pstack, int skip, ref * arr)
{
uint size = ref_stack_count(pstack) - skip;
uint save_space = ialloc_space(idmemory);
- int code;
+ int code, i;
if (size > 65535)
size = 65535;
@@ -770,6 +769,15 @@ copy_stack(i_ctx_t *i_ctx_p, const ref_stack_t * pstack, int skip, ref * arr)
if (code >= 0)
code = ref_stack_store(pstack, arr, size, 0, 1, true, idmemory,
"copy_stack");
+ /* If we are copying the exec stack, try to replace any oparrays with
+ * with the operator than references them
+ */
+ if (pstack == &e_stack) {
+ for (i = 0; i < size; i++) {
+ if (errorexec_find(i_ctx_p, &arr->value.refs[i]) < 0)
+ make_null(&arr->value.refs[i]);
+ }
+ }
ialloc_set_space(idmemory, save_space);
return code;
}
@@ -1934,7 +1942,7 @@ zfinderrorobject(i_ctx_t *i_ctx_p)
* .errorexec with errobj != null, store it in *perror_object and return 1,
* otherwise return 0;
*/
-static int
+int
errorexec_find(i_ctx_t *i_ctx_p, ref *perror_object)
{
long i;
|
CWE-200
| null | null |
1,883
|
gs_interp_reset(i_ctx_t *i_ctx_p)
{ /* Reset the stacks. */
ref_stack_clear(&o_stack);
ref_stack_clear(&e_stack);
esp++;
make_oper(esp, 0, interp_exit);
ref_stack_pop_to(&d_stack, min_dstack_size);
dict_set_top();
}
|
Bypass +Info
| 0
|
gs_interp_reset(i_ctx_t *i_ctx_p)
{ /* Reset the stacks. */
ref_stack_clear(&o_stack);
ref_stack_clear(&e_stack);
esp++;
make_oper(esp, 0, interp_exit);
ref_stack_pop_to(&d_stack, min_dstack_size);
dict_set_top();
}
|
@@ -142,7 +142,6 @@ static int oparray_pop(i_ctx_t *);
static int oparray_cleanup(i_ctx_t *);
static int zerrorexec(i_ctx_t *);
static int zfinderrorobject(i_ctx_t *);
-static int errorexec_find(i_ctx_t *, ref *);
static int errorexec_pop(i_ctx_t *);
static int errorexec_cleanup(i_ctx_t *);
static int zsetstackprotect(i_ctx_t *);
@@ -761,7 +760,7 @@ copy_stack(i_ctx_t *i_ctx_p, const ref_stack_t * pstack, int skip, ref * arr)
{
uint size = ref_stack_count(pstack) - skip;
uint save_space = ialloc_space(idmemory);
- int code;
+ int code, i;
if (size > 65535)
size = 65535;
@@ -770,6 +769,15 @@ copy_stack(i_ctx_t *i_ctx_p, const ref_stack_t * pstack, int skip, ref * arr)
if (code >= 0)
code = ref_stack_store(pstack, arr, size, 0, 1, true, idmemory,
"copy_stack");
+ /* If we are copying the exec stack, try to replace any oparrays with
+ * with the operator than references them
+ */
+ if (pstack == &e_stack) {
+ for (i = 0; i < size; i++) {
+ if (errorexec_find(i_ctx_p, &arr->value.refs[i]) < 0)
+ make_null(&arr->value.refs[i]);
+ }
+ }
ialloc_set_space(idmemory, save_space);
return code;
}
@@ -1934,7 +1942,7 @@ zfinderrorobject(i_ctx_t *i_ctx_p)
* .errorexec with errobj != null, store it in *perror_object and return 1,
* otherwise return 0;
*/
-static int
+int
errorexec_find(i_ctx_t *i_ctx_p, ref *perror_object)
{
long i;
|
CWE-200
| null | null |
1,884
|
interp_exit(i_ctx_t *i_ctx_p)
{
return gs_error_InterpreterExit;
}
|
Bypass +Info
| 0
|
interp_exit(i_ctx_t *i_ctx_p)
{
return gs_error_InterpreterExit;
}
|
@@ -142,7 +142,6 @@ static int oparray_pop(i_ctx_t *);
static int oparray_cleanup(i_ctx_t *);
static int zerrorexec(i_ctx_t *);
static int zfinderrorobject(i_ctx_t *);
-static int errorexec_find(i_ctx_t *, ref *);
static int errorexec_pop(i_ctx_t *);
static int errorexec_cleanup(i_ctx_t *);
static int zsetstackprotect(i_ctx_t *);
@@ -761,7 +760,7 @@ copy_stack(i_ctx_t *i_ctx_p, const ref_stack_t * pstack, int skip, ref * arr)
{
uint size = ref_stack_count(pstack) - skip;
uint save_space = ialloc_space(idmemory);
- int code;
+ int code, i;
if (size > 65535)
size = 65535;
@@ -770,6 +769,15 @@ copy_stack(i_ctx_t *i_ctx_p, const ref_stack_t * pstack, int skip, ref * arr)
if (code >= 0)
code = ref_stack_store(pstack, arr, size, 0, 1, true, idmemory,
"copy_stack");
+ /* If we are copying the exec stack, try to replace any oparrays with
+ * with the operator than references them
+ */
+ if (pstack == &e_stack) {
+ for (i = 0; i < size; i++) {
+ if (errorexec_find(i_ctx_p, &arr->value.refs[i]) < 0)
+ make_null(&arr->value.refs[i]);
+ }
+ }
ialloc_set_space(idmemory, save_space);
return code;
}
@@ -1934,7 +1942,7 @@ zfinderrorobject(i_ctx_t *i_ctx_p)
* .errorexec with errobj != null, store it in *perror_object and return 1,
* otherwise return 0;
*/
-static int
+int
errorexec_find(i_ctx_t *i_ctx_p, ref *perror_object)
{
long i;
|
CWE-200
| null | null |
1,885
|
interp_reclaim(i_ctx_t **pi_ctx_p, int space)
{
i_ctx_t *i_ctx_p = *pi_ctx_p;
gs_gc_root_t ctx_root;
int code;
#ifdef DEBUG
if (gs_debug_c(gs_debug_flag_gc_disable))
return 0;
#endif
gs_register_struct_root(imemory_system, &ctx_root,
(void **)pi_ctx_p, "interp_reclaim(pi_ctx_p)");
code = (*idmemory->reclaim)(idmemory, space);
i_ctx_p = *pi_ctx_p; /* may have moved */
gs_unregister_root(imemory_system, &ctx_root, "interp_reclaim(pi_ctx_p)");
return code;
}
|
Bypass +Info
| 0
|
interp_reclaim(i_ctx_t **pi_ctx_p, int space)
{
i_ctx_t *i_ctx_p = *pi_ctx_p;
gs_gc_root_t ctx_root;
int code;
#ifdef DEBUG
if (gs_debug_c(gs_debug_flag_gc_disable))
return 0;
#endif
gs_register_struct_root(imemory_system, &ctx_root,
(void **)pi_ctx_p, "interp_reclaim(pi_ctx_p)");
code = (*idmemory->reclaim)(idmemory, space);
i_ctx_p = *pi_ctx_p; /* may have moved */
gs_unregister_root(imemory_system, &ctx_root, "interp_reclaim(pi_ctx_p)");
return code;
}
|
@@ -142,7 +142,6 @@ static int oparray_pop(i_ctx_t *);
static int oparray_cleanup(i_ctx_t *);
static int zerrorexec(i_ctx_t *);
static int zfinderrorobject(i_ctx_t *);
-static int errorexec_find(i_ctx_t *, ref *);
static int errorexec_pop(i_ctx_t *);
static int errorexec_cleanup(i_ctx_t *);
static int zsetstackprotect(i_ctx_t *);
@@ -761,7 +760,7 @@ copy_stack(i_ctx_t *i_ctx_p, const ref_stack_t * pstack, int skip, ref * arr)
{
uint size = ref_stack_count(pstack) - skip;
uint save_space = ialloc_space(idmemory);
- int code;
+ int code, i;
if (size > 65535)
size = 65535;
@@ -770,6 +769,15 @@ copy_stack(i_ctx_t *i_ctx_p, const ref_stack_t * pstack, int skip, ref * arr)
if (code >= 0)
code = ref_stack_store(pstack, arr, size, 0, 1, true, idmemory,
"copy_stack");
+ /* If we are copying the exec stack, try to replace any oparrays with
+ * with the operator than references them
+ */
+ if (pstack == &e_stack) {
+ for (i = 0; i < size; i++) {
+ if (errorexec_find(i_ctx_p, &arr->value.refs[i]) < 0)
+ make_null(&arr->value.refs[i]);
+ }
+ }
ialloc_set_space(idmemory, save_space);
return code;
}
@@ -1934,7 +1942,7 @@ zfinderrorobject(i_ctx_t *i_ctx_p)
* .errorexec with errobj != null, store it in *perror_object and return 1,
* otherwise return 0;
*/
-static int
+int
errorexec_find(i_ctx_t *i_ctx_p, ref *perror_object)
{
long i;
|
CWE-200
| null | null |
1,886
|
set_gc_signal(i_ctx_t *i_ctx_p, int value)
{
gs_memory_gc_status_t stat;
int i;
for (i = 0; i < countof(idmemory->spaces_indexed); i++) {
gs_ref_memory_t *mem = idmemory->spaces_indexed[i];
gs_ref_memory_t *mem_stable;
if (mem == 0)
continue;
for (;; mem = mem_stable) {
mem_stable = (gs_ref_memory_t *)
gs_memory_stable((gs_memory_t *)mem);
gs_memory_gc_status(mem, &stat);
stat.signal_value = value;
gs_memory_set_gc_status(mem, &stat);
if (mem_stable == mem)
break;
}
}
}
|
Bypass +Info
| 0
|
set_gc_signal(i_ctx_t *i_ctx_p, int value)
{
gs_memory_gc_status_t stat;
int i;
for (i = 0; i < countof(idmemory->spaces_indexed); i++) {
gs_ref_memory_t *mem = idmemory->spaces_indexed[i];
gs_ref_memory_t *mem_stable;
if (mem == 0)
continue;
for (;; mem = mem_stable) {
mem_stable = (gs_ref_memory_t *)
gs_memory_stable((gs_memory_t *)mem);
gs_memory_gc_status(mem, &stat);
stat.signal_value = value;
gs_memory_set_gc_status(mem, &stat);
if (mem_stable == mem)
break;
}
}
}
|
@@ -142,7 +142,6 @@ static int oparray_pop(i_ctx_t *);
static int oparray_cleanup(i_ctx_t *);
static int zerrorexec(i_ctx_t *);
static int zfinderrorobject(i_ctx_t *);
-static int errorexec_find(i_ctx_t *, ref *);
static int errorexec_pop(i_ctx_t *);
static int errorexec_cleanup(i_ctx_t *);
static int zsetstackprotect(i_ctx_t *);
@@ -761,7 +760,7 @@ copy_stack(i_ctx_t *i_ctx_p, const ref_stack_t * pstack, int skip, ref * arr)
{
uint size = ref_stack_count(pstack) - skip;
uint save_space = ialloc_space(idmemory);
- int code;
+ int code, i;
if (size > 65535)
size = 65535;
@@ -770,6 +769,15 @@ copy_stack(i_ctx_t *i_ctx_p, const ref_stack_t * pstack, int skip, ref * arr)
if (code >= 0)
code = ref_stack_store(pstack, arr, size, 0, 1, true, idmemory,
"copy_stack");
+ /* If we are copying the exec stack, try to replace any oparrays with
+ * with the operator than references them
+ */
+ if (pstack == &e_stack) {
+ for (i = 0; i < size; i++) {
+ if (errorexec_find(i_ctx_p, &arr->value.refs[i]) < 0)
+ make_null(&arr->value.refs[i]);
+ }
+ }
ialloc_set_space(idmemory, save_space);
return code;
}
@@ -1934,7 +1942,7 @@ zfinderrorobject(i_ctx_t *i_ctx_p)
* .errorexec with errobj != null, store it in *perror_object and return 1,
* otherwise return 0;
*/
-static int
+int
errorexec_find(i_ctx_t *i_ctx_p, ref *perror_object)
{
long i;
|
CWE-200
| null | null |
1,887
|
check_for_exec(const_os_ptr op)
{
if (!r_has_attr(op, a_execute) && /* only true if noaccess */
ref_type_uses_access(r_type(op)) &&
(r_has_attr(op, a_executable) || !r_has_type(op, t_dictionary))
) {
return_error(gs_error_invalidaccess);
}
return 0;
}
|
Bypass +Info
| 0
|
check_for_exec(const_os_ptr op)
{
if (!r_has_attr(op, a_execute) && /* only true if noaccess */
ref_type_uses_access(r_type(op)) &&
(r_has_attr(op, a_executable) || !r_has_type(op, t_dictionary))
) {
return_error(gs_error_invalidaccess);
}
return 0;
}
|
@@ -24,6 +24,7 @@
#include "ipacked.h"
#include "iutil.h"
#include "store.h"
+#include "interp.h"
/* Forward references */
static int check_for_exec(const_os_ptr);
@@ -787,7 +788,7 @@ zexecstack2(i_ctx_t *i_ctx_p)
/* Continuation operator to do the actual transfer. */
/* r_size(op1) was set just above. */
static int
-do_execstack(i_ctx_t *i_ctx_p, bool include_marks, os_ptr op1)
+do_execstack(i_ctx_t *i_ctx_p, bool include_marks, bool include_oparrays, os_ptr op1)
{
os_ptr op = osp;
ref *arefs = op1->value.refs;
@@ -829,6 +830,12 @@ do_execstack(i_ctx_t *i_ctx_p, bool include_marks, os_ptr op1)
strlen(tname), (const byte *)tname);
break;
}
+ case t_array:
+ case t_shortarray:
+ case t_mixedarray:
+ if (!include_oparrays && errorexec_find(i_ctx_p, rq) < 0)
+ make_null(rq);
+ break;
default:
;
}
@@ -841,14 +848,14 @@ execstack_continue(i_ctx_t *i_ctx_p)
{
os_ptr op = osp;
- return do_execstack(i_ctx_p, false, op);
+ return do_execstack(i_ctx_p, false, false, op);
}
static int
execstack2_continue(i_ctx_t *i_ctx_p)
{
os_ptr op = osp;
- return do_execstack(i_ctx_p, op->value.boolval, op - 1);
+ return do_execstack(i_ctx_p, op->value.boolval, true, op - 1);
}
/* - .needinput - */
|
CWE-200
| null | null |
1,888
|
count_exec_stack(i_ctx_t *i_ctx_p, bool include_marks)
{
uint count = ref_stack_count(&e_stack);
if (!include_marks) {
uint i;
for (i = count; i--;)
if (r_has_type_attrs(ref_stack_index(&e_stack, (long)i),
t_null, a_executable))
--count;
}
return count;
}
|
Bypass +Info
| 0
|
count_exec_stack(i_ctx_t *i_ctx_p, bool include_marks)
{
uint count = ref_stack_count(&e_stack);
if (!include_marks) {
uint i;
for (i = count; i--;)
if (r_has_type_attrs(ref_stack_index(&e_stack, (long)i),
t_null, a_executable))
--count;
}
return count;
}
|
@@ -24,6 +24,7 @@
#include "ipacked.h"
#include "iutil.h"
#include "store.h"
+#include "interp.h"
/* Forward references */
static int check_for_exec(const_os_ptr);
@@ -787,7 +788,7 @@ zexecstack2(i_ctx_t *i_ctx_p)
/* Continuation operator to do the actual transfer. */
/* r_size(op1) was set just above. */
static int
-do_execstack(i_ctx_t *i_ctx_p, bool include_marks, os_ptr op1)
+do_execstack(i_ctx_t *i_ctx_p, bool include_marks, bool include_oparrays, os_ptr op1)
{
os_ptr op = osp;
ref *arefs = op1->value.refs;
@@ -829,6 +830,12 @@ do_execstack(i_ctx_t *i_ctx_p, bool include_marks, os_ptr op1)
strlen(tname), (const byte *)tname);
break;
}
+ case t_array:
+ case t_shortarray:
+ case t_mixedarray:
+ if (!include_oparrays && errorexec_find(i_ctx_p, rq) < 0)
+ make_null(rq);
+ break;
default:
;
}
@@ -841,14 +848,14 @@ execstack_continue(i_ctx_t *i_ctx_p)
{
os_ptr op = osp;
- return do_execstack(i_ctx_p, false, op);
+ return do_execstack(i_ctx_p, false, false, op);
}
static int
execstack2_continue(i_ctx_t *i_ctx_p)
{
os_ptr op = osp;
- return do_execstack(i_ctx_p, op->value.boolval, op - 1);
+ return do_execstack(i_ctx_p, op->value.boolval, true, op - 1);
}
/* - .needinput - */
|
CWE-200
| null | null |
1,889
|
static char *have_snapdir(struct vfs_handle_struct *handle,
const char *path)
{
struct smb_filename smb_fname;
int ret;
struct shadow_copy2_config *config;
SMB_VFS_HANDLE_GET_DATA(handle, config, struct shadow_copy2_config,
return NULL);
ZERO_STRUCT(smb_fname);
smb_fname.base_name = talloc_asprintf(talloc_tos(), "%s/%s",
path, config->snapdir);
if (smb_fname.base_name == NULL) {
return NULL;
}
ret = SMB_VFS_NEXT_STAT(handle, &smb_fname);
if ((ret == 0) && (S_ISDIR(smb_fname.st.st_ex_mode))) {
return smb_fname.base_name;
}
TALLOC_FREE(smb_fname.base_name);
return NULL;
return NULL;
}
|
+Info
| 0
|
static char *have_snapdir(struct vfs_handle_struct *handle,
const char *path)
{
struct smb_filename smb_fname;
int ret;
struct shadow_copy2_config *config;
SMB_VFS_HANDLE_GET_DATA(handle, config, struct shadow_copy2_config,
return NULL);
ZERO_STRUCT(smb_fname);
smb_fname.base_name = talloc_asprintf(talloc_tos(), "%s/%s",
path, config->snapdir);
if (smb_fname.base_name == NULL) {
return NULL;
}
ret = SMB_VFS_NEXT_STAT(handle, &smb_fname);
if ((ret == 0) && (S_ISDIR(smb_fname.st.st_ex_mode))) {
return smb_fname.base_name;
}
TALLOC_FREE(smb_fname.base_name);
return NULL;
return NULL;
}
|
@@ -30,6 +30,7 @@
*/
#include "includes.h"
+#include "smbd/smbd.h"
#include "system/filesys.h"
#include "include/ntioctl.h"
#include "util_tdb.h"
@@ -1180,6 +1181,42 @@ static char *have_snapdir(struct vfs_handle_struct *handle,
return NULL;
}
+static bool check_access_snapdir(struct vfs_handle_struct *handle,
+ const char *path)
+{
+ struct smb_filename smb_fname;
+ int ret;
+ NTSTATUS status;
+
+ ZERO_STRUCT(smb_fname);
+ smb_fname.base_name = talloc_asprintf(talloc_tos(),
+ "%s",
+ path);
+ if (smb_fname.base_name == NULL) {
+ return false;
+ }
+
+ ret = SMB_VFS_NEXT_STAT(handle, &smb_fname);
+ if (ret != 0 || !S_ISDIR(smb_fname.st.st_ex_mode)) {
+ TALLOC_FREE(smb_fname.base_name);
+ return false;
+ }
+
+ status = smbd_check_access_rights(handle->conn,
+ &smb_fname,
+ false,
+ SEC_DIR_LIST);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(0,("user does not have list permission "
+ "on snapdir %s\n",
+ smb_fname.base_name));
+ TALLOC_FREE(smb_fname.base_name);
+ return false;
+ }
+ TALLOC_FREE(smb_fname.base_name);
+ return true;
+}
+
/**
* Find the snapshot directory (if any) for the given
* filename (which is relative to the share).
@@ -1329,6 +1366,7 @@ static int shadow_copy2_get_shadow_copy_data(
const char *snapdir;
struct dirent *d;
TALLOC_CTX *tmp_ctx = talloc_stackframe();
+ bool ret;
snapdir = shadow_copy2_find_snapdir(tmp_ctx, handle, fsp->fsp_name);
if (snapdir == NULL) {
@@ -1338,6 +1376,13 @@ static int shadow_copy2_get_shadow_copy_data(
talloc_free(tmp_ctx);
return -1;
}
+ ret = check_access_snapdir(handle, snapdir);
+ if (!ret) {
+ DEBUG(0,("access denied on listing snapdir %s\n", snapdir));
+ errno = EACCES;
+ talloc_free(tmp_ctx);
+ return -1;
+ }
p = SMB_VFS_NEXT_OPENDIR(handle, snapdir, NULL, 0);
|
CWE-200
| null | null |
1,890
|
static int shadow_copy2_chmod(vfs_handle_struct *handle, const char *fname,
mode_t mode)
{
time_t timestamp;
char *stripped;
int ret, saved_errno;
char *conv;
if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
×tamp, &stripped)) {
return -1;
}
if (timestamp == 0) {
return SMB_VFS_NEXT_CHMOD(handle, fname, mode);
}
conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
TALLOC_FREE(stripped);
if (conv == NULL) {
return -1;
}
ret = SMB_VFS_NEXT_CHMOD(handle, conv, mode);
saved_errno = errno;
TALLOC_FREE(conv);
errno = saved_errno;
return ret;
}
|
+Info
| 0
|
static int shadow_copy2_chmod(vfs_handle_struct *handle, const char *fname,
mode_t mode)
{
time_t timestamp;
char *stripped;
int ret, saved_errno;
char *conv;
if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
×tamp, &stripped)) {
return -1;
}
if (timestamp == 0) {
return SMB_VFS_NEXT_CHMOD(handle, fname, mode);
}
conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
TALLOC_FREE(stripped);
if (conv == NULL) {
return -1;
}
ret = SMB_VFS_NEXT_CHMOD(handle, conv, mode);
saved_errno = errno;
TALLOC_FREE(conv);
errno = saved_errno;
return ret;
}
|
@@ -30,6 +30,7 @@
*/
#include "includes.h"
+#include "smbd/smbd.h"
#include "system/filesys.h"
#include "include/ntioctl.h"
#include "util_tdb.h"
@@ -1180,6 +1181,42 @@ static char *have_snapdir(struct vfs_handle_struct *handle,
return NULL;
}
+static bool check_access_snapdir(struct vfs_handle_struct *handle,
+ const char *path)
+{
+ struct smb_filename smb_fname;
+ int ret;
+ NTSTATUS status;
+
+ ZERO_STRUCT(smb_fname);
+ smb_fname.base_name = talloc_asprintf(talloc_tos(),
+ "%s",
+ path);
+ if (smb_fname.base_name == NULL) {
+ return false;
+ }
+
+ ret = SMB_VFS_NEXT_STAT(handle, &smb_fname);
+ if (ret != 0 || !S_ISDIR(smb_fname.st.st_ex_mode)) {
+ TALLOC_FREE(smb_fname.base_name);
+ return false;
+ }
+
+ status = smbd_check_access_rights(handle->conn,
+ &smb_fname,
+ false,
+ SEC_DIR_LIST);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(0,("user does not have list permission "
+ "on snapdir %s\n",
+ smb_fname.base_name));
+ TALLOC_FREE(smb_fname.base_name);
+ return false;
+ }
+ TALLOC_FREE(smb_fname.base_name);
+ return true;
+}
+
/**
* Find the snapshot directory (if any) for the given
* filename (which is relative to the share).
@@ -1329,6 +1366,7 @@ static int shadow_copy2_get_shadow_copy_data(
const char *snapdir;
struct dirent *d;
TALLOC_CTX *tmp_ctx = talloc_stackframe();
+ bool ret;
snapdir = shadow_copy2_find_snapdir(tmp_ctx, handle, fsp->fsp_name);
if (snapdir == NULL) {
@@ -1338,6 +1376,13 @@ static int shadow_copy2_get_shadow_copy_data(
talloc_free(tmp_ctx);
return -1;
}
+ ret = check_access_snapdir(handle, snapdir);
+ if (!ret) {
+ DEBUG(0,("access denied on listing snapdir %s\n", snapdir));
+ errno = EACCES;
+ talloc_free(tmp_ctx);
+ return -1;
+ }
p = SMB_VFS_NEXT_OPENDIR(handle, snapdir, NULL, 0);
|
CWE-200
| null | null |
1,891
|
static char *shadow_copy2_convert(TALLOC_CTX *mem_ctx,
struct vfs_handle_struct *handle,
const char *name, time_t timestamp)
{
struct smb_filename converted_fname;
char *result = NULL;
size_t *slashes = NULL;
unsigned num_slashes;
char *path = NULL;
size_t pathlen;
char *insert = NULL;
char *converted = NULL;
size_t insertlen;
int i, saved_errno;
size_t min_offset;
struct shadow_copy2_config *config;
SMB_VFS_HANDLE_GET_DATA(handle, config, struct shadow_copy2_config,
return NULL);
DEBUG(10, ("converting '%s'\n", name));
if (!config->snapdirseverywhere) {
int ret;
char *snapshot_path;
snapshot_path = shadow_copy2_snapshot_path(talloc_tos(),
handle,
timestamp);
if (snapshot_path == NULL) {
goto fail;
}
if (config->rel_connectpath == NULL) {
converted = talloc_asprintf(mem_ctx, "%s/%s",
snapshot_path, name);
} else {
converted = talloc_asprintf(mem_ctx, "%s/%s/%s",
snapshot_path,
config->rel_connectpath,
name);
}
if (converted == NULL) {
goto fail;
}
ZERO_STRUCT(converted_fname);
converted_fname.base_name = converted;
ret = SMB_VFS_NEXT_LSTAT(handle, &converted_fname);
DEBUG(10, ("Trying[not snapdirseverywhere] %s: %d (%s)\n",
converted,
ret, ret == 0 ? "ok" : strerror(errno)));
if (ret == 0) {
DEBUG(10, ("Found %s\n", converted));
result = converted;
converted = NULL;
goto fail;
} else {
errno = ENOENT;
goto fail;
}
/* never reached ... */
}
if (name[0] == 0) {
path = talloc_strdup(mem_ctx, handle->conn->connectpath);
} else {
path = talloc_asprintf(
mem_ctx, "%s/%s", handle->conn->connectpath, name);
}
if (path == NULL) {
errno = ENOMEM;
goto fail;
}
pathlen = talloc_get_size(path)-1;
if (!shadow_copy2_find_slashes(talloc_tos(), path,
&slashes, &num_slashes)) {
goto fail;
}
insert = shadow_copy2_insert_string(talloc_tos(), handle, timestamp);
if (insert == NULL) {
goto fail;
}
insertlen = talloc_get_size(insert)-1;
/*
* Note: We deliberatly don't expensively initialize the
* array with talloc_zero here: Putting zero into
* converted[pathlen+insertlen] below is sufficient, because
* in the following for loop, the insert string is inserted
* at various slash places. So the memory up to position
* pathlen+insertlen will always be initialized when the
* converted string is used.
*/
converted = talloc_array(mem_ctx, char, pathlen + insertlen + 1);
if (converted == NULL) {
goto fail;
}
if (path[pathlen-1] != '/') {
/*
* Append a fake slash to find the snapshot root
*/
size_t *tmp;
tmp = talloc_realloc(talloc_tos(), slashes,
size_t, num_slashes+1);
if (tmp == NULL) {
goto fail;
}
slashes = tmp;
slashes[num_slashes] = pathlen;
num_slashes += 1;
}
min_offset = 0;
if (!config->crossmountpoints) {
min_offset = strlen(config->mount_point);
}
memcpy(converted, path, pathlen+1);
converted[pathlen+insertlen] = '\0';
ZERO_STRUCT(converted_fname);
converted_fname.base_name = converted;
for (i = num_slashes-1; i>=0; i--) {
int ret;
size_t offset;
offset = slashes[i];
if (offset < min_offset) {
errno = ENOENT;
goto fail;
}
memcpy(converted+offset, insert, insertlen);
offset += insertlen;
memcpy(converted+offset, path + slashes[i],
pathlen - slashes[i]);
ret = SMB_VFS_NEXT_LSTAT(handle, &converted_fname);
DEBUG(10, ("Trying[snapdirseverywhere] %s: %d (%s)\n",
converted,
ret, ret == 0 ? "ok" : strerror(errno)));
if (ret == 0) {
/* success */
break;
}
if (errno == ENOTDIR) {
/*
* This is a valid condition: We appended the
* .snaphots/@GMT.. to a file name. Just try
* with the upper levels.
*/
continue;
}
if (errno != ENOENT) {
/* Other problem than "not found" */
goto fail;
}
}
if (i >= 0) {
/*
* Found something
*/
DEBUG(10, ("Found %s\n", converted));
result = converted;
converted = NULL;
} else {
errno = ENOENT;
}
fail:
saved_errno = errno;
TALLOC_FREE(converted);
TALLOC_FREE(insert);
TALLOC_FREE(slashes);
TALLOC_FREE(path);
errno = saved_errno;
return result;
}
|
+Info
| 0
|
static char *shadow_copy2_convert(TALLOC_CTX *mem_ctx,
struct vfs_handle_struct *handle,
const char *name, time_t timestamp)
{
struct smb_filename converted_fname;
char *result = NULL;
size_t *slashes = NULL;
unsigned num_slashes;
char *path = NULL;
size_t pathlen;
char *insert = NULL;
char *converted = NULL;
size_t insertlen;
int i, saved_errno;
size_t min_offset;
struct shadow_copy2_config *config;
SMB_VFS_HANDLE_GET_DATA(handle, config, struct shadow_copy2_config,
return NULL);
DEBUG(10, ("converting '%s'\n", name));
if (!config->snapdirseverywhere) {
int ret;
char *snapshot_path;
snapshot_path = shadow_copy2_snapshot_path(talloc_tos(),
handle,
timestamp);
if (snapshot_path == NULL) {
goto fail;
}
if (config->rel_connectpath == NULL) {
converted = talloc_asprintf(mem_ctx, "%s/%s",
snapshot_path, name);
} else {
converted = talloc_asprintf(mem_ctx, "%s/%s/%s",
snapshot_path,
config->rel_connectpath,
name);
}
if (converted == NULL) {
goto fail;
}
ZERO_STRUCT(converted_fname);
converted_fname.base_name = converted;
ret = SMB_VFS_NEXT_LSTAT(handle, &converted_fname);
DEBUG(10, ("Trying[not snapdirseverywhere] %s: %d (%s)\n",
converted,
ret, ret == 0 ? "ok" : strerror(errno)));
if (ret == 0) {
DEBUG(10, ("Found %s\n", converted));
result = converted;
converted = NULL;
goto fail;
} else {
errno = ENOENT;
goto fail;
}
/* never reached ... */
}
if (name[0] == 0) {
path = talloc_strdup(mem_ctx, handle->conn->connectpath);
} else {
path = talloc_asprintf(
mem_ctx, "%s/%s", handle->conn->connectpath, name);
}
if (path == NULL) {
errno = ENOMEM;
goto fail;
}
pathlen = talloc_get_size(path)-1;
if (!shadow_copy2_find_slashes(talloc_tos(), path,
&slashes, &num_slashes)) {
goto fail;
}
insert = shadow_copy2_insert_string(talloc_tos(), handle, timestamp);
if (insert == NULL) {
goto fail;
}
insertlen = talloc_get_size(insert)-1;
/*
* Note: We deliberatly don't expensively initialize the
* array with talloc_zero here: Putting zero into
* converted[pathlen+insertlen] below is sufficient, because
* in the following for loop, the insert string is inserted
* at various slash places. So the memory up to position
* pathlen+insertlen will always be initialized when the
* converted string is used.
*/
converted = talloc_array(mem_ctx, char, pathlen + insertlen + 1);
if (converted == NULL) {
goto fail;
}
if (path[pathlen-1] != '/') {
/*
* Append a fake slash to find the snapshot root
*/
size_t *tmp;
tmp = talloc_realloc(talloc_tos(), slashes,
size_t, num_slashes+1);
if (tmp == NULL) {
goto fail;
}
slashes = tmp;
slashes[num_slashes] = pathlen;
num_slashes += 1;
}
min_offset = 0;
if (!config->crossmountpoints) {
min_offset = strlen(config->mount_point);
}
memcpy(converted, path, pathlen+1);
converted[pathlen+insertlen] = '\0';
ZERO_STRUCT(converted_fname);
converted_fname.base_name = converted;
for (i = num_slashes-1; i>=0; i--) {
int ret;
size_t offset;
offset = slashes[i];
if (offset < min_offset) {
errno = ENOENT;
goto fail;
}
memcpy(converted+offset, insert, insertlen);
offset += insertlen;
memcpy(converted+offset, path + slashes[i],
pathlen - slashes[i]);
ret = SMB_VFS_NEXT_LSTAT(handle, &converted_fname);
DEBUG(10, ("Trying[snapdirseverywhere] %s: %d (%s)\n",
converted,
ret, ret == 0 ? "ok" : strerror(errno)));
if (ret == 0) {
/* success */
break;
}
if (errno == ENOTDIR) {
/*
* This is a valid condition: We appended the
* .snaphots/@GMT.. to a file name. Just try
* with the upper levels.
*/
continue;
}
if (errno != ENOENT) {
/* Other problem than "not found" */
goto fail;
}
}
if (i >= 0) {
/*
* Found something
*/
DEBUG(10, ("Found %s\n", converted));
result = converted;
converted = NULL;
} else {
errno = ENOENT;
}
fail:
saved_errno = errno;
TALLOC_FREE(converted);
TALLOC_FREE(insert);
TALLOC_FREE(slashes);
TALLOC_FREE(path);
errno = saved_errno;
return result;
}
|
@@ -30,6 +30,7 @@
*/
#include "includes.h"
+#include "smbd/smbd.h"
#include "system/filesys.h"
#include "include/ntioctl.h"
#include "util_tdb.h"
@@ -1180,6 +1181,42 @@ static char *have_snapdir(struct vfs_handle_struct *handle,
return NULL;
}
+static bool check_access_snapdir(struct vfs_handle_struct *handle,
+ const char *path)
+{
+ struct smb_filename smb_fname;
+ int ret;
+ NTSTATUS status;
+
+ ZERO_STRUCT(smb_fname);
+ smb_fname.base_name = talloc_asprintf(talloc_tos(),
+ "%s",
+ path);
+ if (smb_fname.base_name == NULL) {
+ return false;
+ }
+
+ ret = SMB_VFS_NEXT_STAT(handle, &smb_fname);
+ if (ret != 0 || !S_ISDIR(smb_fname.st.st_ex_mode)) {
+ TALLOC_FREE(smb_fname.base_name);
+ return false;
+ }
+
+ status = smbd_check_access_rights(handle->conn,
+ &smb_fname,
+ false,
+ SEC_DIR_LIST);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(0,("user does not have list permission "
+ "on snapdir %s\n",
+ smb_fname.base_name));
+ TALLOC_FREE(smb_fname.base_name);
+ return false;
+ }
+ TALLOC_FREE(smb_fname.base_name);
+ return true;
+}
+
/**
* Find the snapshot directory (if any) for the given
* filename (which is relative to the share).
@@ -1329,6 +1366,7 @@ static int shadow_copy2_get_shadow_copy_data(
const char *snapdir;
struct dirent *d;
TALLOC_CTX *tmp_ctx = talloc_stackframe();
+ bool ret;
snapdir = shadow_copy2_find_snapdir(tmp_ctx, handle, fsp->fsp_name);
if (snapdir == NULL) {
@@ -1338,6 +1376,13 @@ static int shadow_copy2_get_shadow_copy_data(
talloc_free(tmp_ctx);
return -1;
}
+ ret = check_access_snapdir(handle, snapdir);
+ if (!ret) {
+ DEBUG(0,("access denied on listing snapdir %s\n", snapdir));
+ errno = EACCES;
+ talloc_free(tmp_ctx);
+ return -1;
+ }
p = SMB_VFS_NEXT_OPENDIR(handle, snapdir, NULL, 0);
|
CWE-200
| null | null |
1,892
|
static char *shadow_copy2_find_mount_point(TALLOC_CTX *mem_ctx,
vfs_handle_struct *handle)
{
char *path = talloc_strdup(mem_ctx, handle->conn->connectpath);
dev_t dev;
struct stat st;
char *p;
if (stat(path, &st) != 0) {
talloc_free(path);
return NULL;
}
dev = st.st_dev;
while ((p = strrchr(path, '/')) && p > path) {
*p = 0;
if (stat(path, &st) != 0) {
talloc_free(path);
return NULL;
}
if (st.st_dev != dev) {
*p = '/';
break;
}
}
return path;
}
|
+Info
| 0
|
static char *shadow_copy2_find_mount_point(TALLOC_CTX *mem_ctx,
vfs_handle_struct *handle)
{
char *path = talloc_strdup(mem_ctx, handle->conn->connectpath);
dev_t dev;
struct stat st;
char *p;
if (stat(path, &st) != 0) {
talloc_free(path);
return NULL;
}
dev = st.st_dev;
while ((p = strrchr(path, '/')) && p > path) {
*p = 0;
if (stat(path, &st) != 0) {
talloc_free(path);
return NULL;
}
if (st.st_dev != dev) {
*p = '/';
break;
}
}
return path;
}
|
@@ -30,6 +30,7 @@
*/
#include "includes.h"
+#include "smbd/smbd.h"
#include "system/filesys.h"
#include "include/ntioctl.h"
#include "util_tdb.h"
@@ -1180,6 +1181,42 @@ static char *have_snapdir(struct vfs_handle_struct *handle,
return NULL;
}
+static bool check_access_snapdir(struct vfs_handle_struct *handle,
+ const char *path)
+{
+ struct smb_filename smb_fname;
+ int ret;
+ NTSTATUS status;
+
+ ZERO_STRUCT(smb_fname);
+ smb_fname.base_name = talloc_asprintf(talloc_tos(),
+ "%s",
+ path);
+ if (smb_fname.base_name == NULL) {
+ return false;
+ }
+
+ ret = SMB_VFS_NEXT_STAT(handle, &smb_fname);
+ if (ret != 0 || !S_ISDIR(smb_fname.st.st_ex_mode)) {
+ TALLOC_FREE(smb_fname.base_name);
+ return false;
+ }
+
+ status = smbd_check_access_rights(handle->conn,
+ &smb_fname,
+ false,
+ SEC_DIR_LIST);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(0,("user does not have list permission "
+ "on snapdir %s\n",
+ smb_fname.base_name));
+ TALLOC_FREE(smb_fname.base_name);
+ return false;
+ }
+ TALLOC_FREE(smb_fname.base_name);
+ return true;
+}
+
/**
* Find the snapshot directory (if any) for the given
* filename (which is relative to the share).
@@ -1329,6 +1366,7 @@ static int shadow_copy2_get_shadow_copy_data(
const char *snapdir;
struct dirent *d;
TALLOC_CTX *tmp_ctx = talloc_stackframe();
+ bool ret;
snapdir = shadow_copy2_find_snapdir(tmp_ctx, handle, fsp->fsp_name);
if (snapdir == NULL) {
@@ -1338,6 +1376,13 @@ static int shadow_copy2_get_shadow_copy_data(
talloc_free(tmp_ctx);
return -1;
}
+ ret = check_access_snapdir(handle, snapdir);
+ if (!ret) {
+ DEBUG(0,("access denied on listing snapdir %s\n", snapdir));
+ errno = EACCES;
+ talloc_free(tmp_ctx);
+ return -1;
+ }
p = SMB_VFS_NEXT_OPENDIR(handle, snapdir, NULL, 0);
|
CWE-200
| null | null |
1,893
|
static int shadow_copy2_fstat(vfs_handle_struct *handle, files_struct *fsp,
SMB_STRUCT_STAT *sbuf)
{
time_t timestamp;
int ret;
ret = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
if (ret == -1) {
return ret;
}
if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
fsp->fsp_name->base_name,
×tamp, NULL)) {
return 0;
}
if (timestamp != 0) {
convert_sbuf(handle, fsp->fsp_name->base_name, sbuf);
}
return 0;
}
|
+Info
| 0
|
static int shadow_copy2_fstat(vfs_handle_struct *handle, files_struct *fsp,
SMB_STRUCT_STAT *sbuf)
{
time_t timestamp;
int ret;
ret = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
if (ret == -1) {
return ret;
}
if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
fsp->fsp_name->base_name,
×tamp, NULL)) {
return 0;
}
if (timestamp != 0) {
convert_sbuf(handle, fsp->fsp_name->base_name, sbuf);
}
return 0;
}
|
@@ -30,6 +30,7 @@
*/
#include "includes.h"
+#include "smbd/smbd.h"
#include "system/filesys.h"
#include "include/ntioctl.h"
#include "util_tdb.h"
@@ -1180,6 +1181,42 @@ static char *have_snapdir(struct vfs_handle_struct *handle,
return NULL;
}
+static bool check_access_snapdir(struct vfs_handle_struct *handle,
+ const char *path)
+{
+ struct smb_filename smb_fname;
+ int ret;
+ NTSTATUS status;
+
+ ZERO_STRUCT(smb_fname);
+ smb_fname.base_name = talloc_asprintf(talloc_tos(),
+ "%s",
+ path);
+ if (smb_fname.base_name == NULL) {
+ return false;
+ }
+
+ ret = SMB_VFS_NEXT_STAT(handle, &smb_fname);
+ if (ret != 0 || !S_ISDIR(smb_fname.st.st_ex_mode)) {
+ TALLOC_FREE(smb_fname.base_name);
+ return false;
+ }
+
+ status = smbd_check_access_rights(handle->conn,
+ &smb_fname,
+ false,
+ SEC_DIR_LIST);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(0,("user does not have list permission "
+ "on snapdir %s\n",
+ smb_fname.base_name));
+ TALLOC_FREE(smb_fname.base_name);
+ return false;
+ }
+ TALLOC_FREE(smb_fname.base_name);
+ return true;
+}
+
/**
* Find the snapshot directory (if any) for the given
* filename (which is relative to the share).
@@ -1329,6 +1366,7 @@ static int shadow_copy2_get_shadow_copy_data(
const char *snapdir;
struct dirent *d;
TALLOC_CTX *tmp_ctx = talloc_stackframe();
+ bool ret;
snapdir = shadow_copy2_find_snapdir(tmp_ctx, handle, fsp->fsp_name);
if (snapdir == NULL) {
@@ -1338,6 +1376,13 @@ static int shadow_copy2_get_shadow_copy_data(
talloc_free(tmp_ctx);
return -1;
}
+ ret = check_access_snapdir(handle, snapdir);
+ if (!ret) {
+ DEBUG(0,("access denied on listing snapdir %s\n", snapdir));
+ errno = EACCES;
+ talloc_free(tmp_ctx);
+ return -1;
+ }
p = SMB_VFS_NEXT_OPENDIR(handle, snapdir, NULL, 0);
|
CWE-200
| null | null |
1,894
|
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;
}
}
}
| null | 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;
}
}
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,895
|
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);
}
| null | 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);
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,896
|
uint32_t smb1cli_conn_capabilities(struct smbXcli_conn *conn)
{
return conn->smb1.capabilities;
}
| null | 0
|
uint32_t smb1cli_conn_capabilities(struct smbXcli_conn *conn)
{
return conn->smb1.capabilities;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,897
|
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);
}
| null | 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);
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,898
|
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;
}
| null | 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;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,899
|
bool smb1cli_conn_encryption_on(struct smbXcli_conn *conn)
{
return common_encryption_on(conn->smb1.trans_enc);
}
| null | 0
|
bool smb1cli_conn_encryption_on(struct smbXcli_conn *conn)
{
return common_encryption_on(conn->smb1.trans_enc);
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.