* Exim - an Internet mail transport agent *
*************************************************/
+/* Copyright (c) The Exim Maintainers 2020 - 2022 */
/* Copyright (c) University of Cambridge 1995 - 2018 */
-/* Copyright (c) The Exim Maintainers 2020 - 2021 */
/* See the file NOTICE for conditions of use and distribution. */
+/* SPDX-License-Identifier: GPL-2.0-or-later */
#include "exim.h"
*/
void *
-dbfn_read_with_length(open_db *dbblock, const uschar *key, int *length)
+dbfn_read_with_length(open_db * dbblock, const uschar * key, int * length)
{
-void *yield;
+void * yield;
EXIM_DATUM key_datum, result_datum;
int klen = Ustrlen(key) + 1;
uschar * key_copy = store_get(klen, key);
+unsigned dlen;
memcpy(key_copy, key, klen);
/* Assume the data store could have been tainted. Properly, we should
store the taint status with the data. */
-yield = store_get(exim_datum_size_get(&result_datum), GET_TAINTED);
-memcpy(yield, exim_datum_data_get(&result_datum), exim_datum_size_get(&result_datum));
-if (length) *length = exim_datum_size_get(&result_datum);
+dlen = exim_datum_size_get(&result_datum);
+yield = store_get(dlen, GET_TAINTED);
+memcpy(yield, exim_datum_data_get(&result_datum), dlen);
+if (length) *length = dlen;
exim_datum_free(&result_datum); /* Some DBM libs require freeing */
return yield;
{
count = Uatoi(cmd);
while (isdigit((uschar)*cmd)) cmd++;
- while (isspace((uschar)*cmd)) cmd++;
+ Uskip_whitespace(&cmd);
}
if (Ustrncmp(cmd, "open", 4) == 0)
int i;
open_db *odb;
uschar *s = cmd + 4;
- while (isspace((uschar)*s)) s++;
+ Uskip_whitespace(&s);
for (i = 0; i < max_db; i++)
if (dbblock[i].dbptr == NULL) break;
else if (Ustrncmp(cmd, "write", 5) == 0)
{
int rc = 0;
- uschar *key = cmd + 5;
- uschar *data;
+ uschar * key = cmd + 5, * data;
if (current < 0)
{
continue;
}
- while (isspace((uschar)*key)) key++;
+ Uskip_whitespace(&key);
data = key;
- while (*data != 0 && !isspace((uschar)*data)) data++;
- *data++ = 0;
- while (isspace((uschar)*data)) data++;
+ Uskip_nonwhite(&data);
+ *data++ = '\0';
+ Uskip_whitespace(&data);
dbwait = (dbdata_wait *)(&structbuffer);
Ustrcpy(dbwait->text, data);
else if (Ustrncmp(cmd, "read", 4) == 0)
{
- uschar *key = cmd + 4;
+ uschar * key = cmd + 4;
if (current < 0)
{
printf("No current database\n");
continue;
}
- while (isspace((uschar)*key)) key++;
+ Uskip_whitespace(&key);
start = clock();
while (count-- > 0)
dbwait = (dbdata_wait *)dbfn_read_with_length(dbblock+ current, key, NULL);
else if (Ustrncmp(cmd, "delete", 6) == 0)
{
- uschar *key = cmd + 6;
+ uschar * key = cmd + 6;
if (current < 0)
{
printf("No current database\n");
continue;
}
- while (isspace((uschar)*key)) key++;
+ Uskip_whitespace(&key);
dbfn_delete(dbblock + current, key);
}
else if (Ustrncmp(cmd, "close", 5) == 0)
{
- uschar *s = cmd + 5;
- while (isspace((uschar)*s)) s++;
+ uschar * s = cmd + 5;
+ Uskip_whitespace(&s);
i = Uatoi(s);
if (i >= max_db || dbblock[i].dbptr == NULL) printf("Not open\n"); else
{
else if (Ustrncmp(cmd, "file", 4) == 0)
{
- uschar *s = cmd + 4;
- while (isspace((uschar)*s)) s++;
+ uschar * s = cmd + 4;
+ Uskip_whitespace(&s);
i = Uatoi(s);
if (i >= max_db || dbblock[i].dbptr == NULL) printf("Not open\n");
else current = i;
#endif
/* End of dbfn.c */
+/* vi: aw ai sw=2
+*/