8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-22 22:43:03 +01:00

Backported CORE-6525: Segfaults in fbclient when receiving invalid / unexpected data from server

This commit is contained in:
AlexPeshkoff 2021-03-26 15:01:03 +03:00
parent a830ea7e70
commit c10201203a
15 changed files with 372 additions and 422 deletions

View File

@ -21,7 +21,7 @@
COMMON_FLAGS=-ggdb -DFB_SEND_FLAGS=MSG_NOSIGNAL -DLINUX -DAMD64 -pipe -MMD -fPIC -fmessage-length=0 -fno-delete-null-pointer-checks
CXXFLAGS=-std=gnu++03
OPTIMIZE_FLAGS=-O3 -fno-omit-frame-pointer
WARN_FLAGS=-Wall -Wno-switch -Wno-parentheses -Wno-unknown-pragmas -Wno-unused-variable -Wno-invalid-offsetof -Wno-narrowing -Wno-unused-local-typedefs
WARN_FLAGS=-Wall -Wno-switch -Wno-parentheses -Wno-unknown-pragmas -Wno-unused-variable -Wno-invalid-offsetof -Wno-narrowing -Wno-unused-local-typedefs -Wno-class-memaccess
PROD_FLAGS=$(COMMON_FLAGS) $(OPTIMIZE_FLAGS)
#DEV_FLAGS=-DUSE_VALGRIND $(COMMON_FLAGS) $(WARN_FLAGS) -fmax-errors=8

View File

@ -48,18 +48,23 @@
// conflicting blk_t definitions (we are gonna fix this, in due time).
static bool_t burp_getbytes(XDR*, SCHAR *, unsigned);
static bool_t burp_putbytes(XDR*, const SCHAR*, unsigned);
struct BurpXdr : public xdr_t
{
virtual bool_t x_getbytes(SCHAR *, unsigned); // get some bytes from "
virtual bool_t x_putbytes(const SCHAR*, unsigned); // put some bytes to "
BurpXdr()
: x_public(NULL)
{ }
lstring* x_public;
};
typedef struct BurpXdr XDR;
static bool_t expand_buffer(XDR*);
static int xdr_init(XDR*, lstring*, enum xdr_op);
static bool_t xdr_slice(XDR*, lstring*, /*USHORT,*/ const UCHAR*);
static xdr_t::xdr_ops burp_ops =
{
burp_getbytes,
burp_putbytes
};
const unsigned increment = 1024;
@ -224,7 +229,7 @@ ULONG CAN_slice(lstring* buffer, lstring* slice, bool_t direction, /*USHORT sdl_
}
static bool_t burp_getbytes(XDR* xdrs, SCHAR* buff, unsigned bytecount)
bool_t BurpXdr::x_getbytes(SCHAR* buff, unsigned bytecount)
{
/**************************************
*
@ -237,29 +242,29 @@ static bool_t burp_getbytes(XDR* xdrs, SCHAR* buff, unsigned bytecount)
*
**************************************/
if (bytecount && xdrs->x_handy >= bytecount)
if (bytecount && x_handy >= bytecount)
{
memcpy(buff, xdrs->x_private, bytecount);
xdrs->x_private += bytecount;
xdrs->x_handy -= bytecount;
memcpy(buff, x_private, bytecount);
x_private += bytecount;
x_handy -= bytecount;
return TRUE;
}
while (bytecount--)
{
if (xdrs->x_handy == 0 && !expand_buffer(xdrs))
if (x_handy == 0 && !expand_buffer(this))
return FALSE;
*buff++ = *xdrs->x_private++;
--xdrs->x_handy;
*buff++ = *x_private++;
--x_handy;
}
return TRUE;
}
static bool_t burp_putbytes(XDR* xdrs, const SCHAR* buff, unsigned bytecount)
bool_t BurpXdr::x_putbytes(const SCHAR* buff, unsigned bytecount)
{
/**************************************
*
@ -272,22 +277,22 @@ static bool_t burp_putbytes(XDR* xdrs, const SCHAR* buff, unsigned bytecount)
*
**************************************/
if (bytecount && xdrs->x_handy >= bytecount)
if (bytecount && x_handy >= bytecount)
{
memcpy(xdrs->x_private, buff, bytecount);
xdrs->x_private += bytecount;
xdrs->x_handy -= bytecount;
memcpy(x_private, buff, bytecount);
x_private += bytecount;
x_handy -= bytecount;
return TRUE;
}
while (bytecount--)
{
if (xdrs->x_handy == 0 && !expand_buffer(xdrs))
if (x_handy == 0 && !expand_buffer(this))
return FALSE;
*xdrs->x_private++ = *buff++;
--xdrs->x_handy;
*x_private++ = *buff++;
--x_handy;
}
return TRUE;
@ -308,7 +313,7 @@ static bool_t expand_buffer(XDR* xdrs)
* old one.
*
**************************************/
lstring* buffer = (lstring*) xdrs->x_public;
lstring* buffer = xdrs->x_public;
const unsigned usedLength = xdrs->x_private - xdrs->x_base;
const unsigned length = usedLength + xdrs->x_handy + increment;
@ -341,11 +346,8 @@ static int xdr_init(XDR* xdrs, lstring* buffer, enum xdr_op x_op)
*
**************************************/
xdrs->x_public = (caddr_t) buffer;
xdrs->x_base = xdrs->x_private = (caddr_t) buffer->lstr_address;
xdrs->x_handy = buffer->lstr_length;
xdrs->x_ops = &burp_ops;
xdrs->x_op = x_op;
xdrs->x_public = buffer;
xdrs->create((caddr_t) buffer->lstr_address, buffer->lstr_length, x_op);
return TRUE;
}

View File

@ -1550,8 +1550,7 @@ unsigned sqlTypeToDsc(unsigned runOffset, unsigned sqlType, unsigned sqlLength,
default:
fb_assert(false);
// keep old yvalve logic
dscType = sqlType;
Firebird::Arg::Gds(isc_dsql_datatype_err).raise();
break;
}

View File

