Coverage Report

Created: 2025-06-13 06:58

/src/openssl32/crypto/conf/conf_mod.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2002-2023 The OpenSSL Project Authors. All Rights Reserved.
3
 *
4
 * Licensed under the Apache License 2.0 (the "License").  You may not use
5
 * this file except in compliance with the License.  You can obtain a copy
6
 * in the file LICENSE in the source distribution or at
7
 * https://www.openssl.org/source/license.html
8
 */
9
10
/* We need to use some engine deprecated APIs */
11
#define OPENSSL_SUPPRESS_DEPRECATED
12
13
#include "internal/cryptlib.h"
14
#include <stdio.h>
15
#include <ctype.h>
16
#include <openssl/crypto.h>
17
#include "internal/conf.h"
18
#include <openssl/conf_api.h>
19
#include "internal/dso.h"
20
#include "internal/thread_once.h"
21
#include <openssl/x509.h>
22
#include <openssl/trace.h>
23
#include <openssl/engine.h>
24
#include "conf_local.h"
25
26
DEFINE_STACK_OF(CONF_MODULE)
27
DEFINE_STACK_OF(CONF_IMODULE)
28
29
0
#define DSO_mod_init_name "OPENSSL_init"
30
0
#define DSO_mod_finish_name "OPENSSL_finish"
31
32
/*
33
 * This structure contains a data about supported modules. entries in this
34
 * table correspond to either dynamic or static modules.
35
 */
36
37
struct conf_module_st {
38
    /* DSO of this module or NULL if static */
39
    DSO *dso;
40
    /* Name of the module */
41
    char *name;
42
    /* Init function */
43
    conf_init_func *init;
44
    /* Finish function */
45
    conf_finish_func *finish;
46
    /* Number of successfully initialized modules */
47
    int links;
48
    void *usr_data;
49
};
50
51
/*
52
 * This structure contains information about modules that have been
53
 * successfully initialized. There may be more than one entry for a given
54
 * module.
55
 */
56
57
struct conf_imodule_st {
58
    CONF_MODULE *pmod;
59
    char *name;
60
    char *value;
61
    unsigned long flags;
62
    void *usr_data;
63
};
64
65
static CRYPTO_ONCE init_module_list_lock = CRYPTO_ONCE_STATIC_INIT;
66
static CRYPTO_RWLOCK *module_list_lock = NULL;
67
static STACK_OF(CONF_MODULE) *supported_modules = NULL; /* protected by lock */
68
static STACK_OF(CONF_IMODULE) *initialized_modules = NULL; /* protected by lock */
69
70
static CRYPTO_ONCE load_builtin_modules = CRYPTO_ONCE_STATIC_INIT;
71
72
static void module_free(CONF_MODULE *md);
73
static void module_finish(CONF_IMODULE *imod);
74
static int module_run(const CONF *cnf, const char *name, const char *value,
75
                      unsigned long flags);
76
static CONF_MODULE *module_add(DSO *dso, const char *name,
77
                               conf_init_func *ifunc,
78
                               conf_finish_func *ffunc);
79
static CONF_MODULE *module_find(const char *name);
80
static int module_init(CONF_MODULE *pmod, const char *name, const char *value,
81
                       const CONF *cnf);
82
static CONF_MODULE *module_load_dso(const CONF *cnf, const char *name,
83
                                    const char *value);
84
85
static int conf_modules_finish_int(void);
86
87
static void module_lists_free(void)
88
133
{
89
133
    CRYPTO_THREAD_lock_free(module_list_lock);
90
133
    module_list_lock = NULL;
91
92
133
    sk_CONF_MODULE_free(supported_modules);
93
133
    supported_modules = NULL;
94
95
133
    sk_CONF_IMODULE_free(initialized_modules);
96
133
    initialized_modules = NULL;
97
133
}
98
99
DEFINE_RUN_ONCE_STATIC(do_init_module_list_lock)
100
133
{
101
133
    module_list_lock = CRYPTO_THREAD_lock_new();
102
133
    if (module_list_lock == NULL) {
103
0
        ERR_raise(ERR_LIB_CONF, ERR_R_CRYPTO_LIB);
104
0
        return 0;
105
0
    }
106
107
133
    return 1;
108
133
}
109
110
static int conf_diagnostics(const CONF *cnf)
111
0
{
112
0
    return _CONF_get_number(cnf, NULL, "config_diagnostics") != 0;
113
0
}
114
115
/* Main function: load modules from a CONF structure */
116
117
int CONF_modules_load(const CONF *cnf, const char *appname,
118
                      unsigned long flags)
