summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--qarsh_packet.c34
1 files changed, 28 insertions, 6 deletions
diff --git a/qarsh_packet.c b/qarsh_packet.c
index 24f4661..2ca3f13 100644
--- a/qarsh_packet.c
+++ b/qarsh_packet.c
@@ -204,6 +204,20 @@ qp_packet_type(enum qa_packet_type t)
*/
char *
+fetch_uint8(char *buf, int *buflen, int *out)
+{
+ uint8_t i;
+ if (*buflen < sizeof i) {
+ lprintf(0, "Not enough data to unpack a uint8_t, %d\n", *buflen);
+ return buf;
+ }
+ memcpy(&i, buf, sizeof i);
+ *out = i;
+ *buflen -= sizeof i;
+ return buf + sizeof i;
+}
+
+char *
fetch_int(char *buf, int *buflen, int *out)
{
int i;
@@ -338,7 +352,7 @@ parse_qp_rstat(char *buf, int *buflen, struct qa_packet *qp)
void
parse_qp_data(char *buf, int *buflen, struct qa_packet *qp)
{
- buf = fetch_int(buf, buflen, (int *)&(qp->qp_data.qp_remfd));
+ buf = fetch_uint8(buf, buflen, (int *)&(qp->qp_data.qp_remfd));
buf = fetch_off_t(buf, buflen, &(qp->qp_data.qp_offset));
buf = fetch_int(buf, buflen, (int *)&(qp->qp_data.qp_count));
if (qp->qp_data.qp_count > *buflen) {
@@ -355,7 +369,7 @@ parse_qp_data(char *buf, int *buflen, struct qa_packet *qp)
void
parse_qp_data_allow(char *buf, int *buflen, struct qa_packet *qp)
{
- buf = fetch_int(buf, buflen, (int *)&(qp->qp_dallow.qp_remfd));
+ buf = fetch_uint8(buf, buflen, (int *)&(qp->qp_dallow.qp_remfd));
buf = fetch_int(buf, buflen, (int *)&(qp->qp_dallow.qp_count));
}
@@ -369,7 +383,7 @@ parse_packet(char *buf, int buflen)
memset(qp, 0, sizeof *qp);
buf = fetch_int(buf, &buflen, &(qp->qp_seq));
- buf = fetch_int(buf, &buflen, (int *)&(qp->qp_type));
+ buf = fetch_uint8(buf, &buflen, (int *)&(qp->qp_type));
if (qa_pi[qp->qp_type].pi_parse)
qa_pi[qp->qp_type].pi_parse(buf, &buflen, qp);
@@ -387,6 +401,14 @@ parse_packet(char *buf, int buflen)
*
*/
static char *
+store_uint8(char *buf, int i)
+{
+ uint8_t a = i;
+ memcpy(buf, &a, sizeof a);
+ return buf + sizeof a;
+}
+
+static char *
store_int(char *buf, int i)
{
i = htobe32(i);
@@ -504,7 +526,7 @@ store_qp_rstat(char *buf, struct qa_packet *qp)
char *
store_qp_data(char *buf, struct qa_packet *qp)
{
- buf = store_int(buf, qp->qp_data.qp_remfd);
+ buf = store_uint8(buf, qp->qp_data.qp_remfd);
buf = store_off_t(buf, qp->qp_data.qp_offset);
buf = store_void(buf, qp->qp_data.qp_count, qp->qp_data.qp_blob);
return buf;
@@ -513,7 +535,7 @@ store_qp_data(char *buf, struct qa_packet *qp)
char *
store_qp_data_allow(char *buf, struct qa_packet *qp)
{
- buf = store_int(buf, qp->qp_dallow.qp_remfd);
+ buf = store_uint8(buf, qp->qp_dallow.qp_remfd);
buf = store_int(buf, qp->qp_dallow.qp_count);
return buf;
}
@@ -528,7 +550,7 @@ qptostr(struct qa_packet *qp, char *qpstr, int maxsize)
cp = qpstr;
cp = store_int(cp, qp->qp_seq);
- cp = store_int(cp, qp->qp_type);
+ cp = store_uint8(cp, qp->qp_type);
if (qa_pi[qp->qp_type].pi_store) {
cp = qa_pi[qp->qp_type].pi_store(cp, qp);