Coverage Report

Created: 2025-12-31 06:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl30/crypto/conf/conf_mod.c
Line
Count
Source
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
220
{
89
220
    CRYPTO_THREAD_lock_free(module_list_lock);
90
220
    module_list_lock = NULL;
91
92
220
    sk_CONF_MODULE_free(supported_modules);
93
220
    supported_modules = NULL;
94
95
220
    sk_CONF_IMODULE_free(initialized_modules);
96
220
    initialized_modules = NULL;
97
220
}
98
99
DEFINE_RUN_ONCE_STATIC(do_init_module_list_lock)
100
220
{
101
220
    module_list_lock = CRYPTO_THREAD_lock_new();
102
220
    if (module_list_lock == NULL) {
103
0
        ERR_raise(ERR_LIB_CONF, ERR_R_MALLOC_FAILURE);
104
0
        return 0;
105
0
    }
106
107
220
    return 1;
108
220
}
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
0
}
178
179
int CONF_modules_load_file_ex(OSSL_LIB_CTX *libctx, const char *filename,
180
    const char *appname, unsigned long flags)
181
185
{
182
185
    char *file = NULL;
183
185
    CONF *conf = NULL;
184
185
    int ret = 0, diagnostics = 0;
185
186
185
    ERR_set_mark();
187
188
185
    if (filename == NULL) {
189
185
        file = CONF_get1_default_config_file();
190
185
        if (file == NULL)
191
0
            goto err;
192
185
        if (*file == '\0') {
193
            /* Do not try to load an empty file name but do not error out */
194
0
            ret = 1;
195
0
            goto err;
196
0
        }
197
185
    } else {
198
0
        file = (char *)filename;
199
0
    }
200
201
185
    conf = NCONF_new_ex(libctx, NULL);
202
185
    if (conf == NULL)
203
0
        goto err;
204
205
185
    if (NCONF_load(conf, file, NULL) <= 0) {
206
185
        if ((flags & CONF_MFLAGS_IGNORE_MISSING_FILE) && (ERR_GET_REASON(ERR_peek_last_error()) == CONF_R_NO_SUCH_FILE)) {
207
185
            ret = 1;
208
185
        }
209
185
        goto err;
210
185
    }
211
212
0
    ret = CONF_modules_load(conf, appname, flags);
213
0
    diagnostics = conf_diagnostics(conf);
214
215
185
err:
216
185
    if (filename == NULL)
217
185
        OPENSSL_free(file);
218
185
    NCONF_free(conf);
219
220
185
    if ((flags & CONF_MFLAGS_IGNORE_RETURN_CODES) != 0 && !diagnostics)
221
185
        ret = 1;
222
223
185
    if (ret > 0)
224
185
        ERR_pop_to_mark();
225
0
    else
226
0
        ERR_clear_last_mark();
227
228
185
    return ret;
229
0
}
230
231
int CONF_modules_load_file(const char *filename,
232
    const char *appname, unsigned long flags)
233
0
{
234
0
    return CONF_modules_load_file_ex(NULL, filename, appname, flags);
235
0
}
236
237
DEFINE_RUN_ONCE_STATIC(do_load_builtin_modules)
238
0
{
239
0
    OPENSSL_load_builtin_modules();
240
0
#ifndef OPENSSL_NO_ENGINE
241
    /* Need to load ENGINEs */
242
0
    ENGINE_load_builtin_engines();
243
0
#endif
244
0
    return 1;
245
0
}
246
247
static int module_run(const CONF *cnf, const char *name, const char *value,
248
    unsigned long flags)
249
0
{
250
0
    CONF_MODULE *md;
251
0
    int ret;
252
253
0
    if (!RUN_ONCE(&load_builtin_modules, do_load_builtin_modules))
254
0
        return -1;
255
256
0
    md = module_find(name);
257
258
    /* Module not found: try to load DSO */
259
0
    if (!md && !(flags & CONF_MFLAGS_NO_DSO))
260
0
        md = module_load_dso(cnf, name, value);
261
262
0
    if (!md) {
263
0
        if (!(flags & CONF_MFLAGS_SILENT)) {
264
0
            ERR_raise_data(ERR_LIB_CONF, CONF_R_UNKNOWN_MODULE_NAME,
265
0
                "module=%s", name);
266
0
        }
267
0
        return -1;
268
0
    }
269
270
0
    ret = module_init(md, name, value, cnf);
271
272
0
    if (ret <= 0) {
273
0
        if (!(flags & CONF_MFLAGS_SILENT))
274
0
            ERR_raise_data(ERR_LIB_CONF, CONF_R_MODULE_INITIALIZATION_ERROR,
275
0
                "module=%s, value=%s retcode=%-8d",
276
0
                name, value, ret);
277
0
    }
278
279
0
    return ret;
280
0
}
281
282
/* Load a module from a DSO */
283
static CONF_MODULE *module_load_dso(const CONF *cnf,
284
    const char *name, const char *value)