119
0
{
120
0
    STACK_OF(CONF_VALUE) *values;
121
0
    CONF_VALUE *vl;
122
0
    char *vsection = NULL;
123
0
    int ret, i;
124
125
0
    if (!cnf)
126
0
        return 1;
127
128
0
    if (conf_diagnostics(cnf))
129
0
        flags &= ~(CONF_MFLAGS_IGNORE_ERRORS
130
0
                   | CONF_MFLAGS_IGNORE_RETURN_CODES
131
0
                   | CONF_MFLAGS_SILENT
132
0
                   | CONF_MFLAGS_IGNORE_MISSING_FILE);
133
134
0
    ERR_set_mark();
135
0
    if (appname)
136
0
        vsection = NCONF_get_string(cnf, NULL, appname);
137
138
0
    if (!appname || (!vsection && (flags & CONF_MFLAGS_DEFAULT_SECTION)))
139
0
        vsection = NCONF_get_string(cnf, NULL, "openssl_conf");
140
141
0
    if (!vsection) {
142
0
        ERR_pop_to_mark();
143
0
        return 1;
144
0
    }
145
146
0
    OSSL_TRACE1(CONF, "Configuration in section %s\n", vsection);
147
0
    values = NCONF_get_section(cnf, vsection);
148
149
0
    if (values == NULL) {
150
0
        if (!(flags & CONF_MFLAGS_SILENT)) {
151
0
            ERR_clear_last_mark();
152
0
            ERR_raise_data(ERR_LIB_CONF,
153
0
                           CONF_R_OPENSSL_CONF_REFERENCES_MISSING_SECTION,
154
0
                           "openssl_conf=%s", vsection);
155
0
        } else {
156
0
            ERR_pop_to_mark();
157
0
        }
158
0
        return 0;
159
0
    }
160
0
    ERR_pop_to_mark();
161
162
0
    for (i = 0; i < sk_CONF_VALUE_num(values); i++) {
163
0
        vl = sk_CONF_VALUE_value(values, i);
164
0
        ERR_set_mark();
165
0
        ret = module_run(cnf, vl->name, vl->value, flags);
166
0
        OSSL_TRACE3(CONF, "Running module %s (%s) returned %d\n",
167
0
                    vl->name, vl->value, ret);
168
0
        if (ret <= 0)
169
0
            if (!(flags & CONF_MFLAGS_IGNORE_ERRORS)) {
170
0
                ERR_clear_last_mark();
171
0
                return ret;
172
0
            }
173
0
        ERR_pop_to_mark();
174
0
    }
175
176
0
    return 1;
177
178
0
}
179
180
int CONF_modules_load_file_ex(OSSL_LIB_CTX *libctx, const char *filename,
181
                              const char *appname, unsigned long flags)
182
82
{
183
82
    char *file = NULL;
184
82
    CONF *conf = NULL;
185
82
    int ret = 0, diagnostics = 0;
186
187
82
    ERR_set_mark();
188
189
82
    if (filename == NULL) {
190
82
        file = CONF_get1_default_config_file();
191
82
        if (file == NULL)
192
0
            goto err;
193
82
        if (*file == '\0') {
194
            /* Do not try to load an empty file name but do not error out */
195
0
            ret = 1;
196
0
            goto err;
197
0
        }
198
82
    } else {
199
0
        file = (char *)filename;
200
0
    }
201
202
82
    conf = NCONF_new_ex(libctx, NULL);
203
82
    if (conf == NULL)
204
0
        goto err;
205
206
82
    if (NCONF_load(conf, file, NULL) <= 0) {
207
82
        if ((flags & CONF_MFLAGS_IGNORE_MISSING_FILE) &&
208
82
            (ERR_GET_REASON(ERR_peek_last_error()) == CONF_R_NO_SUCH_FILE)) {
209
82
            ret = 1;
210
82
        }
211
82
        goto err;
212
82
    }
213
214
0
    ret = CONF_modules_load(conf, appname, flags);
215
0
    diagnostics = conf_diagnostics(conf);
216
217
82
 err:
218
82
    if (filename == NULL)
219
82
        OPENSSL_free(file);
220
82
    NCONF_free(conf);
221
222
82
    if ((flags & CONF_MFLAGS_IGNORE_RETURN_CODES) != 0 && !diagnostics)
223
82
        ret = 1;
224
225
82
    if (ret > 0)
226
82
        ERR_pop_to_mark();
227
0
    else
228
0
        ERR_clear_last_mark();
229
230
82
    return ret;
231
0
}
232
233
int CONF_modules_load_file(const char *filename,
234
                           const char *appname, unsigned long flags)
