Add macro to check remaining length of STREAM
Avoids poking around in the internals, and also makes the code easier to read.
This commit is contained in:
parent
3e340f2f20
commit
6268b44f06
@ -93,7 +93,7 @@ channel_send(STREAM s, VCHANNEL * channel)
|
|||||||
|
|
||||||
/* first fragment sent in-place */
|
/* first fragment sent in-place */
|
||||||
s_pop_layer(s, channel_hdr);
|
s_pop_layer(s, channel_hdr);
|
||||||
length = s->end - s->p - 8;
|
length = s_remaining(s) - 8;
|
||||||
|
|
||||||
logger(Protocol, Debug, "channel_send(), channel = %d, length = %d", channel->mcs_id,
|
logger(Protocol, Debug, "channel_send(), channel = %d, length = %d", channel->mcs_id,
|
||||||
length);
|
length);
|
||||||
@ -186,7 +186,7 @@ channel_process(STREAM s, uint16 mcs_channel)
|
|||||||
in->p = in->data;
|
in->p = in->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
thislength = MIN(s->end - s->p, in->data + in->size - in->p);
|
thislength = MIN(s_remaining(s), in->data + in->size - in->p);
|
||||||
memcpy(in->p, s->p, thislength);
|
memcpy(in->p, s->p, thislength);
|
||||||
in->p += thislength;
|
in->p += thislength;
|
||||||
|
|
||||||
|
2
iso.c
2
iso.c
@ -177,7 +177,7 @@ iso_send(STREAM s)
|
|||||||
uint16 length;
|
uint16 length;
|
||||||
|
|
||||||
s_pop_layer(s, iso_hdr);
|
s_pop_layer(s, iso_hdr);
|
||||||
length = s->end - s->p;
|
length = s_remaining(s);
|
||||||
|
|
||||||
out_uint8(s, T123_HEADER_VERSION); /* version */
|
out_uint8(s, T123_HEADER_VERSION); /* version */
|
||||||
out_uint8(s, 0); /* reserved */
|
out_uint8(s, 0); /* reserved */
|
||||||
|
2
lspci.c
2
lspci.c
@ -136,7 +136,7 @@ lspci_process(STREAM s)
|
|||||||
static char *rest = NULL;
|
static char *rest = NULL;
|
||||||
char *buf;
|
char *buf;
|
||||||
|
|
||||||
pkglen = s->end - s->p;
|
pkglen = s_remaining(s);
|
||||||
/* str_handle_lines requires null terminated strings */
|
/* str_handle_lines requires null terminated strings */
|
||||||
buf = xmalloc(pkglen + 1);
|
buf = xmalloc(pkglen + 1);
|
||||||
STRNCPY(buf, (char *) s->p, pkglen + 1);
|
STRNCPY(buf, (char *) s->p, pkglen + 1);
|
||||||
|
2
mcs.c
2
mcs.c
@ -306,7 +306,7 @@ mcs_send_to_channel(STREAM s, uint16 channel)
|
|||||||
uint16 length;
|
uint16 length;
|
||||||
|
|
||||||
s_pop_layer(s, mcs_hdr);
|
s_pop_layer(s, mcs_hdr);
|
||||||
length = s->end - s->p - 8;
|
length = s_remaining(s) - 8;
|
||||||
length |= 0x8000;
|
length |= 0x8000;
|
||||||
|
|
||||||
out_uint8(s, (MCS_SDRQ << 2));
|
out_uint8(s, (MCS_SDRQ << 2));
|
||||||
|
2
rdp.c
2
rdp.c
@ -194,7 +194,7 @@ rdp_send_data(STREAM s, uint8 data_pdu_type)
|
|||||||
uint16 length;
|
uint16 length;
|
||||||
|
|
||||||
s_pop_layer(s, rdp_hdr);
|
s_pop_layer(s, rdp_hdr);
|
||||||
length = s->end - s->p;
|
length = s_remaining(s);
|
||||||
|
|
||||||
out_uint16_le(s, length);
|
out_uint16_le(s, length);
|
||||||
out_uint16_le(s, (RDP_PDU_DATA | 0x10));
|
out_uint16_le(s, (RDP_PDU_DATA | 0x10));
|
||||||
|
2
rdpdr.c
2
rdpdr.c
@ -879,7 +879,7 @@ rdpdr_process(STREAM s)
|
|||||||
uint16 pakid;
|
uint16 pakid;
|
||||||
|
|
||||||
logger(Protocol, Debug, "rdpdr_process()");
|
logger(Protocol, Debug, "rdpdr_process()");
|
||||||
/* hexdump(s->p, s->end - s->p); */
|
/* hexdump(s->p, s_remaining(s)); */
|
||||||
|
|
||||||
in_uint16(s, component); /* RDPDR_HEADER.Component */
|
in_uint16(s, component); /* RDPDR_HEADER.Component */
|
||||||
in_uint16(s, pakid); /* RDPDR_HEADER.PacketId */
|
in_uint16(s, pakid); /* RDPDR_HEADER.PacketId */
|
||||||
|
8
rdpsnd.c
8
rdpsnd.c
@ -343,7 +343,7 @@ rdpsnd_process_packet(uint8 opcode, STREAM s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
rdpsnd_queue_write(rdpsnd_dsp_process
|
rdpsnd_queue_write(rdpsnd_dsp_process
|
||||||
(s->p, s->end - s->p, current_driver,
|
(s->p, s_remaining(s), current_driver,
|
||||||
&formats[current_format]), tick, packet_index);
|
&formats[current_format]), tick, packet_index);
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
@ -386,7 +386,7 @@ rdpsnd_process(STREAM s)
|
|||||||
/* New packet */
|
/* New packet */
|
||||||
if (packet.size == 0)
|
if (packet.size == 0)
|
||||||
{
|
{
|
||||||
if ((s->end - s->p) < 4)
|
if (!s_check_rem(s, 4))
|
||||||
{
|
{
|
||||||
logger(Sound, Error,
|
logger(Sound, Error,
|
||||||
"rdpsnd_process(), split at packet header, things will go south from here...");
|
"rdpsnd_process(), split at packet header, things will go south from here...");
|
||||||
@ -405,7 +405,7 @@ rdpsnd_process(STREAM s)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
len = MIN(s->end - s->p, packet.end - packet.p);
|
len = MIN(s_remaining(s), s_remaining(&packet));
|
||||||
|
|
||||||
/* Microsoft's server is so broken it's not even funny... */
|
/* Microsoft's server is so broken it's not even funny... */
|
||||||
if (packet_opcode == SNDC_WAVE)
|
if (packet_opcode == SNDC_WAVE)
|
||||||
@ -451,7 +451,7 @@ rdpsnddbg_process(STREAM s)
|
|||||||
static char *rest = NULL;
|
static char *rest = NULL;
|
||||||
char *buf;
|
char *buf;
|
||||||
|
|
||||||
pkglen = s->end - s->p;
|
pkglen = s_remaining(s);
|
||||||
/* str_handle_lines requires null terminated strings */
|
/* str_handle_lines requires null terminated strings */
|
||||||
buf = (char *) xmalloc(pkglen + 1);
|
buf = (char *) xmalloc(pkglen + 1);
|
||||||
STRNCPY(buf, (char *) s->p, pkglen + 1);
|
STRNCPY(buf, (char *) s->p, pkglen + 1);
|
||||||
|
@ -380,7 +380,7 @@ alsa_play(void)
|
|||||||
|
|
||||||
next_tick = rdpsnd_queue_next_tick();
|
next_tick = rdpsnd_queue_next_tick();
|
||||||
|
|
||||||
len = (out->end - out->p) / (samplewidth_out * audiochannels_out);
|
len = s_remaining(out) / (samplewidth_out * audiochannels_out);
|
||||||
if ((len = snd_pcm_writei(out_handle, out->p, ((MAX_FRAMES < len) ? MAX_FRAMES : len))) < 0)
|
if ((len = snd_pcm_writei(out_handle, out->p, ((MAX_FRAMES < len) ? MAX_FRAMES : len))) < 0)
|
||||||
{
|
{
|
||||||
snd_pcm_prepare(out_handle);
|
snd_pcm_prepare(out_handle);
|
||||||
|
@ -171,7 +171,7 @@ libao_play(void)
|
|||||||
|
|
||||||
next_tick = rdpsnd_queue_next_tick();
|
next_tick = rdpsnd_queue_next_tick();
|
||||||
|
|
||||||
len = (WAVEOUTLEN > (out->end - out->p)) ? (out->end - out->p) : WAVEOUTLEN;
|
len = MIN(WAVEOUTLEN, s_remaining(out));
|
||||||
ao_play(o_device, (char *) out->p, len);
|
ao_play(o_device, (char *) out->p, len);
|
||||||
out->p += len;
|
out->p += len;
|
||||||
|
|
||||||
|
@ -412,7 +412,7 @@ oss_play(void)
|
|||||||
packet = rdpsnd_queue_current_packet();
|
packet = rdpsnd_queue_current_packet();
|
||||||
out = &packet->s;
|
out = &packet->s;
|
||||||
|
|
||||||
len = out->end - out->p;
|
len = s_remaining(out);
|
||||||
|
|
||||||
len = write(dsp_fd, out->p, (len > MAX_LEN) ? MAX_LEN : len);
|
len = write(dsp_fd, out->p, (len > MAX_LEN) ? MAX_LEN : len);
|
||||||
if (len == -1)
|
if (len == -1)
|
||||||
|
@ -1192,7 +1192,7 @@ pulse_play(void)
|
|||||||
playback_seek = PA_SEEK_RELATIVE;
|
playback_seek = PA_SEEK_RELATIVE;
|
||||||
|
|
||||||
avail_space = pa_stream_writable_size(playback_stream);
|
avail_space = pa_stream_writable_size(playback_stream);
|
||||||
audio_size = out->end - out->p <= avail_space ? out->end - out->p : avail_space;
|
audio_size = MIN(s_remaining(out), avail_space);
|
||||||
if (audio_size)
|
if (audio_size)
|
||||||
{
|
{
|
||||||
if (pa_stream_write
|
if (pa_stream_write
|
||||||
|
@ -256,7 +256,7 @@ sgi_play(void)
|
|||||||
packet = rdpsnd_queue_current_packet();
|
packet = rdpsnd_queue_current_packet();
|
||||||
out = (STREAM) (void *) &(packet->s);
|
out = (STREAM) (void *) &(packet->s);
|
||||||
|
|
||||||
len = out->end - out->p;
|
len = s_remaining(out);
|
||||||
|
|
||||||
alWriteFrames(output_port, out->p, len / combinedFrameSize);
|
alWriteFrames(output_port, out->p, len / combinedFrameSize);
|
||||||
|
|
||||||
|
@ -419,7 +419,7 @@ sun_play(void)
|
|||||||
packet = rdpsnd_queue_current_packet();
|
packet = rdpsnd_queue_current_packet();
|
||||||
out = &packet->s;
|
out = &packet->s;
|
||||||
|
|
||||||
len = out->end - out->p;
|
len = s_remaining(out);
|
||||||
|
|
||||||
len = write(dsp_fd, out->p, (len > MAX_LEN) ? MAX_LEN : len);
|
len = write(dsp_fd, out->p, (len > MAX_LEN) ? MAX_LEN : len);
|
||||||
if (len == -1)
|
if (len == -1)
|
||||||
|
@ -377,7 +377,7 @@ seamless_process(STREAM s)
|
|||||||
unsigned int pkglen;
|
unsigned int pkglen;
|
||||||
char *buf;
|
char *buf;
|
||||||
|
|
||||||
pkglen = s->end - s->p;
|
pkglen = s_remaining(s);
|
||||||
/* str_handle_lines requires null terminated strings */
|
/* str_handle_lines requires null terminated strings */
|
||||||
buf = xmalloc(pkglen + 1);
|
buf = xmalloc(pkglen + 1);
|
||||||
STRNCPY(buf, (char *) s->p, pkglen + 1);
|
STRNCPY(buf, (char *) s->p, pkglen + 1);
|
||||||
|
8
secure.c
8
secure.c
@ -352,7 +352,7 @@ sec_send_to_channel(STREAM s, uint32 flags, uint16 channel)
|
|||||||
if (flags & SEC_ENCRYPT)
|
if (flags & SEC_ENCRYPT)
|
||||||
{
|
{
|
||||||
flags &= ~SEC_ENCRYPT;
|
flags &= ~SEC_ENCRYPT;
|
||||||
datalen = s->end - s->p - 8;
|
datalen = s_remaining(s) - 8;
|
||||||
sec_sign(s->p, 8, g_sec_sign_key, g_rc4_key_len, s->p + 8, datalen);
|
sec_sign(s->p, 8, g_sec_sign_key, g_rc4_key_len, s->p + 8, datalen);
|
||||||
sec_encrypt(s->p + 8, datalen);
|
sec_encrypt(s->p + 8, datalen);
|
||||||
}
|
}
|
||||||
@ -885,7 +885,7 @@ sec_recv(RD_BOOL * is_fastpath)
|
|||||||
}
|
}
|
||||||
|
|
||||||
in_uint8s(s, 8); /* signature */
|
in_uint8s(s, 8); /* signature */
|
||||||
sec_decrypt(s->p, s->end - s->p);
|
sec_decrypt(s->p, s_remaining(s));
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
@ -905,7 +905,7 @@ sec_recv(RD_BOOL * is_fastpath)
|
|||||||
}
|
}
|
||||||
|
|
||||||
in_uint8s(s, 8); /* signature */
|
in_uint8s(s, 8); /* signature */
|
||||||
sec_decrypt(s->p, s->end - s->p);
|
sec_decrypt(s->p, s_remaining(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sec_flags & SEC_LICENSE_PKT)
|
if (sec_flags & SEC_LICENSE_PKT)
|
||||||
@ -923,7 +923,7 @@ sec_recv(RD_BOOL * is_fastpath)
|
|||||||
}
|
}
|
||||||
|
|
||||||
in_uint8s(s, 8); /* signature */
|
in_uint8s(s, 8); /* signature */
|
||||||
sec_decrypt(s->p, s->end - s->p);
|
sec_decrypt(s->p, s_remaining(s));
|
||||||
|
|
||||||
/* Check for a redirect packet, starts with 00 04 */
|
/* Check for a redirect packet, starts with 00 04 */
|
||||||
if (s->p[0] == 0 && s->p[1] == 4)
|
if (s->p[0] == 0 && s->p[1] == 4)
|
||||||
|
4
stream.h
4
stream.h
@ -60,7 +60,9 @@ size_t in_ansi_string(STREAM s, char *string, size_t len);
|
|||||||
#define s_push_layer(s,h,n) { (s)->h = (s)->p; (s)->p += n; }
|
#define s_push_layer(s,h,n) { (s)->h = (s)->p; (s)->p += n; }
|
||||||
#define s_pop_layer(s,h) (s)->p = (s)->h;
|
#define s_pop_layer(s,h) (s)->p = (s)->h;
|
||||||
#define s_mark_end(s) (s)->end = (s)->p;
|
#define s_mark_end(s) (s)->end = (s)->p;
|
||||||
#define s_check_rem(s,n) (((s)->p <= (s)->end) && ((size_t)n <= (size_t)((s)->end - (s)->p)))
|
/* Returns number of bytes that can still be read from STREAM */
|
||||||
|
#define s_remaining(s) (size_t)((s)->end - (s)->p)
|
||||||
|
#define s_check_rem(s,n) (((s)->p <= (s)->end) && ((size_t)n <= s_remaining(s)))
|
||||||
#define s_check_end(s) ((s)->p == (s)->end)
|
#define s_check_end(s) ((s)->p == (s)->end)
|
||||||
#define s_length(s) ((s)->end - (s)->data)
|
#define s_length(s) ((s)->end - (s)->data)
|
||||||
#define s_left(s) ((s)->size - (size_t)((s)->p - (s)->data))
|
#define s_left(s) ((s)->size - (size_t)((s)->p - (s)->data))
|
||||||
|
Loading…
Reference in New Issue
Block a user