285
0
{
286
0
    DSO *dso = NULL;
287
0
    conf_init_func *ifunc;
288
0
    conf_finish_func *ffunc;
289
0
    const char *path = NULL;
290
0
    int errcode = 0;
291
0
    CONF_MODULE *md;
292
293
    /* Look for alternative path in module section */
294
0
    path = _CONF_get_string(cnf, value, "path");
295
0
    if (path == NULL) {
296
0
        path = name;
297
0
    }
298
0
    dso = DSO_load(NULL, path, NULL, 0);
299
0
    if (dso == NULL) {
300
0
        errcode = CONF_R_ERROR_LOADING_DSO;
301
0
        goto err;
302
0
    }
303
0
    ifunc = (conf_init_func *)DSO_bind_func(dso, DSO_mod_init_name);
304
0
    if (ifunc == NULL) {
305
0
        errcode = CONF_R_MISSING_INIT_FUNCTION;
306
0
        goto err;
307
0
    }
308
0
    ffunc = (conf_finish_func *)DSO_bind_func(dso, DSO_mod_finish_name);
309
    /* All OK, add module */
310
0
    md = module_add(dso, name, ifunc, ffunc);
311
312
0
    if (md == NULL)
313
0
        goto err;
314
315
0
    return md;
316
317
0
err:
318
0
    DSO_free(dso);
319
0
    ERR_raise_data(ERR_LIB_CONF, errcode, "module=%s, path=%s", name, path);
320
0
    return NULL;
321
0
}
322
323
/* add module to list */
324
static CONF_MODULE *module_add(DSO *dso, const char *name,
325
    conf_init_func *ifunc, conf_finish_func *ffunc)
326
0
{
327
0
    CONF_MODULE *tmod = NULL;
328
329
0
    if (!RUN_ONCE(&init_module_list_lock, do_init_module_list_lock))
330
0
        return NULL;
331
332
0
    if (!CRYPTO_THREAD_write_lock(module_list_lock))
333
0
        return NULL;
334
335
0
    if (supported_modules == NULL)
336
0
        supported_modules = sk_CONF_MODULE_new_null();
337
0
    if (supported_modules == NULL)
338
0
        goto err;
339
0
    if ((tmod = OPENSSL_zalloc(sizeof(*tmod))) == NULL) {
340
0
        ERR_raise(ERR_LIB_CONF, ERR_R_MALLOC_FAILURE);
341
0
        goto err;
342
0
    }
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_MALLOC_FAILURE);
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_MALLOC_FAILURE);
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
0
}
473
474
/*
475
 * Unload any dynamic modules that have a link count of zero: i.e. have no
476
 * active initialized modules. If 'all' is set then all modules are unloaded
477
 * including static ones.
478
 */
479
480
void CONF_modules_unload(int all)
481
24
{
482
24
    int i;
483
24
    CONF_MODULE *md;
484
485
24
    if (!conf_modules_finish_int()) /* also inits module list lock */
486
0
        return;
487
488
24
    if (!CRYPTO_THREAD_write_lock(module_list_lock))
489
0
        return;
490
491
    /* unload modules in reverse order */
492
24
    for (i = sk_CONF_MODULE_num(supported_modules) - 1; i >= 0; i--) {
493
0
        md = sk_CONF_MODULE_value(supported_modules, i);
494
        /* If static or in use and 'all' not set ignore it */
495
0
        if (((md->links > 0) || !md->dso) && !all)
496
0
            continue;
497
        /* Since we're working in reverse this is OK */
498
0
        (void)sk_CONF_MODULE_delete(supported_modules, i);
499
0
        module_free(md);
500
0
    }
501
502
24
    if (sk_CONF_MODULE_num(supported_modules) == 0) {
503
0
        sk_CONF_MODULE_free(supported_modules);
504
0
        supported_modules = NULL;
505
0
    }
506
507
24
    CRYPTO_THREAD_unlock(module_list_lock);
508
24
}
509
510
/* unload a single module */
511
static void module_free(CONF_MODULE *md)
512
0
{
513
0
    DSO_free(md->dso);
514
0
    OPENSSL_free(md->name);
515
0
    OPENSSL_free(md);
516
0
}
517
518
/* finish and free up all modules instances */
519
520
static int conf_modules_finish_int(void)
521
24
{
522
24
    CONF_IMODULE *imod;
523
524
24
    if (!RUN_ONCE(&init_module_list_lock, do_init_module_list_lock))
525
0
        return 0;
526
527
    /* If module_list_lock is NULL here it means we were already unloaded */
528
24
    if (module_list_lock == NULL
529
24
        || !CRYPTO_THREAD_write_lock(module_list_lock))
530
0
        return 0;
531
532
24
    while (sk_CONF_IMODULE_num(initialized_modules) > 0) {
533
0
        imod = sk_CONF_IMODULE_pop(initialized_modules);
534
0
        module_finish(imod);
535
0
    }
536
24
    sk_CONF_IMODULE_free(initialized_modules);
537
24
    initialized_modules = NULL;
538
539
24
    CRYPTO_THREAD_unlock(module_list_lock);
540
541
24
    return 1;
542
24
}
543
544
void CONF_modules_finish(void)
545
0
{
546
0
    conf_modules_finish_int();
547
0
}
548
549
/* finish a module instance */
550
551
static void module_finish(CONF_IMODULE *imod)
552
0
{
553
0
    if (!imod)
554
0
        return;
555
0
    if (imod->pmod->finish)
556
0
        imod->pmod->finish(imod);
557
0
    imod->pmod->links--;
558
0
    OPENSSL_free(imod->name);
559
0
    OPENSSL_free(imod->value);
560
0
    OPENSSL_free(imod);
561
0
}
562
563
/* Add a static module to OpenSSL */
564
565
int CONF_module_add(const char *name, conf_init_func *ifunc,
566
    conf_finish_func *ffunc)