235
0
{
236
0
    return CONF_modules_load_file_ex(NULL, filename, appname, flags);
237
0
}
238
239
DEFINE_RUN_ONCE_STATIC(do_load_builtin_modules)
240
0
{
241
0
    OPENSSL_load_builtin_modules();
242
0
#ifndef OPENSSL_NO_ENGINE
243
    /* Need to load ENGINEs */
244
0
    ENGINE_load_builtin_engines();
245
0
#endif
246
0
    return 1;
247
0
}
248
249
static int module_run(const CONF *cnf, const char *name, const char *value,
250
                      unsigned long flags)
251
0
{
252
0
    CONF_MODULE *md;
253
0
    int ret;
254
255
0
    if (!RUN_ONCE(&load_builtin_modules, do_load_builtin_modules))
256
0
        return -1;
257
258
0
    md = module_find(name);
259
260
    /* Module not found: try to load DSO */
261
0
    if (!md && !(flags & CONF_MFLAGS_NO_DSO))
262
0
        md = module_load_dso(cnf, name, value);
263
264
0
    if (!md) {
265
0
        if (!(flags & CONF_MFLAGS_SILENT)) {
266
0
            ERR_raise_data(ERR_LIB_CONF, CONF_R_UNKNOWN_MODULE_NAME,
267
0
                           "module=%s", name);
268
0
        }
269
0
        return -1;
270
0
    }
271
272
0
    ret = module_init(md, name, value, cnf);
273
274
0
    if (ret <= 0) {
275
0
        if (!(flags & CONF_MFLAGS_SILENT))
276
0
            ERR_raise_data(ERR_LIB_CONF, CONF_R_MODULE_INITIALIZATION_ERROR,
277
0
                           "module=%s, value=%s retcode=%-8d",
278
0
                           name, value, ret);
279
0
    }
280
281
0
    return ret;
282
0
}
283
284
/* Load a module from a DSO */
285
static CONF_MODULE *module_load_dso(const CONF *cnf,
286
                                    const char *name, const char *value)
287
0
{
288
0
    DSO *dso = NULL;
289
0
    conf_init_func *ifunc;
290
0
    conf_finish_func *ffunc;
291
0
    const char *path = NULL;
292
0
    int errcode = 0;
293
0
    CONF_MODULE *md;
294
295
    /* Look for alternative path in module section */
296
0
    path = _CONF_get_string(cnf, value, "path");
297
0
    if (path == NULL) {
298
0
        path = name;
299
0
    }
300
0
    dso = DSO_load(NULL, path, NULL, 0);
301
0
    if (dso == NULL) {
302
0
        errcode = CONF_R_ERROR_LOADING_DSO;
303
0
        goto err;
304
0
    }
305
0
    ifunc = (conf_init_func *)DSO_bind_func(dso, DSO_mod_init_name);
306
0
    if (ifunc == NULL) {
307
0
        errcode = CONF_R_MISSING_INIT_FUNCTION;
308
0
        goto err;
309
0
    }
310
0
    ffunc = (conf_finish_func *)DSO_bind_func(dso, DSO_mod_finish_name);
311
    /* All OK, add module */
312
0
    md = module_add(dso, name, ifunc, ffunc);
313
314
0
    if (md == NULL)
315
0
        goto err;
316
317
0
    return md;
318
319
0
 err:
320
0
    DSO_free(dso);
321
0
    ERR_raise_data(ERR_LIB_CONF, errcode, "module=%s, path=%s", name, path);
322
0
    return NULL;
323
0
}
324
325
/* add module to list */
326
static CONF_MODULE *module_add(DSO *dso, const char *name,
327
                               conf_init_func *ifunc, conf_finish_func *ffunc)