@ -31,6 +31,8 @@
#include "../yvalve/gds_proto.h"
#include "../common/gdsassert.h"
typedef struct xdr_t XDR;
inline UCHAR* XDR_ALLOC(ULONG size)
{
return (UCHAR*) gds__alloc((SLONG) size);
@ -66,24 +68,14 @@ inline void DEBUG_XDR_FREE(XDR*, const void*, const void*, ULONG)
const unsigned MAXSTRING_FOR_WRAPSTRING = 65535;
static bool_t mem_getbytes(XDR*, SCHAR*, unsigned);
static bool_t mem_putbytes(XDR*, const SCHAR*, unsigned);
static const XDR::xdr_ops mem_ops =
{
mem_getbytes,
mem_putbytes
};
#define GETBYTES (*xdrs->x_ops->x_getbytes)
#define PUTBYTES (*xdrs->x_ops->x_putbytes)
#define GETBYTES xdrs->x_getbytes
#define PUTBYTES xdrs->x_putbytes
inline bool_t GETLONG(XDR* xdrs, SLONG* lp)
{
SLONG l;
if (!(*xdrs->x_ops->x_getbytes)(xdrs, reinterpret_cast<char*>(&l), 4))
if (!xdrs->x_getbytes(reinterpret_cast<char*>(&l), 4))
return FALSE;
*lp = xdrs->x_local ? l : ntohl(l);
@ -94,7 +86,7 @@ inline bool_t GETLONG(XDR* xdrs, SLONG* lp)
inline bool_t PUTLONG(XDR* xdrs, const SLONG* lp)
{
const SLONG l = xdrs->x_local ? *lp : htonl(*lp);
return (*xdrs->x_ops->x_putbytes)(xdrs, reinterpret_cast<const char*>(&l), 4);
return xdrs->x_putbytes(reinterpret_cast<const char*>(&l), 4);
}
static SCHAR zeros[4] = { 0, 0, 0, 0 };
@ -484,17 +476,17 @@ bool_t xdr_opaque(XDR* xdrs, SCHAR* p, unsigned len)
switch (xdrs->x_op)
{
case XDR_ENCODE:
if (!PUTBYTES(xdrs, p, len))
if (!PUTBYTES(p, len))
return FALSE;
if (l)
return PUTBYTES(xdrs, filler, l);
return PUTBYTES(filler, l);
return TRUE;
case XDR_DECODE:
if (!GETBYTES(xdrs, p, len))
if (!GETBYTES(p, len))
return FALSE;
if (l)
return GETBYTES(xdrs, trash, l);
return GETBYTES(trash, l);
return TRUE;
case XDR_FREE:
@ -601,12 +593,12 @@ bool_t xdr_string(XDR* xdrs, SCHAR** sp, unsigned maxlength)
length = static_cast<ULONG>(strlen(*sp));
if (length > maxlength ||
!PUTLONG(xdrs, reinterpret_cast<SLONG*>(&length)) ||
!PUTBYTES(xdrs, *sp, length))
!PUTBYTES(*sp, length))
{
return FALSE;
}
if ((length = (4 - length) & 3) != 0)
return PUTBYTES(xdrs, filler, length);
return PUTBYTES(filler, length);
return TRUE;
case XDR_DECODE:
@ -619,13 +611,13 @@ bool_t xdr_string(XDR* xdrs, SCHAR** sp, unsigned maxlength)
DEBUG_XDR_ALLOC(xdrs, sp, *sp, (maxlength + 1));
}
if (!GETLONG(xdrs, reinterpret_cast<SLONG*>(&length)) ||
length > maxlength || !GETBYTES(xdrs, *sp, length))
length > maxlength || !GETBYTES(*sp, length))
{
return FALSE;
}
(*sp)[length] = 0;
if ((length = (4 - length) & 3) != 0)
return GETBYTES(xdrs, trash, length);
return GETBYTES(trash, length);
return TRUE;
case XDR_FREE:
@ -759,7 +751,7 @@ bool_t xdr_wrapstring(XDR* xdrs, SCHAR** strp)
}
int xdrmem_create( XDR* xdrs, SCHAR* addr, unsigned len, xdr_op x_op)
int xdr_t::create(SCHAR* addr, unsigned len, xdr_op op)
{
/**************************************
*
@ -772,16 +764,14 @@ int xdrmem_create( XDR* xdrs, SCHAR* addr, unsigned len, xdr_op x_op)
*
**************************************/
xdrs->x_base = xdrs->x_private = addr;
xdrs->x_handy = len;
xdrs->x_ops = &mem_ops;
xdrs->x_op = x_op;
x_base = x_private = addr;
x_handy = len;
x_op = op;
return TRUE;
}
static bool_t mem_getbytes( XDR* xdrs, SCHAR* buff, unsigned bytecount)
bool_t xdr_t::x_getbytes(SCHAR* buff, unsigned bytecount)
{
/**************************************
*
@ -793,14 +783,14 @@ static bool_t mem_getbytes( XDR* xdrs, SCHAR* buff, unsigned bytecount)
* Get a bunch of bytes from a memory stream if it fits.
*
**************************************/
if (xdrs->x_handy < bytecount)
if (x_handy < bytecount)
return FALSE;
if (bytecount)
{
memcpy(buff, xdrs->x_private, bytecount);
xdrs->x_private += bytecount;
xdrs->x_handy -= bytecount;
memcpy(buff, x_private, bytecount);
x_private += bytecount;
x_handy -= bytecount;
}
return TRUE;
@ -828,7 +818,7 @@ SLONG xdr_peek_long(const XDR* xdrs, const void* data, size_t size)
}
static bool_t mem_putbytes(XDR* xdrs, const SCHAR* buff, unsigned bytecount)
bool_t xdr_t::x_putbytes(const SCHAR* buff, unsigned bytecount)
{
/**************************************
*
@ -840,15 +830,19 @@ static bool_t mem_putbytes(XDR* xdrs, const SCHAR* buff, unsigned bytecount)
* Put a bunch of bytes to a memory stream if it fits.
*
**************************************/
if (xdrs->x_handy < bytecount)
if (x_handy < bytecount)
return FALSE;
if (bytecount)
{
memcpy(xdrs->x_private, buff, bytecount);
xdrs->x_private += bytecount;
xdrs->x_handy -= bytecount;
memcpy(x_private, buff, bytecount);
x_private += bytecount;
x_handy -= bytecount;
}
return TRUE;
}
xdr_t::~xdr_t()
{ }

View File

@ -26,8 +26,8 @@
*
*/
#ifndef REMOTE_XDR_H
#define REMOTE_XDR_H
#ifndef COMMON_XDR_H
#define COMMON_XDR_H
#include <sys/types.h>
#ifdef WIN_NT
@ -49,32 +49,23 @@ typedef int bool_t;
enum xdr_op { XDR_ENCODE = 0, XDR_DECODE = 1, XDR_FREE = 2 };
typedef struct xdr_t
struct xdr_t
{
xdr_op x_op; // operation; fast additional param
struct xdr_ops
{
bool_t (*x_getbytes)(struct xdr_t*, SCHAR *, unsigned); // get some bytes from "
bool_t (*x_putbytes)(struct xdr_t*, const SCHAR*, unsigned); // put some bytes to "
} const *x_ops;
caddr_t x_public; // Users' data
virtual bool_t x_getbytes(SCHAR *, unsigned); // get some bytes from "
virtual bool_t x_putbytes(const SCHAR*, unsigned); // put some bytes to "
virtual ~xdr_t();
xdr_op x_op; // operation; fast additional param
caddr_t x_private; // pointer to private data
caddr_t x_base; // private used for position info
unsigned x_handy; // extra private word
bool x_local; // transmission is known to be local (bytes are in the host order)
#ifdef DEV_BUILD
bool x_client; // set this flag to true if this is client port
#endif
public:
xdr_t() :
x_op(XDR_ENCODE), x_ops(0), x_public(0), x_private(0), x_base(0), x_handy(0),
x_local(false)
#ifdef DEV_BUILD
, x_client(false)
#endif
x_op(XDR_ENCODE), x_private(0), x_base(0), x_handy(0), x_local(false)
{ }
} XDR;
int create(SCHAR* addr, unsigned len, xdr_op op);
};
#endif // REMOTE_XDR_H
#endif // COMMON_XDR_H

View File

@ -31,22 +31,22 @@
// Functions below need to have C++ linkage to avoid name clash with
// standard XDR. Firebird XDR is NOT compatible with Sun XDR at interface level
bool_t xdr_datum(XDR*, const dsc*, UCHAR*);
bool_t xdr_double(XDR*, double*);
bool_t xdr_enum(XDR*, xdr_op*);
bool_t xdr_float(XDR*, float*);
bool_t xdr_int(XDR*, int*);
bool_t xdr_long(XDR*, SLONG*);
bool_t xdr_opaque(XDR*, SCHAR*, unsigned);
bool_t xdr_quad(XDR*, SQUAD*);
bool_t xdr_short(XDR*, SSHORT*);
bool_t xdr_string(XDR*, SCHAR**, unsigned);
bool_t xdr_u_int(XDR*, unsigned*);
bool_t xdr_u_long(XDR*, ULONG*);
bool_t xdr_u_short(XDR*, u_short*);
bool_t xdr_wrapstring(XDR*, SCHAR**);
bool_t xdr_hyper(XDR*, void*);
bool_t xdrmem_create(XDR*, SCHAR*, unsigned, xdr_op);
SLONG xdr_peek_long(const XDR*, const void* data, size_t size);
bool_t xdr_datum(xdr_t*, const dsc*, UCHAR*);
bool_t xdr_double(xdr_t*, double*);
bool_t xdr_enum(xdr_t*, xdr_op*);
bool_t xdr_float(xdr_t*, float*);
bool_t xdr_int(xdr_t*, int*);
bool_t xdr_long(xdr_t*, SLONG*);
bool_t xdr_opaque(xdr_t*, SCHAR*, unsigned);
bool_t xdr_quad(xdr_t*, SQUAD*);
bool_t xdr_short(xdr_t*, SSHORT*);
bool_t xdr_string(xdr_t*, SCHAR**, unsigned);
bool_t xdr_u_int(xdr_t*, unsigned*);
bool_t xdr_u_long(xdr_t*, ULONG*);
bool_t xdr_u_short(xdr_t*, u_short*);
bool_t xdr_wrapstring(xdr_t*, SCHAR**);
bool_t xdr_hyper(xdr_t*, void*);
bool_t xdrmem_create(xdr_t*, SCHAR*, unsigned, xdr_op);
SLONG xdr_peek_long(const xdr_t*, const void* data, size_t size);
#endif // REMOTE_XDR_PROTO_H

View File

