You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

742 lines
18 KiB

  1. /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  2. * All rights reserved.
  3. *
  4. * This package is an SSL implementation written
  5. * by Eric Young (eay@cryptsoft.com).
  6. * The implementation was written so as to conform with Netscapes SSL.
  7. *
  8. * This library is free for commercial and non-commercial use as long as
  9. * the following conditions are aheared to. The following conditions
  10. * apply to all code found in this distribution, be it the RC4, RSA,
  11. * lhash, DES, etc., code; not just the SSL code. The SSL documentation
  12. * included with this distribution is covered by the same copyright terms
  13. * except that the holder is Tim Hudson (tjh@cryptsoft.com).
  14. *
  15. * Copyright remains Eric Young's, and as such any Copyright notices in
  16. * the code are not to be removed.
  17. * If this package is used in a product, Eric Young should be given attribution
  18. * as the author of the parts of the library used.
  19. * This can be in the form of a textual message at program startup or
  20. * in documentation (online or textual) provided with the package.
  21. *
  22. * Redistribution and use in source and binary forms, with or without
  23. * modification, are permitted provided that the following conditions
  24. * are met:
  25. * 1. Redistributions of source code must retain the copyright
  26. * notice, this list of conditions and the following disclaimer.
  27. * 2. Redistributions in binary form must reproduce the above copyright
  28. * notice, this list of conditions and the following disclaimer in the
  29. * documentation and/or other materials provided with the distribution.
  30. * 3. All advertising materials mentioning features or use of this software
  31. * must display the following acknowledgement:
  32. * "This product includes cryptographic software written by
  33. * Eric Young (eay@cryptsoft.com)"
  34. * The word 'cryptographic' can be left out if the rouines from the library
  35. * being used are not cryptographic related :-).
  36. * 4. If you include any Windows specific code (or a derivative thereof) from
  37. * the apps directory (application code) you must include an acknowledgement:
  38. * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
  39. *
  40. * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
  41. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  42. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  43. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  44. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  45. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  46. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  47. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  48. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  49. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  50. * SUCH DAMAGE.
  51. *
  52. * The licence and distribution terms for any publically available version or
  53. * derivative of this code cannot be changed. i.e. this code cannot simply be
  54. * copied and put under another distribution licence
  55. * [including the GNU Public Licence.] */
  56. #include <openssl/conf.h>
  57. #include <string.h>
  58. #include <ctype.h>
  59. #include <openssl/bio.h>
  60. #include <openssl/buf.h>
  61. #include <openssl/err.h>
  62. #include <openssl/mem.h>
  63. #include "conf_def.h"
  64. static uint32_t conf_value_hash(const CONF_VALUE *v) {
  65. return (lh_strhash(v->section) << 2) ^ lh_strhash(v->name);
  66. }
  67. static int conf_value_cmp(const CONF_VALUE *a, const CONF_VALUE *b) {
  68. int i;
  69. if (a->section != b->section) {
  70. i = strcmp(a->section, b->section);
  71. if (i) {
  72. return i;
  73. }
  74. }
  75. if (a->name != NULL && b->name != NULL) {
  76. return strcmp(a->name, b->name);
  77. } else if (a->name == b->name) {
  78. return 0;
  79. } else {
  80. return (a->name == NULL) ? -1 : 1;
  81. }
  82. }
  83. CONF *NCONF_new() {
  84. CONF *conf;
  85. conf = OPENSSL_malloc(sizeof(CONF));
  86. if (conf == NULL) {
  87. return NULL;
  88. }
  89. conf->data = lh_CONF_VALUE_new(conf_value_hash, conf_value_cmp);
  90. if (conf->data == NULL) {
  91. OPENSSL_free(conf);
  92. return NULL;
  93. }
  94. return conf;
  95. }
  96. static void value_free_contents(CONF_VALUE *value) {
  97. if (value->section) {
  98. OPENSSL_free(value->section);
  99. }
  100. if (value->name) {
  101. OPENSSL_free(value->name);
  102. if (value->value) {
  103. OPENSSL_free(value->value);
  104. }
  105. } else {
  106. if (value->value) {
  107. sk_CONF_VALUE_free((STACK_OF(CONF_VALUE)*)value->value);
  108. }
  109. }
  110. }
  111. static void value_free(CONF_VALUE *value) {
  112. value_free_contents(value);
  113. OPENSSL_free(value);
  114. }
  115. void NCONF_free(CONF *conf) {
  116. if (conf == NULL || conf->data == NULL) {
  117. return;
  118. }
  119. lh_CONF_VALUE_doall(conf->data, value_free_contents);
  120. lh_CONF_VALUE_free(conf->data);
  121. OPENSSL_free(conf);
  122. }
  123. CONF_VALUE *NCONF_new_section(const CONF *conf, const char *section) {
  124. STACK_OF(CONF_VALUE) *sk = NULL;
  125. int ok = 0, i;
  126. CONF_VALUE *v = NULL, *old_value;
  127. sk = sk_CONF_VALUE_new_null();
  128. v = OPENSSL_malloc(sizeof(CONF_VALUE));
  129. if (sk == NULL || v == NULL) {
  130. goto err;
  131. }
  132. i = strlen(section) + 1;
  133. v->section = OPENSSL_malloc(i);
  134. if (v->section == NULL) {
  135. goto err;
  136. }
  137. memcpy(v->section, section, i);
  138. v->section[i-1] = 0;
  139. v->name = NULL;
  140. v->value = (char *)sk;
  141. if (!lh_CONF_VALUE_insert(conf->data, &old_value, v)) {
  142. goto err;
  143. }
  144. if (old_value) {
  145. value_free(old_value);
  146. }
  147. ok = 1;
  148. err:
  149. if (!ok) {
  150. if (sk != NULL) {
  151. sk_CONF_VALUE_free(sk);
  152. }
  153. if (v != NULL) {
  154. OPENSSL_free(v);
  155. }
  156. v = NULL;
  157. }
  158. return v;
  159. }
  160. static int str_copy(CONF *conf, char *section, char **pto, char *from) {
  161. int q, r, rr = 0, to = 0, len = 0;
  162. char *s, *e, *rp, *rrp, *np, *cp, v;
  163. const char *p;
  164. BUF_MEM *buf;
  165. buf = BUF_MEM_new();
  166. if (buf == NULL) {
  167. return 0;
  168. }
  169. len = strlen(from) + 1;
  170. if (!BUF_MEM_grow(buf, len)) {
  171. goto err;
  172. }
  173. for (;;) {
  174. if (IS_QUOTE(conf, *from)) {
  175. q = *from;
  176. from++;
  177. while (!IS_EOF(conf, *from) && (*from != q)) {
  178. if (IS_ESC(conf, *from)) {
  179. from++;
  180. if (IS_EOF(conf, *from)) {
  181. break;
  182. }
  183. }
  184. buf->data[to++] = *(from++);
  185. }
  186. if (*from == q) {
  187. from++;
  188. }
  189. } else if (IS_DQUOTE(conf, *from)) {
  190. q = *from;
  191. from++;
  192. while (!IS_EOF(conf, *from)) {
  193. if (*from == q) {
  194. if (*(from + 1) == q) {
  195. from++;
  196. } else {
  197. break;
  198. }
  199. }
  200. buf->data[to++] = *(from++);
  201. }
  202. if (*from == q) {
  203. from++;
  204. }
  205. } else if (IS_ESC(conf, *from)) {
  206. from++;
  207. v = *(from++);
  208. if (IS_EOF(conf, v)) {
  209. break;
  210. } else if (v == 'r') {
  211. v = '\r';
  212. } else if (v == 'n') {
  213. v = '\n';
  214. } else if (v == 'b') {
  215. v = '\b';
  216. } else if (v == 't') {
  217. v = '\t';
  218. }
  219. buf->data[to++] = v;
  220. } else if (IS_EOF(conf, *from)) {
  221. break;
  222. } else if (*from == '$') {
  223. /* try to expand it */
  224. rrp = NULL;
  225. s = &(from[1]);
  226. if (*s == '{') {
  227. q = '}';
  228. } else if (*s == '(') {
  229. q = ')';
  230. } else {
  231. q = 0;
  232. }
  233. if (q) {
  234. s++;
  235. }
  236. cp = section;
  237. e = np = s;
  238. while (IS_ALPHA_NUMERIC(conf, *e)) {
  239. e++;
  240. }
  241. if (e[0] == ':' && e[1] == ':') {
  242. cp = np;
  243. rrp = e;
  244. rr = *e;
  245. *rrp = '\0';
  246. e += 2;
  247. np = e;
  248. while (IS_ALPHA_NUMERIC(conf, *e)) {
  249. e++;
  250. }
  251. }
  252. r = *e;
  253. *e = '\0';
  254. rp = e;
  255. if (q) {
  256. if (r != q) {
  257. OPENSSL_PUT_ERROR(CONF, str_copy, CONF_R_NO_CLOSE_BRACE);
  258. goto err;
  259. }
  260. e++;
  261. }
  262. /* So at this point we have
  263. * np which is the start of the name string which is
  264. * '\0' terminated.
  265. * cp which is the start of the section string which is
  266. * '\0' terminated.
  267. * e is the 'next point after'.
  268. * r and rr are the chars replaced by the '\0'
  269. * rp and rrp is where 'r' and 'rr' came from. */
  270. p = NCONF_get_string(conf, cp, np);
  271. if (rrp != NULL) {
  272. *rrp = rr;
  273. }
  274. *rp = r;
  275. if (p == NULL) {
  276. OPENSSL_PUT_ERROR(CONF, str_copy, CONF_R_VARIABLE_HAS_NO_VALUE);
  277. goto err;
  278. }
  279. BUF_MEM_grow_clean(buf, (strlen(p) + buf->length - (e - from)));
  280. while (*p) {
  281. buf->data[to++] = *(p++);
  282. }
  283. /* Since we change the pointer 'from', we also have
  284. to change the perceived length of the string it
  285. points at. /RL */
  286. len -= e - from;
  287. from = e;
  288. /* In case there were no braces or parenthesis around
  289. the variable reference, we have to put back the
  290. character that was replaced with a '\0'. /RL */
  291. *rp = r;
  292. } else {
  293. buf->data[to++] = *(from++);
  294. }
  295. }
  296. buf->data[to] = '\0';
  297. if (*pto != NULL) {
  298. OPENSSL_free(*pto);
  299. }
  300. *pto = buf->data;
  301. OPENSSL_free(buf);
  302. return 1;
  303. err:
  304. if (buf != NULL) {
  305. BUF_MEM_free(buf);
  306. }
  307. return 0;
  308. }
  309. static CONF_VALUE *get_section(const CONF *conf, const char *section) {
  310. CONF_VALUE template;
  311. memset(&template, 0, sizeof(template));
  312. template.section = (char *) section;
  313. return lh_CONF_VALUE_retrieve(conf->data, &template);
  314. }
  315. STACK_OF(CONF_VALUE) *NCONF_get_section(const CONF *conf, const char *section) {
  316. CONF_VALUE *section_value = get_section(conf, section);
  317. if (section_value == NULL) {
  318. return NULL;
  319. }
  320. return (STACK_OF(CONF_VALUE)*) section_value->value;
  321. }
  322. const char *NCONF_get_string(const CONF *conf, const char *section,
  323. const char *name) {
  324. CONF_VALUE template, *value;
  325. memset(&template, 0, sizeof(template));
  326. template.section = (char *) section;
  327. template.name = (char *) name;
  328. value = lh_CONF_VALUE_retrieve(conf->data, &template);
  329. if (value == NULL) {
  330. return NULL;
  331. }
  332. return value->value;
  333. }
  334. int add_string(const CONF *conf, CONF_VALUE *section, CONF_VALUE *value) {
  335. STACK_OF(CONF_VALUE) *section_stack = (STACK_OF(CONF_VALUE)*) section->value;
  336. CONF_VALUE *old_value;
  337. value->section = section->section;
  338. if (!sk_CONF_VALUE_push(section_stack, value)) {
  339. return 0;
  340. }
  341. if (!lh_CONF_VALUE_insert(conf->data, &old_value, value)) {
  342. return 0;
  343. }
  344. if (old_value != NULL) {
  345. (void)sk_CONF_VALUE_delete_ptr(section_stack, old_value);
  346. value_free(old_value);
  347. }
  348. return 1;
  349. }
  350. static char *eat_ws(CONF *conf, char *p) {
  351. while (IS_WS(conf, *p) && !IS_EOF(conf, *p)) {
  352. p++;
  353. }
  354. return p;
  355. }
  356. #define scan_esc(conf, p) (((IS_EOF((conf), (p)[1])) ? ((p) + 1) : ((p) + 2)))
  357. static char *eat_alpha_numeric(CONF *conf, char *p) {
  358. for (;;) {
  359. if (IS_ESC(conf, *p)) {
  360. p = scan_esc(conf, p);
  361. continue;
  362. }
  363. if (!IS_ALPHA_NUMERIC_PUNCT(conf, *p)) {
  364. return p;
  365. }
  366. p++;
  367. }
  368. }
  369. static char *scan_quote(CONF *conf, char *p) {
  370. int q = *p;
  371. p++;
  372. while (!IS_EOF(conf, *p) && *p != q) {
  373. if (IS_ESC(conf, *p)) {
  374. p++;
  375. if (IS_EOF(conf, *p)) {
  376. return p;
  377. }
  378. }
  379. p++;
  380. }
  381. if (*p == q) {
  382. p++;
  383. }
  384. return p;
  385. }
  386. static char *scan_dquote(CONF *conf, char *p) {
  387. int q = *p;
  388. p++;
  389. while (!(IS_EOF(conf, *p))) {
  390. if (*p == q) {
  391. if (*(p + 1) == q) {
  392. p++;
  393. } else {
  394. break;
  395. }
  396. }
  397. p++;
  398. }
  399. if (*p == q) {
  400. p++;
  401. }
  402. return p;
  403. }
  404. static void clear_comments(CONF *conf, char *p) {
  405. for (;;) {
  406. if (IS_FCOMMENT(conf, *p)) {
  407. *p = '\0';
  408. return;
  409. }
  410. if (!IS_WS(conf, *p)) {
  411. break;
  412. }
  413. p++;
  414. }
  415. for (;;) {
  416. if (IS_COMMENT(conf, *p)) {
  417. *p = '\0';
  418. return;
  419. }
  420. if (IS_DQUOTE(conf, *p)) {
  421. p = scan_dquote(conf, p);
  422. continue;
  423. }
  424. if (IS_QUOTE(conf, *p)) {
  425. p = scan_quote(conf, p);
  426. continue;
  427. }
  428. if (IS_ESC(conf, *p)) {
  429. p = scan_esc(conf, p);
  430. continue;
  431. }
  432. if (IS_EOF(conf, *p)) {
  433. return;
  434. } else {
  435. p++;
  436. }
  437. }
  438. }
  439. static int def_load_bio(CONF *conf, BIO *in, long *out_error_line) {
  440. static const size_t CONFBUFSIZE = 512;
  441. int bufnum = 0, i, ii;
  442. BUF_MEM *buff = NULL;
  443. char *s, *p, *end;
  444. int again;
  445. long eline = 0;
  446. char btmp[DECIMAL_SIZE(eline) + 1];
  447. CONF_VALUE *v = NULL, *tv;
  448. CONF_VALUE *sv = NULL;
  449. char *section = NULL, *buf;
  450. char *start, *psection, *pname;
  451. if ((buff = BUF_MEM_new()) == NULL) {
  452. OPENSSL_PUT_ERROR(CONF, def_load_bio, ERR_R_BUF_LIB);
  453. goto err;
  454. }
  455. section = (char *)OPENSSL_malloc(10);
  456. if (section == NULL) {
  457. OPENSSL_PUT_ERROR(CONF, def_load_bio, ERR_R_MALLOC_FAILURE);
  458. goto err;
  459. }
  460. BUF_strlcpy(section, "default", 10);
  461. sv = NCONF_new_section(conf, section);
  462. if (sv == NULL) {
  463. OPENSSL_PUT_ERROR(CONF, def_load_bio, CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
  464. goto err;
  465. }
  466. bufnum = 0;
  467. again = 0;
  468. for (;;) {
  469. if (!BUF_MEM_grow(buff, bufnum + CONFBUFSIZE)) {
  470. OPENSSL_PUT_ERROR(CONF, def_load_bio, ERR_R_BUF_LIB);
  471. goto err;
  472. }
  473. p = &(buff->data[bufnum]);
  474. *p = '\0';
  475. BIO_gets(in, p, CONFBUFSIZE - 1);
  476. p[CONFBUFSIZE - 1] = '\0';
  477. ii = i = strlen(p);
  478. if (i == 0 && !again)
  479. break;
  480. again = 0;
  481. while (i > 0) {
  482. if ((p[i - 1] != '\r') && (p[i - 1] != '\n'))
  483. break;
  484. else
  485. i--;
  486. }
  487. /* we removed some trailing stuff so there is a new
  488. * line on the end. */
  489. if (ii && i == ii)
  490. again = 1; /* long line */
  491. else {
  492. p[i] = '\0';
  493. eline++; /* another input line */
  494. }
  495. /* we now have a line with trailing \r\n removed */
  496. /* i is the number of bytes */
  497. bufnum += i;
  498. v = NULL;
  499. /* check for line continuation */
  500. if (bufnum >= 1) {
  501. /* If we have bytes and the last char '\\' and
  502. * second last char is not '\\' */
  503. p = &(buff->data[bufnum - 1]);
  504. if (IS_ESC(conf, p[0]) && ((bufnum <= 1) || !IS_ESC(conf, p[-1]))) {
  505. bufnum--;
  506. again = 1;
  507. }
  508. }
  509. if (again)
  510. continue;
  511. bufnum = 0;
  512. buf = buff->data;
  513. clear_comments(conf, buf);
  514. s = eat_ws(conf, buf);
  515. if (IS_EOF(conf, *s))
  516. continue; /* blank line */
  517. if (*s == '[') {
  518. char *ss;
  519. s++;
  520. start = eat_ws(conf, s);
  521. ss = start;
  522. again:
  523. end = eat_alpha_numeric(conf, ss);
  524. p = eat_ws(conf, end);
  525. if (*p != ']') {
  526. if (*p != '\0') {
  527. ss = p;
  528. goto again;
  529. }
  530. OPENSSL_PUT_ERROR(CONF, def_load_bio, CONF_R_MISSING_CLOSE_SQUARE_BRACKET);
  531. goto err;
  532. }
  533. *end = '\0';
  534. if (!str_copy(conf, NULL, &section, start))
  535. goto err;
  536. if ((sv = get_section(conf, section)) == NULL)
  537. sv = NCONF_new_section(conf, section);
  538. if (sv == NULL) {
  539. OPENSSL_PUT_ERROR(CONF, def_load_bio, CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
  540. goto err;
  541. }
  542. continue;
  543. } else {
  544. pname = s;
  545. psection = NULL;
  546. end = eat_alpha_numeric(conf, s);
  547. if ((end[0] == ':') && (end[1] == ':')) {
  548. *end = '\0';
  549. end += 2;
  550. psection = pname;
  551. pname = end;
  552. end = eat_alpha_numeric(conf, end);
  553. }
  554. p = eat_ws(conf, end);
  555. if (*p != '=') {
  556. OPENSSL_PUT_ERROR(CONF, def_load_bio, CONF_R_MISSING_EQUAL_SIGN);
  557. goto err;
  558. }
  559. *end = '\0';
  560. p++;
  561. start = eat_ws(conf, p);
  562. while (!IS_EOF(conf, *p))
  563. p++;
  564. p--;
  565. while ((p != start) && (IS_WS(conf, *p)))
  566. p--;
  567. p++;
  568. *p = '\0';
  569. if (!(v = (CONF_VALUE *)OPENSSL_malloc(sizeof(CONF_VALUE)))) {
  570. OPENSSL_PUT_ERROR(CONF, def_load_bio, ERR_R_MALLOC_FAILURE);
  571. goto err;
  572. }
  573. if (psection == NULL)
  574. psection = section;
  575. v->name = (char *)OPENSSL_malloc(strlen(pname) + 1);
  576. v->value = NULL;
  577. if (v->name == NULL) {
  578. OPENSSL_PUT_ERROR(CONF, def_load_bio, ERR_R_MALLOC_FAILURE);
  579. goto err;
  580. }
  581. BUF_strlcpy(v->name, pname, strlen(pname) + 1);
  582. if (!str_copy(conf, psection, &(v->value), start))
  583. goto err;
  584. if (strcmp(psection, section) != 0) {
  585. if ((tv = get_section(conf, psection)) == NULL)
  586. tv = NCONF_new_section(conf, psection);
  587. if (tv == NULL) {
  588. OPENSSL_PUT_ERROR(CONF, def_load_bio, CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
  589. goto err;
  590. }
  591. } else
  592. tv = sv;
  593. if (add_string(conf, tv, v) == 0) {
  594. OPENSSL_PUT_ERROR(CONF, def_load_bio, ERR_R_MALLOC_FAILURE);
  595. goto err;
  596. }
  597. v = NULL;
  598. }
  599. }
  600. if (buff != NULL)
  601. BUF_MEM_free(buff);
  602. if (section != NULL)
  603. OPENSSL_free(section);
  604. return 1;
  605. err:
  606. if (buff != NULL)
  607. BUF_MEM_free(buff);
  608. if (section != NULL)
  609. OPENSSL_free(section);
  610. if (out_error_line != NULL)
  611. *out_error_line = eline;
  612. BIO_snprintf(btmp, sizeof btmp, "%ld", eline);
  613. ERR_add_error_data(2, "line ", btmp);
  614. if (v != NULL) {
  615. if (v->name != NULL)
  616. OPENSSL_free(v->name);
  617. if (v->value != NULL)
  618. OPENSSL_free(v->value);
  619. if (v != NULL)
  620. OPENSSL_free(v);
  621. }
  622. return 0;
  623. }
  624. int NCONF_load(CONF *conf, const char *filename, long *out_error_line) {
  625. BIO *in = BIO_new_file(filename, "rb");
  626. int ret;
  627. if (in == NULL) {
  628. OPENSSL_PUT_ERROR(CONF, NCONF_load, ERR_R_SYS_LIB);
  629. return 0;
  630. }
  631. ret = def_load_bio(conf, in, out_error_line);
  632. BIO_free(in);
  633. return ret;
  634. }
  635. int CONF_parse_list(const char *list, char sep, int remove_whitespace,
  636. int (*list_cb)(const char *elem, int len, void *usr),
  637. void *arg) {
  638. int ret;
  639. const char *lstart, *tmpend, *p;
  640. if (list == NULL) {
  641. OPENSSL_PUT_ERROR(CONF, CONF_parse_list, CONF_R_LIST_CANNOT_BE_NULL);
  642. return 0;
  643. }
  644. lstart = list;
  645. for (;;) {
  646. if (remove_whitespace) {
  647. while (*lstart && isspace((unsigned char)*lstart))
  648. lstart++;
  649. }
  650. p = strchr(lstart, sep);
  651. if (p == lstart || !*lstart)
  652. ret = list_cb(NULL, 0, arg);
  653. else {
  654. if (p)
  655. tmpend = p - 1;
  656. else
  657. tmpend = lstart + strlen(lstart) - 1;
  658. if (remove_whitespace) {
  659. while (isspace((unsigned char)*tmpend))
  660. tmpend--;
  661. }
  662. ret = list_cb(lstart, tmpend - lstart + 1, arg);
  663. }
  664. if (ret <= 0)
  665. return ret;
  666. if (p == NULL)
  667. return 1;
  668. lstart = p + 1;
  669. }
  670. }