328
0
{
329
0
    CONF_MODULE *tmod = NULL;
330
331
0
    if (!RUN_ONCE(&init_module_list_lock, do_init_module_list_lock))
332
0
        return NULL;
333
334
0
    if (!CRYPTO_THREAD_write_lock(module_list_lock))
335
0
        return NULL;
336
337
0
    if (supported_modules == NULL)
338
0
        supported_modules = sk_CONF_MODULE_new_null();
339
0
    if (supported_modules == NULL)
340
0
        goto err;
341
0
    if ((tmod = OPENSSL_zalloc(sizeof(*tmod))) == NULL)
342
0
        goto err;
343
344
0
    tmod->dso = dso;
345
0
    tmod->name = OPENSSL_strdup(name);
346
0
    tmod->init = ifunc;
347
0
    tmod->finish = ffunc;
348
0
    if (tmod->name == NULL)
349
0
        goto err;
350
351
0
    if (!sk_CONF_MODULE_push(supported_modules, tmod))
352
0
        goto err;
353
354
0
    CRYPTO_THREAD_unlock(module_list_lock);
355
0
    return tmod;
356
357
0
 err:
358
0
    CRYPTO_THREAD_unlock(module_list_lock);
359
0
    if (tmod != NULL) {
360
0
        OPENSSL_free(tmod->name);
361
0
        OPENSSL_free(tmod);
362
0
    }
363
0
    return NULL;
364
0
}
365
366
/*
367
 * Find a module from the list. We allow module names of the form
368
 * modname.XXXX to just search for modname to allow the same module to be
369
 * initialized more than once.
370
 */
371
372
static CONF_MODULE *module_find(const char *name)
373
0
{
374
0
    CONF_MODULE *tmod;
375
0
    int i, nchar;
376
0
    char *p;
377
0
    p = strrchr(name, '.');
378
379
0
    if (p)
380
0
        nchar = p - name;
381
0
    else
382
0
        nchar = strlen(name);
383
384
0
    if (!RUN_ONCE(&init_module_list_lock, do_init_module_list_lock))
385
0
        return NULL;
386
387
0
    if (!CRYPTO_THREAD_read_lock(module_list_lock))
388
0
        return NULL;
389
390
0
    for (i = 0; i < sk_CONF_MODULE_num(supported_modules); i++) {
391
0
        tmod = sk_CONF_MODULE_value(supported_modules, i);
392
0
        if (strncmp(tmod->name, name, nchar) == 0) {
393
0
            CRYPTO_THREAD_unlock(module_list_lock);
394
0
            return tmod;
395
0
        }
396
0
    }
397
398
0
    CRYPTO_THREAD_unlock(module_list_lock);
399
0
    return NULL;
400
0
}
401
402
/* initialize a module */
403
static int module_init(CONF_MODULE *pmod, const char *name, const char *value,
404
                       const CONF *cnf)
405
0
{
406
0
    int ret = 1;
407
0
    int init_called = 0;
408
0
    CONF_IMODULE *imod = NULL;
409
410
    /* Otherwise add initialized module to list */
411
0
    imod = OPENSSL_malloc(sizeof(*imod));
412
0
    if (imod == NULL)
413
0
        goto err;
414
415
0
    imod->pmod = pmod;
416
0
    imod->name = OPENSSL_strdup(name);
417
0
    imod->value = OPENSSL_strdup(value);
418
0
    imod->usr_data = NULL;
419
420
0
    if (!imod->name || !imod->value)
421
0
        goto memerr;
422
423
    /* Try to initialize module */
424
0
    if (pmod->init) {
425
0
        ret = pmod->init(imod, cnf);
426
0
        init_called = 1;
427
        /* Error occurred, exit */
428
0
        if (ret <= 0)
429
0
            goto err;
430
0
    }
431
432
0
    if (!RUN_ONCE(&init_module_list_lock, do_init_module_list_lock))
433
0
        goto err;
434
435
0
    if (!CRYPTO_THREAD_write_lock(module_list_lock))
436
0
        goto err;
437
438
0
    if (initialized_modules == NULL) {
439
0
        initialized_modules = sk_CONF_IMODULE_new_null();
440
0
        if (initialized_modules == NULL) {
441
0
            CRYPTO_THREAD_unlock(module_list_lock);
442
0
            ERR_raise(ERR_LIB_CONF, ERR_R_CRYPTO_LIB);
443
0
            goto err;
444
0
        }
445
0
    }
446
447
0
    if (!sk_CONF_IMODULE_push(initialized_modules, imod)) {
448
0
        CRYPTO_THREAD_unlock(module_list_lock);
449
0
        ERR_raise(ERR_LIB_CONF, ERR_R_CRYPTO_LIB);
450
0
        goto err;
451
0
    }
452
453
0
    pmod->links++;
454
455
0
    CRYPTO_THREAD_unlock(module_list_lock);
456
0
    return ret;
457
458
0
 err:
459
460
    /* We've started the module so we'd better finish it */
461
0
    if (pmod->finish && init_called)
462
0
        pmod->finish(imod);
463
464
0
 memerr:
465
0
    if (imod) {
466
0
        OPENSSL_free(imod->name);
467
0
        OPENSSL_free(imod->value);
468
0
        OPENSSL_free(imod);
469
0
    }
470
471
0
    return -1;
472
473
0
}
474
475
/*
476
 * Unload any dynamic modules that have a link count of zero: i.e. have no
477
 * active initialized modules. If 'all' is set then all modules are unloaded
478
 * including static ones.
479
 */
