From fa93e401ce5bd513d7df13029fef2461d0d95be1 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 15 Jan 2018 15:15:42 +0100 Subject: [PATCH] additionally check that size returned by Postgres matches --- src/pq/pq_result_helper.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/src/pq/pq_result_helper.c b/src/pq/pq_result_helper.c index 045fe74b1..d9fed26a6 100644 --- a/src/pq/pq_result_helper.c +++ b/src/pq/pq_result_helper.c @@ -100,8 +100,8 @@ extract_varsize_blob (void *cls, idst = GNUNET_malloc (len); *((void **) dst) = idst; GNUNET_memcpy (idst, - res, - len); + res, + len); return GNUNET_OK; } @@ -165,7 +165,7 @@ extract_fixed_blob (void *cls, { GNUNET_break (0); return GNUNET_SYSERR; - } + } /* if a field is null, continue but * remember that we now return a different result */ @@ -182,8 +182,8 @@ extract_fixed_blob (void *cls, fnum); GNUNET_assert (NULL != res); GNUNET_memcpy (dst, - res, - len); + res, + len); return GNUNET_OK; } @@ -580,7 +580,7 @@ extract_uint16 (void *cls, if (PQgetisnull (result, row, fnum)) - { + { GNUNET_break (0); return GNUNET_SYSERR; } @@ -590,6 +590,14 @@ extract_uint16 (void *cls, GNUNET_break (0); return GNUNET_SYSERR; } + if (sizeof (uint16_t) != + PQgetlength (result, + row, + fnum)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } res = (uint16_t *) PQgetvalue (result, row, fnum); @@ -663,6 +671,14 @@ extract_uint32 (void *cls, GNUNET_break (0); return GNUNET_SYSERR; } + if (sizeof (uint32_t) != + PQgetlength (result, + row, + fnum)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } res = (uint32_t *) PQgetvalue (result, row, fnum); @@ -736,6 +752,14 @@ extract_uint64 (void *cls, GNUNET_break (0); return GNUNET_SYSERR; } + if (sizeof (uint64_t) != + PQgetlength (result, + row, + fnum)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } res = (uint64_t *) PQgetvalue (result, row, fnum); -- 2.25.1