567
0
{
568
0
    if (module_add(NULL, name, ifunc, ffunc))
569
0
        return 1;
570
0
    else
571
0
        return 0;
572
0
}
573
574
void ossl_config_modules_free(void)
575
220
{
576
220
    CONF_modules_unload(1); /* calls CONF_modules_finish */
577
220
    module_lists_free();
578
220
}
579
580
/* Utility functions */
581
582
const char *CONF_imodule_get_name(const CONF_IMODULE *md)
583
0
{
584
0
    return md->name;
585
0
}
586
587
const char *CONF_imodule_get_value(const CONF_IMODULE *md)
588
0
{
589
0
    return md->value;
590
0
}
591
592
void *CONF_imodule_get_usr_data(const CONF_IMODULE *md)
593
0
{
594
0
    return md->usr_data;
595
0
}
596
597
void CONF_imodule_set_usr_data(CONF_IMODULE *md, void *usr_data)
598
0
{
599
0
    md->usr_data = usr_data;
600
0
}
601
602
CONF_MODULE *CONF_imodule_get_module(const CONF_IMODULE *md)
603
0
{
604
0
    return md->pmod;
605
0
}
606
607
unsigned long CONF_imodule_get_flags(const CONF_IMODULE *md)
608
0
{
609
0
    return md->flags;
610
0
}
611
612
void CONF_imodule_set_flags(CONF_IMODULE *md, unsigned long flags)
613
0
{
614
0
    md->flags = flags;
615
0
}
616
617
void *CONF_module_get_usr_data(CONF_MODULE *pmod)
618
0
{
619
0
    return pmod->usr_data;
620
0
}
621
622
void CONF_module_set_usr_data(CONF_MODULE *pmod, void *usr_data)
623
0
{
624
0
    pmod->usr_data = usr_data;
625
0
}
626
627
/* Return default config file name */
628
char *CONF_get1_default_config_file(void)
629
42
{
630
42
    const char *t;
631
42
    char *file, *sep = "";
632
42
    size_t size;
633
634
42
    if ((file = ossl_safe_getenv("OPENSSL_CONF")) != NULL)
635
0
        return OPENSSL_strdup(file);
636
637
42
    t = X509_get_default_cert_area();
638
42
#ifndef OPENSSL_SYS_VMS
639
42
    sep = "/";
640
42
#endif
641
42
    size = strlen(t) + strlen(sep) + strlen(OPENSSL_CONF) + 1;
642
42
    file = OPENSSL_malloc(size);
643
644
42
    if (file == NULL)
645
0
        return NULL;
646
42
    BIO_snprintf(file, size, "%s%s%s", t, sep, OPENSSL_CONF);
647
648
42
    return file;
649
42
}
650
651
/*
652
 * This function takes a list separated by 'sep' and calls the callback
653
 * function giving the start and length of each member optionally stripping
654
 * leading and trailing whitespace. This can be used to parse comma separated
655
 * lists for example.
656
 */
657
658
int CONF_parse_list(const char *list_, int sep, int nospc,
659
    int (*list_cb)(const char *elem, int len, void *usr),
660
    void *arg)
661
617k
{
662
617k
    int ret;
663
617k
    const char *lstart, *tmpend, *p;
664
665
617k
    if (list_ == NULL) {
666
0
        ERR_raise(ERR_LIB_CONF, CONF_R_LIST_CANNOT_BE_NULL);
667
0
        return 0;
668
0
    }
669
670
617k
    lstart = list_;
671
1.57M
    for (;;) {
672
1.57M
        if (nospc) {
673
1.85M
            while (*lstart && isspace((unsigned char)*lstart))
674
272k
                lstart++;
675
1.57M
        }
676
1.57M
        p = strchr(lstart, sep);
677
1.57M
        if (p == lstart || *lstart == '\0')
678
0
            ret = list_cb(NULL, 0, arg);
679
1.57M
        else {
680
1.57M
            if (p)
681
961k
                tmpend = p - 1;
682
617k
            else
683
617k
                tmpend = lstart + strlen(lstart) - 1;
684
1.57M
            if (nospc) {
685
1.57M
                while (isspace((unsigned char)*tmpend))
686
272k
                    tmpend--;
687
1.57M
            }
688
1.57M
            ret = list_cb(lstart, tmpend - lstart + 1, arg);
689
1.57M
        }
690
1.57M
        if (ret <= 0)
691
0
            return ret;
692
1.57M
        if (p == NULL)
693
617k
            return 1;
694
961k
        lstart = p + 1;
695
961k
    }
696
617k
}