@ -129,6 +129,27 @@ namespace {
if (length > MAX_USHORT && port->port_protocol < PROTOCOL_VERSION13)
status_exception::raise(Arg::Gds(isc_imp_exc) << Arg::Gds(isc_blktoobig));
}
class SaveString
{
public:
SaveString(cstring& toSave, ULONG newLength, UCHAR* newBuffer)
: ptr(&toSave),
oldValue(*ptr)
{
ptr->cstr_address = newBuffer;
ptr->cstr_allocated = newLength;
}
~SaveString()
{
*ptr = oldValue;
}
private:
cstring* ptr;
cstring oldValue;
};
}
namespace Remote {
@ -2499,9 +2520,7 @@ Statement* Attachment::prepare(CheckStatusWrapper* status, ITransaction* apiTra,
}
P_RESP* response = &packet->p_resp;
CSTRING temp = response->p_resp_data;
response->p_resp_data.cstr_allocated = (ULONG) buffer.getCount();
response->p_resp_data.cstr_address = buffer.begin();
SaveString temp(response->p_resp_data, buffer.getCount(), buffer.begin());
try
{
@ -2522,8 +2541,8 @@ Statement* Attachment::prepare(CheckStatusWrapper* status, ITransaction* apiTra,
else
{
fb_assert(!response->p_resp_object);
response->p_resp_object = 0;
}
response->p_resp_data = temp;
if (!(status->getState() & Firebird::IStatus::STATE_ERRORS))
{
@ -3020,7 +3039,13 @@ int ResultSet::fetchNext(CheckStatusWrapper* status, void* buffer)
status_exception::raise(Arg::Gds(isc_port_len) <<
Arg::Num(msg_length) << Arg::Num(statement->rsr_user_select_format->fmt_length));
}
if (statement->rsr_user_select_format == statement->rsr_select_format) {
if (statement->rsr_user_select_format == statement->rsr_select_format)
{
if (!msg || !message->msg_address)
{
move_error(Arg::Gds(isc_dsql_sqlda_err));
// Msg 263 SQLDA missing or wrong number of variables
}
memcpy(msg, message->msg_address, msg_length);
}
else
@ -3399,7 +3424,7 @@ int Blob::getSegment(CheckStatusWrapper* status, unsigned int bufferLength, void
PACKET* packet = &rdb->rdb_packet;
P_SGMT* segment = &packet->p_sgmt;
P_RESP* response = &packet->p_resp;
CSTRING temp = response->p_resp_data;
SaveString temp(response->p_resp_data, bufferLength, bufferPtr);
// Handle a blob that has been created rather than opened (this should yield an error)
@ -3409,21 +3434,10 @@ int Blob::getSegment(CheckStatusWrapper* status, unsigned int bufferLength, void
segment->p_sgmt_length = bufferLength;
segment->p_sgmt_blob = blob->rbl_id;
segment->p_sgmt_segment.cstr_length = 0;
send_packet(port, packet);
response->p_resp_data.cstr_allocated = bufferLength;
response->p_resp_data.cstr_address = bufferPtr;
receive_response(status, rdb, packet);
try
{
receive_response(status, rdb, packet);
}
catch (const Exception& /*ex*/)
{
response->p_resp_data = temp;
throw;
}
response->p_resp_data = temp;
if (segmentLength)
*segmentLength = response->p_resp_data.cstr_length;
return IStatus::RESULT_OK;
@ -3557,15 +3571,7 @@ int Blob::getSegment(CheckStatusWrapper* status, unsigned int bufferLength, void
response->p_resp_data.cstr_allocated = blob->rbl_buffer_length;
response->p_resp_data.cstr_address = blob->rbl_buffer;
try
{
receive_response(status, rdb, packet);
}
catch (const Exception& /*ex*/)
{
response->p_resp_data = temp;
throw;
}
receive_response(status, rdb, packet);
blob->rbl_length = (USHORT) response->p_resp_data.cstr_length;
blob->rbl_ptr = blob->rbl_buffer;
@ -3576,8 +3582,6 @@ int Blob::getSegment(CheckStatusWrapper* status, unsigned int bufferLength, void
blob->rbl_flags |= Rbl::EOF_PENDING;
}
response->p_resp_data = temp;
if (segmentLength)
*segmentLength = length;
return code;
@ -6156,21 +6160,9 @@ static void info(CheckStatusWrapper* status,
// Set up for the response packet.
P_RESP* response = &packet->p_resp;
CSTRING temp = response->p_resp_data;
response->p_resp_data.cstr_allocated = buffer_length;
response->p_resp_data.cstr_address = buffer;
SaveString temp(response->p_resp_data, buffer_length, buffer);
try
{
receive_response(status, rdb, packet);
}
catch (const Exception&)
{
response->p_resp_data = temp;
throw;
}
response->p_resp_data = temp;
receive_response(status, rdb, packet);
}
static bool useLegacyAuth(const char* nm, int protocol, ClumpletWriter& dpb)
@ -6477,7 +6469,8 @@ static void mov_dsql_message(const UCHAR* from_msg,
*
**************************************/
if (!from_fmt || !to_fmt || from_fmt->fmt_desc.getCount() != to_fmt->fmt_desc.getCount())
if (!from_msg || !from_fmt || !to_msg || !to_fmt ||
from_fmt->fmt_desc.getCount() != to_fmt->fmt_desc.getCount())
{
move_error(Arg::Gds(isc_dsql_sqlda_err));
// Msg 263 SQLDA missing or wrong number of variables
@ -7326,19 +7319,10 @@ static void svcstart(CheckStatusWrapper* status,
// Set up for the response packet.
P_RESP* response = &packet->p_resp;
CSTRING temp = response->p_resp_data;
SaveString temp(response->p_resp_data, 0, NULL);
response->p_resp_data.cstr_length = 0;
try
{
receive_response(status, rdb, packet);
}
catch (const Exception&)
{
response->p_resp_data = temp;
throw;
}
response->p_resp_data = temp;
receive_response(status, rdb, packet);
}

View File

@ -543,9 +543,7 @@ static SocketsArray* forkSockets;
static void get_peer_info(rem_port*);
static void inet_gen_error(bool, rem_port*, const Arg::StatusVector& v);
static bool_t inet_getbytes(XDR*, SCHAR *, unsigned);
static void inet_error(bool, rem_port*, const TEXT*, ISC_STATUS, int);
static bool_t inet_putbytes(XDR*, const SCHAR*, unsigned);
static bool inet_read(XDR*);
static rem_port* inet_try_connect( PACKET*,
Rdb*,
@ -574,17 +572,17 @@ static bool select_wait(rem_port*, Select*);
static int send_full(rem_port*, PACKET *);
static int send_partial(rem_port*, PACKET *);
static int xdrinet_create(XDR*, rem_port*, UCHAR *, USHORT, enum xdr_op);
static XDR* xdrinet_create(rem_port*, UCHAR *, USHORT, enum xdr_op);
static bool setNoNagleOption(rem_port*);
static bool setFastLoopbackOption(rem_port*, SOCKET s = INVALID_SOCKET);
static FPTR_INT tryStopMainThread = 0;
static XDR::xdr_ops inet_ops =
struct InetXdr : public XDR
{
inet_getbytes,
inet_putbytes
virtual bool_t x_getbytes(SCHAR *, unsigned); // get some bytes from "
virtual bool_t x_putbytes(const SCHAR*, unsigned); // put some bytes to "
};
@ -1459,11 +1457,11 @@ static rem_port* alloc_port(rem_port* const parent, const USHORT flags)
port->port_async_receive = inet_async_receive;
port->port_flags |= flags;
xdrinet_create(&port->port_send, port,
port->port_send = xdrinet_create(port,
&port->port_buffer[REM_SEND_OFFSET(INET_remote_buffer)],
(USHORT) INET_remote_buffer, XDR_ENCODE);
xdrinet_create(&port->port_receive, port,
port->port_receive = xdrinet_create(port,
&port->port_buffer[REM_RECV_OFFSET(INET_remote_buffer)], 0, XDR_DECODE);
if (parent && !(parent->port_server_flags & SRVR_thread_per_port))
@ -2052,11 +2050,8 @@ static rem_port* receive( rem_port* main_port, PACKET * packet)
// this level rather than try to catch them in all places where
// this routine is called
#ifdef DEV_BUILD
main_port->port_receive.x_client = !(main_port->port_flags & PORT_server);
#endif
do {
if (!xdr_protocol(&main_port->port_receive, packet))
if (!xdr_protocol(main_port->port_receive, packet))
{
packet->p_operation = main_port->port_partial_data ? op_partial : op_exit;
if (packet->p_operation == op_exit)
@ -2438,10 +2433,7 @@ static int send_full( rem_port* port, PACKET * packet)
*
**************************************/
#ifdef DEV_BUILD
port->port_send.x_client = !(port->port_flags & PORT_server);
#endif
if (!xdr_protocol(&port->port_send, packet))
if (!xdr_protocol(port->port_send, packet))
return false;
#ifdef DEBUG
@ -2457,7 +2449,7 @@ static int send_full( rem_port* port, PACKET * packet)
} // end scope
#endif
return REMOTE_deflate(&port->port_send, inet_write, packet_send, true);
return REMOTE_deflate(port->port_send, inet_write, packet_send, true);
}
static int send_partial( rem_port* port, PACKET * packet)
@ -2486,15 +2478,11 @@ static int send_partial( rem_port* port, PACKET * packet)
} // end scope
#endif
#ifdef DEV_BUILD
port->port_send.x_client = !(port->port_flags & PORT_server);
#endif
return xdr_protocol(&port->port_send, packet);
return xdr_protocol(port->port_send, packet);
}
static int xdrinet_create(XDR* xdrs, rem_port* port, UCHAR* buffer, USHORT length, enum xdr_op x_op)
XDR* xdrinet_create(rem_port* port, UCHAR* buffer, USHORT length, enum xdr_op x_op)
{
/**************************************
*
@ -2507,13 +2495,12 @@ static int xdrinet_create(XDR* xdrs, rem_port* port, UCHAR* buffer, USHORT lengt
*
**************************************/
xdrs->x_public = (caddr_t) port;
xdrs->x_base = xdrs->x_private = reinterpret_cast<SCHAR*>(buffer);
xdrs->x_handy = length;
xdrs->x_ops = (xdr_t::xdr_ops*) &inet_ops;
xdrs->x_op = x_op;
XDR* xdrs = FB_NEW InetXdr;
return true;
xdrs->x_public = port;
xdrs->create(reinterpret_cast<SCHAR*>(buffer), length, x_op);
return xdrs;
}
#ifdef HAVE_SETITIMER
@ -2594,7 +2581,7 @@ static void inet_gen_error(bool releasePort, rem_port* port, const Arg::StatusVe
}
static bool_t inet_getbytes( XDR* xdrs, SCHAR* buff, unsigned bytecount)
bool_t InetXdr::x_getbytes(SCHAR* buff, unsigned bytecount)
{
/**************************************
*
@ -2606,32 +2593,31 @@ static bool_t inet_getbytes( XDR* xdrs, SCHAR* buff, unsigned bytecount)
* Get a bunch of bytes from a memory stream if it fits.
*
**************************************/
const rem_port* port = (rem_port*) xdrs->x_public;
if (port->port_flags & PORT_server)
return REMOTE_getbytes(xdrs, buff, bytecount);
if (x_public->port_flags & PORT_server)
return REMOTE_getbytes(this, buff, bytecount);
// Use memcpy to optimize bulk transfers.
while (bytecount > sizeof(ISC_QUAD))
{
if (xdrs->x_handy >= bytecount)
if (x_handy >= bytecount)
{
memcpy(buff, xdrs->x_private, bytecount);
xdrs->x_private += bytecount;
xdrs->x_handy -= bytecount;
memcpy(buff, x_private, bytecount);
x_private += bytecount;
x_handy -= bytecount;
return TRUE;
}
if (xdrs->x_handy > 0)
if (x_handy > 0)
{
memcpy(buff, xdrs->x_private, xdrs->x_handy);
xdrs->x_private += xdrs->x_handy;
buff += xdrs->x_handy;
bytecount -= xdrs->x_handy;
xdrs->x_handy = 0;
memcpy(buff, x_private, x_handy);
x_private += x_handy;
buff += x_handy;
bytecount -= x_handy;
x_handy = 0;
}
if (!inet_read(xdrs))
if (!inet_read(this))
return FALSE;
}
@ -2641,21 +2627,21 @@ static bool_t inet_getbytes( XDR* xdrs, SCHAR* buff, unsigned bytecount)
if (!bytecount)
return TRUE;
if (xdrs->x_handy >= bytecount)
if (x_handy >= bytecount)
{
xdrs->x_handy -= bytecount;
x_handy -= bytecount;
while (bytecount--)
*buff++ = *xdrs->x_private++;
*buff++ = *x_private++;
return TRUE;
}
while (bytecount--)
{
if (xdrs->x_handy == 0 && !inet_read(xdrs))
if (x_handy == 0 && !inet_read(this))
return FALSE;
*buff++ = *xdrs->x_private++;
--xdrs->x_handy;
*buff++ = *x_private++;
--x_handy;
}
return TRUE;
@ -2724,7 +2710,7 @@ static void inet_error(bool releasePort, rem_port* port, const TEXT* function, I
}
}
static bool_t inet_putbytes( XDR* xdrs, const SCHAR* buff, unsigned bytecount)
bool_t InetXdr::x_putbytes(const SCHAR* buff, unsigned bytecount)
{
/**************************************
*
@ -2741,24 +2727,24 @@ static bool_t inet_putbytes( XDR* xdrs, const SCHAR* buff, unsigned bytecount)
while (bytecount > sizeof(ISC_QUAD))
{
if (xdrs->x_handy >= bytecount)
if (x_handy >= bytecount)
{
memcpy(xdrs->x_private, buff, bytecount);
xdrs->x_private += bytecount;
xdrs->x_handy -= bytecount;
memcpy(x_private, buff, bytecount);
x_private += bytecount;
x_handy -= bytecount;
return TRUE;
}
if (xdrs->x_handy > 0)
if (x_handy > 0)
{
memcpy(xdrs->x_private, buff, xdrs->x_handy);
xdrs->x_private += xdrs->x_handy;
buff += xdrs->x_handy;
bytecount -= xdrs->x_handy;
xdrs->x_handy = 0;
memcpy(x_private, buff, x_handy);
x_private += x_handy;
buff += x_handy;
bytecount -= x_handy;
x_handy = 0;
}
if (!REMOTE_deflate(xdrs, inet_write, packet_send, false))
if (!REMOTE_deflate(this, inet_write, packet_send, false))
{
return FALSE;
}
@ -2770,21 +2756,21 @@ static bool_t inet_putbytes( XDR* xdrs, const SCHAR* buff, unsigned bytecount)
if (!bytecount)
return TRUE;
if (xdrs->x_handy >= bytecount)
if (x_handy >= bytecount)
{
xdrs->x_handy -= bytecount;
x_handy -= bytecount;
while (bytecount--)
*xdrs->x_private++ = *buff++;
*x_private++ = *buff++;
return TRUE;
}
while (bytecount--)
{
if (xdrs->x_handy == 0 && !REMOTE_deflate(xdrs, inet_write, packet_send, false))
if (x_handy == 0 && !REMOTE_deflate(this, inet_write, packet_send, false))
return FALSE;
--xdrs->x_handy;
*xdrs->x_private++ = *buff++;
--x_handy;
*x_private++ = *buff++;
}
return TRUE;
@ -2805,7 +2791,7 @@ static bool inet_read( XDR* xdrs)
* message sent will handle this.
*
**************************************/
rem_port* port = (rem_port*) xdrs->x_public;
rem_port* port = xdrs->x_public;
char* p = xdrs->x_base;
const char* const end = p + INET_remote_buffer;
@ -2928,7 +2914,7 @@ static bool inet_write(XDR* xdrs)
**************************************/
// Encode the data portion of the packet
rem_port* port = (rem_port*) xdrs->x_public;
rem_port* port = xdrs->x_public;
const char* p = xdrs->x_base;
USHORT length = xdrs->x_private - p;

View File

@ -76,12 +76,10 @@ static rem_str* make_pipe_name(const RefPtr<const Config>&, const TEXT*, const
static rem_port* receive(rem_port*, PACKET*);
static int send_full(rem_port*, PACKET*);
static int send_partial(rem_port*, PACKET*);
static int xdrwnet_create(XDR*, rem_port*, UCHAR*, USHORT, xdr_op);
static XDR* xdrwnet_create(rem_port*, UCHAR *, USHORT, xdr_op);
static bool_t xdrwnet_endofrecord(XDR*);//, int);
static bool wnet_error(rem_port*, const TEXT*, ISC_STATUS, int);
static void wnet_gen_error(rem_port*, const Arg::StatusVector& v);
static bool_t wnet_getbytes(XDR*, SCHAR*, unsigned);
static bool_t wnet_putbytes(XDR*, const SCHAR*, unsigned);
static bool_t wnet_read(XDR*);
static bool_t wnet_write(XDR*); //, int);
#ifdef DEBUG
@ -93,10 +91,10 @@ static void wnet_make_file_name(TEXT*, DWORD);
static int cleanup_ports(const int, const int, void*);
static xdr_t::xdr_ops wnet_ops =
struct WnetXdr : public XDR
{
wnet_getbytes,
wnet_putbytes
virtual bool_t x_getbytes(SCHAR *, unsigned); // get some bytes from "
virtual bool_t x_putbytes(const SCHAR*, unsigned); // put some bytes to "
};
@ -389,7 +387,7 @@ rem_port* WNET_connect(const TEXT* name, PACKET* packet, USHORT flag, Firebird::
}
else
{
gds__log("WNET/inet_error: fork/CreateProcess errno = %d", GetLastError());
gds__log("WNET/wnet_error: fork/CreateProcess errno = %d", GetLastError());
CloseHandle(port->port_pipe);
}
@ -529,9 +527,9 @@ static rem_port* alloc_port( rem_port* parent)
port->port_event = CreateEvent(NULL, TRUE, TRUE, NULL);
xdrwnet_create(&port->port_send, port, &port->port_buffer[BUFFER_SIZE], BUFFER_SIZE, XDR_ENCODE);
port->port_send = xdrwnet_create(port, &port->port_buffer[BUFFER_SIZE], BUFFER_SIZE, XDR_ENCODE);
xdrwnet_create(&port->port_receive, port, port->port_buffer, 0, XDR_DECODE);
port->port_receive = xdrwnet_create(port, port->port_buffer, 0, XDR_DECODE);
if (parent)
{
@ -883,11 +881,7 @@ static rem_port* receive( rem_port* main_port, PACKET* packet)
*
**************************************/
#ifdef DEV_BUILD
main_port->port_receive.x_client = !(main_port->port_flags & PORT_server);
#endif
if (!xdr_protocol(&main_port->port_receive, packet))
if (!xdr_protocol(main_port->port_receive, packet))
packet->p_operation = op_exit;
return main_port;
@ -907,14 +901,10 @@ static int send_full( rem_port* port, PACKET* packet)
*
**************************************/
#ifdef DEV_BUILD
port->port_send.x_client = !(port->port_flags & PORT_server);
#endif
if (!xdr_protocol(&port->port_send, packet))
if (!xdr_protocol(port->port_send, packet))
return FALSE;
return xdrwnet_endofrecord(&port->port_send); //, TRUE);
return xdrwnet_endofrecord(port->port_send); //, TRUE);
}
@ -931,17 +921,11 @@ static int send_partial( rem_port* port, PACKET* packet)
*
**************************************/
#ifdef DEV_BUILD
port->port_send.x_client = !(port->port_flags & PORT_server);
#endif
return xdr_protocol(&port->port_send, packet);
return xdr_protocol(port->port_send, packet);
}
static int xdrwnet_create(XDR* xdrs,
rem_port* port,
UCHAR* buffer, USHORT length, xdr_op x_op)
static XDR* xdrwnet_create(rem_port* port, UCHAR* buffer, USHORT length, xdr_op x_op)
{
/**************************************
*
@ -954,13 +938,12 @@ static int xdrwnet_create(XDR* xdrs,
*
**************************************/
xdrs->x_public = (caddr_t) port;
xdrs->x_base = xdrs->x_private = reinterpret_cast<SCHAR*>(buffer);
xdrs->x_handy = length;
xdrs->x_ops = &wnet_ops;
xdrs->x_op = x_op;
XDR* xdrs = FB_NEW WnetXdr;
return TRUE;
xdrs->x_public = port;
xdrs->create(reinterpret_cast<SCHAR*>(buffer), length, x_op);
return xdrs;
}
@ -1048,7 +1031,7 @@ static void wnet_gen_error (rem_port* port, const Arg::StatusVector& v)
}
static bool_t wnet_getbytes( XDR* xdrs, SCHAR* buff, unsigned bytecount)
bool_t WnetXdr::x_getbytes(SCHAR* buff, unsigned bytecount)
{
/**************************************
*
@ -1064,22 +1047,22 @@ static bool_t wnet_getbytes( XDR* xdrs, SCHAR* buff, unsigned bytecount)
while (bytecount > (SLONG) sizeof(ISC_QUAD))
{
if (xdrs->x_handy >= bytecount)
if (x_handy >= bytecount)
{
memcpy(buff, xdrs->x_private, bytecount);
xdrs->x_private += bytecount;
xdrs->x_handy -= bytecount;
memcpy(buff, x_private, bytecount);
x_private += bytecount;
x_handy -= bytecount;
return TRUE;
}
if (xdrs->x_handy > 0)
if (x_handy > 0)
{
memcpy(buff, xdrs->x_private, xdrs->x_handy);
xdrs->x_private += xdrs->x_handy;
buff += xdrs->x_handy;
bytecount -= xdrs->x_handy;
xdrs->x_handy = 0;
memcpy(buff, x_private, x_handy);
x_private += x_handy;
buff += x_handy;
bytecount -= x_handy;
x_handy = 0;
}
if (!wnet_read(xdrs))
if (!wnet_read(this))
return FALSE;
}
@ -1089,28 +1072,28 @@ static bool_t wnet_getbytes( XDR* xdrs, SCHAR* buff, unsigned bytecount)
if (!bytecount)
return TRUE;
if (xdrs->x_handy >= bytecount)
if (x_handy >= bytecount)
{
xdrs->x_handy -= bytecount;
x_handy -= bytecount;
do {
*buff++ = *xdrs->x_private++;
*buff++ = *x_private++;
} while (--bytecount);
return TRUE;
}
while (bytecount--)
{
if (xdrs->x_handy == 0 && !wnet_read(xdrs))
if (x_handy == 0 && !wnet_read(this))
return FALSE;
*buff++ = *xdrs->x_private++;
--xdrs->x_handy;
*buff++ = *x_private++;
--x_handy;
}
return TRUE;
}
static bool_t wnet_putbytes( XDR* xdrs, const SCHAR* buff, unsigned count)
bool_t WnetXdr::x_putbytes(const SCHAR* buff, unsigned count)
{
/**************************************
*
@ -1128,22 +1111,22 @@ static bool_t wnet_putbytes( XDR* xdrs, const SCHAR* buff, unsigned count)
while (bytecount > (SLONG) sizeof(ISC_QUAD))
{
if (xdrs->x_handy >= bytecount)
if (x_handy >= bytecount)
{
memcpy(xdrs->x_private, buff, bytecount);
xdrs->x_private += bytecount;
xdrs->x_handy -= bytecount;
memcpy(x_private, buff, bytecount);
x_private += bytecount;
x_handy -= bytecount;
return TRUE;
}
if (xdrs->x_handy > 0)
if (x_handy > 0)
{
memcpy(xdrs->x_private, buff, xdrs->x_handy);
xdrs->x_private += xdrs->x_handy;
buff += xdrs->x_handy;
bytecount -= xdrs->x_handy;
xdrs->x_handy = 0;
memcpy(x_private, buff, x_handy);
x_private += x_handy;
buff += x_handy;
bytecount -= x_handy;
x_handy = 0;
}
if (!wnet_write(xdrs /*, 0*/))
if (!wnet_write(this /*, 0*/))
return FALSE;
}
@ -1153,21 +1136,21 @@ static bool_t wnet_putbytes( XDR* xdrs, const SCHAR* buff, unsigned count)
if (!bytecount)
return TRUE;
if (xdrs->x_handy >= bytecount)
if (x_handy >= bytecount)
{
xdrs->x_handy -= bytecount;
x_handy -= bytecount;
do {
*xdrs->x_private++ = *buff++;
*x_private++ = *buff++;
} while (--bytecount);
return TRUE;
}
while (bytecount--)
{
if (xdrs->x_handy == 0 && !wnet_write(xdrs /*, 0*/))
if (x_handy == 0 && !wnet_write(this /*, 0*/))
return FALSE;
--xdrs->x_handy;
*xdrs->x_private++ = *buff++;
--x_handy;
*x_private++ = *buff++;
}
return TRUE;
@ -1189,7 +1172,7 @@ static bool_t wnet_read( XDR* xdrs)
* message sent will handle this.
*
**************************************/
rem_port* port = (rem_port*) xdrs->x_public;
rem_port* port = xdrs->x_public;
SCHAR* p = xdrs->x_base;
const SCHAR* const end = p + BUFFER_SIZE;
@ -1242,7 +1225,7 @@ static bool_t wnet_write( XDR* xdrs /*, bool_t end_flag*/)
**************************************/
// Encode the data portion of the packet
rem_port* vport = (rem_port*) xdrs->x_public;
rem_port* vport = xdrs->x_public;
const SCHAR* p = xdrs->x_base;
SSHORT length = xdrs->x_private - p;

View File

@ -68,17 +68,15 @@ static rem_port* receive(rem_port*, PACKET*);
static int send_full(rem_port*, PACKET*);
static int send_partial(rem_port*, PACKET*);
static int xdrxnet_create(XDR*, rem_port*, UCHAR*, USHORT, xdr_op);
static XDR* xdrxnet_create(rem_port*, UCHAR *, USHORT, xdr_op);
static bool_t xnet_getbytes(XDR*, SCHAR*, unsigned);
static bool_t xnet_putbytes(XDR*, const SCHAR*, unsigned);
static bool_t xnet_read(XDR* xdrs);
static bool_t xnet_write(XDR* xdrs);
static xdr_t::xdr_ops xnet_ops =
struct XnetXdr : public XDR
{
xnet_getbytes,
xnet_putbytes
virtual bool_t x_getbytes(SCHAR *, unsigned); // get some bytes from "
virtual bool_t x_putbytes(const SCHAR*, unsigned); // put some bytes to "
};
static DWORD current_process_id;
@ -700,8 +698,8 @@ static rem_port* alloc_port(rem_port* parent,
port->port_request = aux_request;
port->port_buff_size = send_length;
xdrxnet_create(&port->port_send, port, send_buffer, send_length, XDR_ENCODE);
xdrxnet_create(&port->port_receive, port, receive_buffer, 0, XDR_DECODE);
port->port_send = xdrxnet_create(port, send_buffer, send_length, XDR_ENCODE);
port->port_receive = xdrxnet_create(port, receive_buffer, 0, XDR_DECODE);
if (parent)
{
@ -1589,13 +1587,9 @@ static rem_port* receive( rem_port* main_port, PACKET* packet)
*
**************************************/
#ifdef DEV_BUILD
main_port->port_receive.x_client = !(main_port->port_flags & PORT_server);
#endif
try
{
if (!xdr_protocol(&main_port->port_receive, packet))
if (!xdr_protocol(main_port->port_receive, packet))
packet->p_operation = op_exit;
}
catch (const Exception&)
@ -1621,14 +1615,10 @@ static int send_full( rem_port* port, PACKET* packet)
*
**************************************/
#ifdef DEV_BUILD
port->port_send.x_client = !(port->port_flags & PORT_server);
#endif
if (!xdr_protocol(&port->port_send, packet))
if (!xdr_protocol(port->port_send, packet))
return FALSE;
if (xnet_write(&port->port_send))
if (xnet_write(port->port_send))
return TRUE;
xnet_error(port, isc_net_write_err, ERRNO);
@ -1649,11 +1639,7 @@ static int send_partial( rem_port* port, PACKET* packet)
*
**************************************/
#ifdef DEV_BUILD
port->port_send.x_client = !(port->port_flags & PORT_server);
#endif
return xdr_protocol(&port->port_send, packet);
return xdr_protocol(port->port_send, packet);
}
void XnetClientEndPoint::server_shutdown(rem_port* port)
@ -1698,7 +1684,7 @@ void XnetClientEndPoint::server_shutdown(rem_port* port)
}
static int xdrxnet_create(XDR* xdrs, rem_port* port, UCHAR* buffer, USHORT length, xdr_op x_op)
static XDR* xdrxnet_create(rem_port* port, UCHAR* buffer, USHORT length, xdr_op x_op)
{
/**************************************
*
@ -1711,15 +1697,12 @@ static int xdrxnet_create(XDR* xdrs, rem_port* port, UCHAR* buffer, USHORT lengt
*
**************************************/
xdrs->x_public = (caddr_t) port;
xdrs->x_private = reinterpret_cast<SCHAR*>(buffer);
xdrs->x_base = xdrs->x_private;
xdrs->x_handy = length;
xdrs->x_ops = &xnet_ops;
xdrs->x_op = x_op;
xdrs->x_local = true;
XDR* xdrs = FB_NEW XnetXdr;
return TRUE;
xdrs->x_public = port;
xdrs->create(reinterpret_cast<SCHAR*>(buffer), length, x_op);
return xdrs;
}
@ -1772,7 +1755,7 @@ static void xnet_error(rem_port* port, ISC_STATUS operation, int status)
}
static bool_t xnet_getbytes(XDR* xdrs, SCHAR* buff, unsigned bytecount)
bool_t XnetXdr::x_getbytes(SCHAR* buff, unsigned bytecount)
{
/**************************************
*
@ -1784,7 +1767,7 @@ static bool_t xnet_getbytes(XDR* xdrs, SCHAR* buff, unsigned bytecount)
* Fetch a bunch of bytes from remote interface.
*
**************************************/
rem_port* port = (rem_port*) xdrs->x_public;
rem_port* port = x_public;
const bool portServer = (port->port_flags & PORT_server);
XCC xcc = port->port_xcc;
XPM xpm = xcc->xcc_xpm;
@ -1802,24 +1785,24 @@ static bool_t xnet_getbytes(XDR* xdrs, SCHAR* buff, unsigned bytecount)
}
SLONG to_copy;
if (xdrs->x_handy >= bytecount)
if (x_handy >= bytecount)
to_copy = bytecount;
else
to_copy = xdrs->x_handy;
to_copy = x_handy;
if (xdrs->x_handy)
if (x_handy)
{
if (to_copy == sizeof(SLONG))
*((SLONG*)buff) = *((SLONG*)xdrs->x_private);
*((SLONG*)buff) = *((SLONG*)x_private);
else
memcpy(buff, xdrs->x_private, to_copy);
memcpy(buff, x_private, to_copy);
xdrs->x_handy -= to_copy;
xdrs->x_private += to_copy;
x_handy -= to_copy;
x_private += to_copy;
}
else
{
if (!xnet_read(xdrs))
if (!xnet_read(this))
return FALSE;
}
@ -1834,7 +1817,7 @@ static bool_t xnet_getbytes(XDR* xdrs, SCHAR* buff, unsigned bytecount)
}
static bool_t xnet_putbytes(XDR* xdrs, const SCHAR* buff, unsigned bytecount)
bool_t XnetXdr::x_putbytes(const SCHAR* buff, unsigned bytecount)
{
/**************************************
*
@ -1846,7 +1829,7 @@ static bool_t xnet_putbytes(XDR* xdrs, const SCHAR* buff, unsigned bytecount)
* Put a bunch of bytes into a memory stream.
*
**************************************/
rem_port* port = (rem_port*)xdrs->x_public;
rem_port* port = x_public;
const bool portServer = (port->port_flags & PORT_server);
XCC xcc = port->port_xcc;
XCH xch = xcc->xcc_send_channel;
@ -1866,14 +1849,14 @@ static bool_t xnet_putbytes(XDR* xdrs, const SCHAR* buff, unsigned bytecount)
}
SLONG to_copy;
if (xdrs->x_handy >= bytecount)
if (x_handy >= bytecount)
to_copy = bytecount;
else
to_copy = xdrs->x_handy;
to_copy = x_handy;
if (xdrs->x_handy)
if (x_handy)
{
if (xdrs->x_handy == xch->xch_size)
if (x_handy == xch->xch_size)
{
while (!xnet_shutdown)
{
@ -1921,16 +1904,16 @@ static bool_t xnet_putbytes(XDR* xdrs, const SCHAR* buff, unsigned bytecount)
}
if (to_copy == sizeof(SLONG))
*((SLONG*)xdrs->x_private) = *((SLONG*)buff);
*((SLONG*)x_private) = *((SLONG*)buff);
else
memcpy(xdrs->x_private, buff, to_copy);
memcpy(x_private, buff, to_copy);
xdrs->x_handy -= to_copy;
xdrs->x_private += to_copy;
x_handy -= to_copy;
x_private += to_copy;
}
else
{
if (!xnet_write(xdrs))
if (!xnet_write(this))
{
xnet_error(port, isc_net_write_err, ERRNO);
return FALSE;
@ -1960,7 +1943,7 @@ static bool_t xnet_read(XDR* xdrs)
* Read a buffer full of data.
*
**************************************/
rem_port* port = (rem_port*) xdrs->x_public;
rem_port* port = xdrs->x_public;
const bool portServer = (port->port_flags & PORT_server);
XCC xcc = port->port_xcc;
XCH xch = xcc->xcc_recv_channel;
@ -2048,7 +2031,7 @@ static bool_t xnet_write(XDR* xdrs)
* filled and ready for reading.
*
**************************************/
rem_port* port = (rem_port*) xdrs->x_public;
rem_port* port = xdrs->x_public;
XCC xcc = port->port_xcc;
XCH xch = xcc->xcc_send_channel;

View File

@ -98,6 +98,8 @@ static bool alloc_cstring(XDR*, CSTRING*);
static void free_cstring(XDR*, CSTRING*);
static void reset_statement(XDR*, SSHORT);
static bool_t xdr_cstring(XDR*, CSTRING*);
static bool_t xdr_response(XDR*, CSTRING*);
static bool_t xdr_cstring_with_limit(XDR*, CSTRING*, ULONG);
static inline bool_t xdr_cstring_const(XDR*, CSTRING_CONST*);
#ifdef DEBUG_XDR_MEMORY
static bool_t xdr_debug_packet(XDR*, enum xdr_op, PACKET*);
@ -113,8 +115,6 @@ static bool_t xdr_sql_message(XDR*, SLONG);
static bool_t xdr_trrq_blr(XDR*, CSTRING*);
static bool_t xdr_trrq_message(XDR*, USHORT);
#include "../common/xdr_proto.h"
inline void fixupLength(const XDR* xdrs, ULONG& length)
{
// If the short (16-bit) value >= 32KB is being transmitted,
@ -181,7 +181,7 @@ void xdr_debug_memory(XDR* xdrs,
* status vector.
*
**************************************/
rem_port* port = (rem_port*) xdrs->x_public;
rem_port* port = xdrs->x_public;
fb_assert(port != 0);
fb_assert(port->port_header.blk_type == type_port);
@ -417,7 +417,7 @@ bool_t xdr_protocol(XDR* xdrs, PACKET* p)
response = &p->p_resp;
MAP(xdr_short, reinterpret_cast<SSHORT&>(response->p_resp_object));
MAP(xdr_quad, response->p_resp_blob_id);
MAP(xdr_cstring, response->p_resp_data);
MAP(xdr_response, response->p_resp_data);
return xdr_status_vector(xdrs, response->p_resp_status_vector) ?
P_TRUE(xdrs, p) : P_FALSE(xdrs, p);
@ -797,7 +797,7 @@ bool_t xdr_protocol(XDR* xdrs, PACKET* p)
P_CRYPT_CALLBACK* cc = &p->p_cc;
MAP(xdr_cstring, cc->p_cc_data);
rem_port* port = (rem_port*) xdrs->x_public;
rem_port* port = xdrs->x_public;
// If the protocol is 0 we are in the process of establishing a connection.
// crypt_key_callback at this phaze means server protocol is at least P15
if (port->port_protocol >= PROTOCOL_VERSION14 || port->port_protocol == 0)
@ -949,6 +949,13 @@ static void free_cstring( XDR* xdrs, CSTRING* cstring)
}
static bool xdr_is_client(XDR* xdrs)
{
const rem_port* port = xdrs->x_public;
return !(port->port_flags & PORT_server);
}
// CVC: This function is a little stub to validate that indeed, bpb's aren't
// overwritten by accident. Even though xdr_string writes to cstr_address,
// an action we wanted to block, it first allocates a new buffer.
@ -961,19 +968,39 @@ static void free_cstring( XDR* xdrs, CSTRING* cstring)
// The same function is being used to check P_SGMT & P_DDL.
static inline bool_t xdr_cstring_const(XDR* xdrs, CSTRING_CONST* cstring)
{
#ifdef DEV_BUILD
if (xdrs->x_client)
if (xdr_is_client(xdrs) && xdrs->x_op == XDR_DECODE)
{
const bool cond =
!(xdrs->x_op == XDR_DECODE &&
cstring->cstr_length <= cstring->cstr_allocated && cstring->cstr_allocated);
fb_assert(cond);
fb_assert(!(cstring->cstr_length <= cstring->cstr_allocated && cstring->cstr_allocated));
if (!cstring->cstr_allocated)
{
// Normally we should not decode into such CSTRING_CONST at client side
// May be op, normally never sent to client, was received
cstring->cstr_address = NULL;
cstring->cstr_length = 0;
}
}
#endif
return xdr_cstring(xdrs, reinterpret_cast<CSTRING*>(cstring));
}
static inline bool_t xdr_response(XDR* xdrs, CSTRING* cstring)
{
if (xdr_is_client(xdrs) && xdrs->x_op == XDR_DECODE && cstring->cstr_allocated)
{
ULONG limit = cstring->cstr_allocated;
cstring->cstr_allocated = 0;
return xdr_cstring_with_limit(xdrs, cstring, limit);
}
return xdr_cstring(xdrs, cstring);
}
static bool_t xdr_cstring( XDR* xdrs, CSTRING* cstring)
{
return xdr_cstring_with_limit(xdrs, cstring, 0);
}
static bool_t xdr_cstring_with_limit( XDR* xdrs, CSTRING* cstring, ULONG limit)
{
/**************************************
*
@ -1001,29 +1028,25 @@ static bool_t xdr_cstring( XDR* xdrs, CSTRING* cstring)
{
case XDR_ENCODE:
if (cstring->cstr_length &&
!(*xdrs->x_ops->x_putbytes) (xdrs,
reinterpret_cast<const SCHAR*>(cstring->cstr_address),
cstring->cstr_length))
!xdrs->x_putbytes(reinterpret_cast<const SCHAR*>(cstring->cstr_address), cstring->cstr_length))
{
return FALSE;
}
l = (4 - cstring->cstr_length) & 3;
if (l)
return (*xdrs->x_ops->x_putbytes) (xdrs, filler, l);
return xdrs->x_putbytes(filler, l);
return TRUE;
case XDR_DECODE:
if (limit && cstring->cstr_length > limit)
return FALSE;
if (!alloc_cstring(xdrs, cstring))
return FALSE;
if (!(*xdrs->x_ops->x_getbytes)(xdrs,
reinterpret_cast<SCHAR*>(cstring->cstr_address),
cstring->cstr_length))
{
if (!xdrs->x_getbytes(reinterpret_cast<SCHAR*>(cstring->cstr_address), cstring->cstr_length))
return FALSE;
}
l = (4 - cstring->cstr_length) & 3;
if (l)
return (*xdrs->x_ops->x_getbytes) (xdrs, trash, l);
return xdrs->x_getbytes(trash, l);
return TRUE;
case XDR_FREE:
@ -1049,7 +1072,7 @@ static bool_t xdr_debug_packet( XDR* xdrs, enum xdr_op xop, PACKET* packet)
* entering/removing from a port's packet tracking vector.
*
**************************************/
rem_port* port = (rem_port*) xdrs->x_public;
rem_port* port = xdrs->x_public;
fb_assert(port != 0);
fb_assert(port->port_header.blk_type == type_port);
@ -1168,7 +1191,7 @@ static bool_t xdr_message( XDR* xdrs, RMessage* message, const rem_fmt* format)
if (xdrs->x_op == XDR_FREE)
return TRUE;
rem_port* port = (rem_port*) xdrs->x_public;
rem_port* port = xdrs->x_public;
if (!message || !format)
return FALSE;
@ -1207,7 +1230,7 @@ static bool_t xdr_packed_message( XDR* xdrs, RMessage* message, const rem_fmt* f
if (xdrs->x_op == XDR_FREE)
return TRUE;
const rem_port* const port = (rem_port*) xdrs->x_public;
const rem_port* const port = xdrs->x_public;
if (!message || !format)
return FALSE;
@ -1342,7 +1365,7 @@ static bool_t xdr_request(XDR* xdrs,
if (xdrs->x_op == XDR_FREE)
return TRUE;
rem_port* port = (rem_port*) xdrs->x_public;
rem_port* port = xdrs->x_public;
if (request_id >= port->port_objects.getCount())
return FALSE;
@ -1449,7 +1472,7 @@ static bool_t xdr_slice(XDR* xdrs, lstring* slice, /*USHORT sdl_length,*/ const
}
const dsc* desc = &info.sdl_info_element;
const rem_port* port = (rem_port*) xdrs->x_public;
const rem_port* port = xdrs->x_public;
BLOB_PTR* p = (BLOB_PTR*) slice->lstr_address;
ULONG n;
@ -1502,7 +1525,7 @@ static bool_t xdr_sql_blr(XDR* xdrs,
if (xdrs->x_op == XDR_FREE)
return TRUE;
rem_port* port = (rem_port*) xdrs->x_public;
rem_port* port = xdrs->x_public;
Rsr* statement;
@ -1603,7 +1626,7 @@ static bool_t xdr_sql_message( XDR* xdrs, SLONG statement_id)
if (xdrs->x_op == XDR_FREE)
return TRUE;
rem_port* port = (rem_port*) xdrs->x_public;
rem_port* port = xdrs->x_public;
if (statement_id >= 0)
{
@ -1767,7 +1790,7 @@ static bool_t xdr_trrq_blr(XDR* xdrs, CSTRING* blr)
if (xdrs->x_op == XDR_FREE || xdrs->x_op == XDR_ENCODE)
return TRUE;
rem_port* port = (rem_port*) xdrs->x_public;
rem_port* port = xdrs->x_public;
Rpr* procedure = port->port_rpr;
if (!procedure)
procedure = port->port_rpr = FB_NEW Rpr;
@ -1831,7 +1854,7 @@ static bool_t xdr_trrq_message( XDR* xdrs, USHORT msg_type)
if (xdrs->x_op == XDR_FREE)
return TRUE;
rem_port* port = (rem_port*) xdrs->x_public;
rem_port* port = xdrs->x_public;
Rpr* procedure = port->port_rpr;
if (msg_type == 1)
@ -1855,7 +1878,7 @@ static void reset_statement( XDR* xdrs, SSHORT statement_id)
**************************************/
Rsr* statement = NULL;
rem_port* port = (rem_port*) xdrs->x_public;
rem_port* port = xdrs->x_public;
// if the statement ID is -1, this seems to indicate that we are
// re-executing the previous statement. This is not a

View File

@ -28,8 +28,8 @@
#include "../common/config/config.h"
#include "../common/classes/RefCounted.h"
#include "../common/security.h"
#include "../common/xdr.h"
#include "../remote/protocol.h"
#include "../common/xdr_proto.h"
namespace Firebird
{
@ -42,6 +42,16 @@ namespace Remote
}
struct rem_port;
struct RemoteXdr : public xdr_t
{
RemoteXdr()
: x_public(NULL)
{ }
rem_port* x_public;
};
typedef struct RemoteXdr XDR;
struct rem_fmt;
struct Rdb;
typedef bool PacketReceive(rem_port*, UCHAR*, SSHORT, SSHORT*);

View File

@ -30,7 +30,6 @@
#include "../common/gdsassert.h"
#include "../remote/proto_proto.h"
#include "../remote/remot_proto.h"
#include "../common/xdr_proto.h"
#include "../yvalve/gds_proto.h"
#include "../common/config/config.h"
#include "../common/classes/init.h"
@ -324,12 +323,9 @@ void REMOTE_free_packet( rem_port* port, PACKET * packet, bool partial)
if (packet)
{
xdrmem_create(&xdr, reinterpret_cast<char*>(packet), sizeof(PACKET), XDR_FREE);
xdr.x_public = (caddr_t) port;
xdr.create(reinterpret_cast<char*>(packet), sizeof(PACKET), XDR_FREE);
xdr.x_public = port;
xdr.x_local = (port->port_type == rem_port::XNET);
#ifdef DEV_BUILD
xdr.x_client = false;
#endif
if (partial) {
xdr_protocol(&xdr, packet);
@ -743,7 +739,7 @@ bool_t REMOTE_getbytes (XDR* xdrs, SCHAR* buff, unsigned bytecount)
xdrs->x_handy = 0;
}
rem_port* port = (rem_port*) xdrs->x_public;
rem_port* port = xdrs->x_public;
Firebird::RefMutexEnsureUnlock queGuard(*port->port_que_sync, FB_FUNCTION);
queGuard.enter();
if (port->port_qoffset >= port->port_queue.getCount())
@ -1143,7 +1139,7 @@ static void setCStr(CSTRING& to, const char* from)
to.cstr_allocated = 0;
}
void rem_port::addServerKeys(CSTRING* passedStr)
void rem_port::addServerKeys(const CSTRING* passedStr)
{
Firebird::ClumpletReader newKeys(Firebird::ClumpletReader::UnTagged,
passedStr->cstr_address, passedStr->cstr_length);
@ -1523,7 +1519,7 @@ bool REMOTE_inflate(rem_port* port, PacketReceive* packet_receive, UCHAR* buffer
bool REMOTE_deflate(XDR* xdrs, ProtoWrite* proto_write, PacketSend* packet_send, bool flash)
{
#ifdef WIRE_COMPRESS_SUPPORT
rem_port* port = (rem_port*) xdrs->x_public;
rem_port* port = xdrs->x_public;
if (!(port->port_compressed && (port->port_flags & PORT_compressed)))
return proto_write(xdrs);

View File

@ -611,7 +611,7 @@ inline void Rsr::releaseException()
rsr_status = NULL;
}
#include "../common/xdr.h"
#include "../remote/remot_proto.h"
// Generalized port definition.
@ -972,8 +972,8 @@ struct rem_port : public Firebird::GlobalStorage, public Firebird::RefCounted
HANDLE port_pipe; // port pipe handle
HANDLE port_event; // event associated with a port
#endif
XDR port_receive;
XDR port_send;
Firebird::AutoPtr<XDR> port_receive;
Firebird::AutoPtr<XDR> port_send;
#ifdef DEBUG_XDR_MEMORY
r e m _ v e c* port_packet_vector; // Vector of send/receive packets
#endif
@ -1148,7 +1148,7 @@ public:
void releaseObject(OBJCT id)
{
if (id != INVALID_OBJECT)
if (id != INVALID_OBJECT && id <= MAX_OBJCT_HANDLES)
{
port_objects[id].release();
}
@ -1174,7 +1174,7 @@ public:
bool haveRecvData()
{
Firebird::RefMutexGuard queGuard(*port_que_sync, FB_FUNCTION);
return ((port_receive.x_handy > 0) || (port_qoffset < port_queue.getCount()));
return ((port_receive->x_handy > 0) || (port_qoffset < port_queue.getCount()));
}
void clearRecvQue()
@ -1182,7 +1182,7 @@ public:
Firebird::RefMutexGuard queGuard(*port_que_sync, FB_FUNCTION);
port_queue.clear();
port_qoffset = 0;
port_receive.x_private = port_receive.x_base;
port_receive->x_private = port_receive->x_base;
}
class RecvQueState
@ -1194,8 +1194,8 @@ public:
RecvQueState(const rem_port* port)
{
save_handy = port->port_receive.x_handy;
save_private = port->port_receive.x_private - port->port_receive.x_base;
save_handy = port->port_receive->x_handy;
save_private = port->port_receive->x_private - port->port_receive->x_base;
save_qoffset = port->port_qoffset;
}
};
@ -1210,11 +1210,11 @@ public:
if (rs.save_qoffset > 0 && (rs.save_qoffset != port_qoffset))
{
Firebird::Array<char>& q = port_queue[rs.save_qoffset - 1];
memcpy(port_receive.x_base, q.begin(), q.getCount());
memcpy(port_receive->x_base, q.begin(), q.getCount());
}
port_qoffset = rs.save_qoffset;
port_receive.x_private = port_receive.x_base + rs.save_private;
port_receive.x_handy = rs.save_handy;
port_receive->x_private = port_receive->x_base + rs.save_private;
port_receive->x_handy = rs.save_handy;
}
// TMN: The following member functions are conceptually private
@ -1262,7 +1262,7 @@ public:
Firebird::string getRemoteId() const;
void auxAcceptError(PACKET* packet);
void addServerKeys(CSTRING* str);
void addServerKeys(const CSTRING* str);
bool tryNewKey(InternalCryptKey* cryptKey);
void checkResponse(Firebird::IStatus* warning, PACKET* packet, bool checkKeys = false);

View File

@ -44,7 +44,6 @@
#include "../remote/parse_proto.h"
#include "../remote/remot_proto.h"
#include "../remote/server/serve_proto.h"
#include "../common/xdr_proto.h"
#ifdef WIN_NT
#include "../../remote/server/os/win32/cntl_proto.h"
#include <stdlib.h>
@ -6187,7 +6186,7 @@ SSHORT rem_port::asyncReceive(PACKET* asyncPacket, const UCHAR* buffer, SSHORT d
return 0;
}
SLONG original_op = xdr_peek_long(&port_async_receive->port_receive, buffer, dataSize);
SLONG original_op = xdr_peek_long(port_async_receive->port_receive, buffer, dataSize);
switch (original_op)
{
case op_cancel:
@ -6203,7 +6202,7 @@ SSHORT rem_port::asyncReceive(PACKET* asyncPacket, const UCHAR* buffer, SSHORT d
MutexLockGuard guard(mutex, FB_FUNCTION);
port_async_receive->clearRecvQue();
port_async_receive->port_receive.x_handy = 0;
port_async_receive->port_receive->x_handy = 0;
port_async_receive->port_protocol = port_protocol;
memcpy(port_async_receive->port_queue.add().getBuffer(dataSize), buffer, dataSize);
@ -6212,7 +6211,7 @@ SSHORT rem_port::asyncReceive(PACKET* asyncPacket, const UCHAR* buffer, SSHORT d
port_async_receive->receive(asyncPacket);
}
const SSHORT asyncSize = dataSize - port_async_receive->port_receive.x_handy;
const SSHORT asyncSize = dataSize - port_async_receive->port_receive->x_handy;
fb_assert(asyncSize >= 0);
switch (asyncPacket->p_operation)