480
481
void CONF_modules_unload(int all)
482
80
{
483
80
    int i;
484
80
    CONF_MODULE *md;
485
486
80
    if (!conf_modules_finish_int()) /* also inits module list lock */
487
0
        return;
488
489
80
    if (!CRYPTO_THREAD_write_lock(module_list_lock))
490
0
        return;
491
492
    /* unload modules in reverse order */
493
80
    for (i = sk_CONF_MODULE_num(supported_modules) - 1; i >= 0; i--) {
494
0
        md = sk_CONF_MODULE_value(supported_modules, i);
495
        /* If static or in use and 'all' not set ignore it */
496
0
        if (((md->links > 0) || !md->dso) && !all)
497
0
            continue;
498
        /* Since we're working in reverse this is OK */
499
0
        (void)sk_CONF_MODULE_delete(supported_modules, i);
500
0
        module_free(md);
501
0
    }
502
503
80
    if (sk_CONF_MODULE_num(supported_modules) == 0) {
504
0
        sk_CONF_MODULE_free(supported_modules);
505
0
        supported_modules = NULL;
506
0
    }
507
508
80
    CRYPTO_THREAD_unlock(module_list_lock);
509
80
}
510
511
/* unload a single module */
512
static void module_free(CONF_MODULE *md)
513
0
{
514
0
    DSO_free(md->dso);
515
0
    OPENSSL_free(md->name);
516
0
    OPENSSL_free(md);
517
0
}
518
519
/* finish and free up all modules instances */
520
521
static int conf_modules_finish_int(void)
522
80
{
523
80
    CONF_IMODULE *imod;
524
525
80
    if (!RUN_ONCE(&init_module_list_lock, do_init_module_list_lock))
526
0
        return 0;
527
528
    /* If module_list_lock is NULL here it means we were already unloaded */
529
80
    if (module_list_lock == NULL
530
80
        || !CRYPTO_THREAD_write_lock(module_list_lock))
531
0
        return 0;
532
533
80
    while (sk_CONF_IMODULE_num(initialized_modules) > 0) {
534
0
        imod = sk_CONF_IMODULE_pop(initialized_modules);
535
0
        module_finish(imod);
536
0
    }
537
80
    sk_CONF_IMODULE_free(initialized_modules);
538
80
    initialized_modules = NULL;
539
540
80
    CRYPTO_THREAD_unlock(module_list_lock);
541
542
80
    return 1;
543
80
}
544
545
void CONF_modules_finish(void)
546
0
{
547
0
    conf_modules_finish_int();
548
0
}
549
550
/* finish a module instance */
551
552
static void module_finish(CONF_IMODULE *imod)
553
0
{
554
0
    if (!imod)
555
0
        return;
556
0
    if (imod->pmod->finish)
557
0
        imod->pmod->finish(imod);
558
0
    imod->pmod->links--;
559
0
    OPENSSL_free(imod->name);
560
0
    OPENSSL_free(imod->value);
561
0
    OPENSSL_free(imod);
562
0
}
563
564
/* Add a static module to OpenSSL */
565
566
int CONF_module_add(const char *name, conf_init_func *ifunc,
567
                    conf_finish_func *ffunc)
