diff options
author | Christian Grothoff <christian@grothoff.org> | 2024-01-18 12:08:53 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2024-02-07 23:48:45 +0100 |
commit | e0d46f96859b33b3f04791028e30bce4f0173567 (patch) | |
tree | 18478e55759cf318da746e64353183601dfb3899 /src/pq | |
parent | b5de0afa73c0b8f7bcf988e2bc00f07f4f6cf42e (diff) |
auditordb tabularasa
Diffstat (limited to 'src/pq')
-rw-r--r-- | src/pq/pq_common.h | 15 | ||||
-rw-r--r-- | src/pq/pq_result_helper.c | 41 |
2 files changed, 46 insertions, 10 deletions
diff --git a/src/pq/pq_common.h b/src/pq/pq_common.h index 1562646ff..3248778a0 100644 --- a/src/pq/pq_common.h +++ b/src/pq/pq_common.h @@ -77,6 +77,21 @@ struct TALER_PQ_AmountP /** + * Memory representation of an taler amount record for Postgres. + * + * All values need to be in network-byte-order. + */ +struct TALER_PQ_AmountNullP +{ + uint32_t cnt; /* # elements in the tuple (== 2) */ + uint32_t oid_v; /* oid of .v */ + uint32_t sz_v; /* size of .v */ + uint32_t oid_f; /* oid of .f */ + uint32_t sz_f; /* size of .f */ +} __attribute__((packed)); + + +/** * Memory representation of an taler amount record with currency for Postgres. * * All values need to be in network-byte-order. diff --git a/src/pq/pq_result_helper.c b/src/pq/pq_result_helper.c index 915aad144..e81c78302 100644 --- a/src/pq/pq_result_helper.c +++ b/src/pq/pq_result_helper.c @@ -229,6 +229,30 @@ extract_amount_tuple (void *cls, size = PQgetlength (result, row, col); + in = PQgetvalue (result, + row, + col); + if (sizeof(struct TALER_PQ_AmountNullP) == size) + { + struct TALER_PQ_AmountNullP apn; + + memcpy (&apn, + in, + size); + if ( (2 == ntohl (apn.cnt)) && + (-1 == (int32_t) ntohl (apn.sz_v)) && + (-1 == (int32_t) ntohl (apn.sz_f)) ) + { + /* is NULL! */ + return GNUNET_NO; + } + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Incorrect size of binary field `%s' and not NULL (got %zu, expected %zu)\n", + fname, + size, + sizeof(ap)); + return GNUNET_SYSERR; + } if (sizeof(ap) != size) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -239,9 +263,6 @@ extract_amount_tuple (void *cls, return GNUNET_SYSERR; } - in = PQgetvalue (result, - row, - col); memcpy (&ap, in, size); @@ -1141,13 +1162,13 @@ extract_array_generic ( *((void **) dst) = NULL; #define FAIL_IF(cond) \ - do { \ - if ((cond)) \ - { \ - GNUNET_break (! (cond)); \ - goto FAIL; \ - } \ - } while (0) + do { \ + if ((cond)) \ + { \ + GNUNET_break (! (cond)); \ + goto FAIL; \ + } \ + } while (0) col_num = PQfnumber (result, fname); FAIL_IF (0 > col_num); |