568
0
{
569
0
    if (module_add(NULL, name, ifunc, ffunc))
570
0
        return 1;
571
0
    else
572
0
        return 0;
573
0
}
574
575
void ossl_config_modules_free(void)
576
133
{
577
133
    CONF_modules_unload(1); /* calls CONF_modules_finish */
578
133
    module_lists_free();
579
133
}
580
581
/* Utility functions */
582
583
const char *CONF_imodule_get_name(const CONF_IMODULE *md)
584
0
{
585
0
    return md->name;
586
0
}
587
588
const char *CONF_imodule_get_value(const CONF_IMODULE *md)
589
0
{
590
0
    return md->value;
591
0
}
592
593
void *CONF_imodule_get_usr_data(const CONF_IMODULE *md)
594
0
{
595
0
    return md->usr_data;
596
0
}
597
598
void CONF_imodule_set_usr_data(CONF_IMODULE *md, void *usr_data)
599
0
{
600
0
    md->usr_data = usr_data;
601
0
}
602
603
CONF_MODULE *CONF_imodule_get_module(const CONF_IMODULE *md)
604
0
{
605
0
    return md->pmod;
606
0
}
607
608
unsigned long CONF_imodule_get_flags(const CONF_IMODULE *md)
609
0
{
610
0
    return md->flags;
611
0
}
612
613
void CONF_imodule_set_flags(CONF_IMODULE *md, unsigned long flags)
614
0
{
615
0
    md->flags = flags;
616
0
}
617
618
void *CONF_module_get_usr_data(CONF_MODULE *pmod)
619
0
{
620
0
    return pmod->usr_data;
621
0
}
622
623
void CONF_module_set_usr_data(CONF_MODULE *pmod, void *usr_data)
624
0
{
625
0
    pmod->usr_data = usr_data;
626
0
}
627
628
/* Return default config file name */
629
char *CONF_get1_default_config_file(void)
630
45
{
631
45
    const char *t;
632
45
    char *file, *sep = "";
633
45
    size_t size;
634
635
45
    if ((file = ossl_safe_getenv("OPENSSL_CONF")) != NULL)
636
0
        return OPENSSL_strdup(file);
637
638
45
    t = X509_get_default_cert_area();
639
45
#ifndef OPENSSL_SYS_VMS
640
45
    sep = "/";
641
45
#endif
642
45
    size = strlen(t) + strlen(sep) + strlen(OPENSSL_CONF) + 1;
643
45
    file = OPENSSL_malloc(size);
644
645
45
    if (file == NULL)
646
0
        return NULL;
647
45
    BIO_snprintf(file, size, "%s%s%s", t, sep, OPENSSL_CONF);
648
649
45
    return file;
650
45
}
651
652
/*
653
 * This function takes a list separated by 'sep' and calls the callback
654
 * function giving the start and length of each member optionally stripping
655
 * leading and trailing whitespace. This can be used to parse comma separated
656
 * lists for example.
657
 */
658
659
int CONF_parse_list(const char *list_, int sep, int nospc,
660
                    int (*list_cb) (const char *elem, int len, void *usr),
661
                    void *arg)
662
234k
{
663
234k
    int ret;
664
234k
    const char *lstart, *tmpend, *p;
665
666
234k
    if (list_ == NULL) {
667
0
        ERR_raise(ERR_LIB_CONF, CONF_R_LIST_CANNOT_BE_NULL);
668
0
        return 0;
669
0
    }
670
671
234k
    lstart = list_;
672
610k
    for (;;) {
673
610k
        if (nospc) {
674
703k
            while (*lstart && isspace((unsigned char)*lstart))
675
93.1k
                lstart++;
676
610k
        }
677
610k
        p = strchr(lstart, sep);
678
610k
        if (p == lstart || *lstart == '\0')
679
0
            ret = list_cb(NULL, 0, arg);
680
610k
        else {
681
610k
            if (p)
682
376k
                tmpend = p - 1;
683
234k
            else
684
234k
                tmpend = lstart + strlen(lstart) - 1;
685
610k
            if (nospc) {
686
610k
                while (isspace((unsigned char)*tmpend))
687
93.1k
                    tmpend--;
688
610k
            }
689
610k
            ret = list_cb(lstart, tmpend - lstart + 1, arg);
690
610k
        }
691
610k
        if (ret <= 0)
692
0
            return ret;
693
610k
        if (p == NULL)
694
234k
            return 1;
695
376k
        lstart = p + 1;
696
376k
    }
697
234k
}