magic.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. /*
  2. * Copyright (c) Christos Zoulas 2003.
  3. * All Rights Reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice immediately at the beginning of the file, without modification,
  10. * this list of conditions, and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  16. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
  19. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  21. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  22. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  23. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  24. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  25. * SUCH DAMAGE.
  26. */
  27. #ifdef WIN32
  28. #include <windows.h>
  29. #include <shlwapi.h>
  30. #endif
  31. #include "file.h"
  32. #ifndef lint
  33. FILE_RCSID("@(#)$File: magic.c,v 1.115 2021/09/20 17:45:41 christos Exp $")
  34. #endif /* lint */
  35. #include "magic.h"
  36. #include <stdlib.h>
  37. #include <unistd.h>
  38. #include <string.h>
  39. #ifdef QUICK
  40. #include <sys/mman.h>
  41. #endif
  42. #include <limits.h> /* for PIPE_BUF */
  43. #if defined(HAVE_UTIMES)
  44. # include <sys/time.h>
  45. #elif defined(HAVE_UTIME)
  46. # if defined(HAVE_SYS_UTIME_H)
  47. # include <sys/utime.h>
  48. # elif defined(HAVE_UTIME_H)
  49. # include <utime.h>
  50. # endif
  51. #endif
  52. #ifdef HAVE_UNISTD_H
  53. #include <unistd.h> /* for read() */
  54. #endif
  55. #ifndef PIPE_BUF
  56. /* Get the PIPE_BUF from pathconf */
  57. #ifdef _PC_PIPE_BUF
  58. #define PIPE_BUF pathconf(".", _PC_PIPE_BUF)
  59. #else
  60. #define PIPE_BUF 512
  61. #endif
  62. #endif
  63. private void close_and_restore(const struct magic_set *, const char *, int,
  64. const struct stat *);
  65. private int unreadable_info(struct magic_set *, mode_t, const char *);
  66. private const char* get_default_magic(void);
  67. #ifndef COMPILE_ONLY
  68. private const char *file_or_fd(struct magic_set *, const char *, int);
  69. #endif
  70. #ifndef STDIN_FILENO
  71. #define STDIN_FILENO 0
  72. #endif
  73. #ifdef WIN32
  74. /* HINSTANCE of this shared library. Needed for get_default_magic() */
  75. static HINSTANCE _w32_dll_instance = NULL;
  76. static void
  77. _w32_append_path(char **hmagicpath, const char *fmt, ...)
  78. {
  79. char *tmppath;
  80. char *newpath;
  81. va_list ap;
  82. va_start(ap, fmt);
  83. if (vasprintf(&tmppath, fmt, ap) < 0) {
  84. va_end(ap);
  85. return;
  86. }
  87. va_end(ap);
  88. if (access(tmppath, R_OK) == -1)
  89. goto out;
  90. if (*hmagicpath == NULL) {
  91. *hmagicpath = tmppath;
  92. return;
  93. }
  94. if (asprintf(&newpath, "%s%c%s", *hmagicpath, PATHSEP, tmppath) < 0)
  95. goto out;
  96. free(*hmagicpath);
  97. free(tmppath);
  98. *hmagicpath = newpath;
  99. return;
  100. out:
  101. free(tmppath);
  102. }
  103. static void
  104. _w32_get_magic_relative_to(char **hmagicpath, HINSTANCE module)
  105. {
  106. static const char *trypaths[] = {
  107. "%s/share/misc/magic.mgc",
  108. "%s/magic.mgc",
  109. };
  110. LPSTR dllpath;
  111. size_t sp;
  112. dllpath = calloc(MAX_PATH + 1, sizeof(*dllpath));
  113. if (!GetModuleFileNameA(module, dllpath, MAX_PATH))
  114. goto out;
  115. PathRemoveFileSpecA(dllpath);
  116. if (module) {
  117. char exepath[MAX_PATH];
  118. GetModuleFileNameA(NULL, exepath, MAX_PATH);
  119. PathRemoveFileSpecA(exepath);
  120. if (stricmp(exepath, dllpath) == 0)
  121. goto out;
  122. }
  123. sp = strlen(dllpath);
  124. if (sp > 3 && stricmp(&dllpath[sp - 3], "bin") == 0) {
  125. _w32_append_path(hmagicpath,
  126. "%s/../share/misc/magic.mgc", dllpath);
  127. goto out;
  128. }
  129. for (sp = 0; sp < __arraycount(trypaths); sp++)
  130. _w32_append_path(hmagicpath, trypaths[sp], dllpath);
  131. out:
  132. free(dllpath);
  133. }
  134. #ifndef BUILD_AS_WINDOWS_STATIC_LIBARAY
  135. /* Placate GCC by offering a sacrificial previous prototype */
  136. BOOL WINAPI DllMain(HINSTANCE, DWORD, LPVOID);
  137. BOOL WINAPI
  138. DllMain(HINSTANCE hinstDLL, DWORD fdwReason,
  139. LPVOID lpvReserved __attribute__((__unused__)))
  140. {
  141. if (fdwReason == DLL_PROCESS_ATTACH)
  142. _w32_dll_instance = hinstDLL;
  143. return 1;
  144. }
  145. #endif
  146. #endif
  147. private const char *
  148. get_default_magic(void)
  149. {
  150. static const char hmagic[] = "/.magic/magic.mgc";
  151. static char *default_magic;
  152. char *home, *hmagicpath;
  153. #ifndef WIN32
  154. struct stat st;
  155. if (default_magic) {
  156. free(default_magic);
  157. default_magic = NULL;
  158. }
  159. if ((home = getenv("HOME")) == NULL)
  160. return MAGIC;
  161. if (asprintf(&hmagicpath, "%s/.magic.mgc", home) < 0)
  162. return MAGIC;
  163. if (stat(hmagicpath, &st) == -1) {
  164. free(hmagicpath);
  165. if (asprintf(&hmagicpath, "%s/.magic", home) < 0)
  166. return MAGIC;
  167. if (stat(hmagicpath, &st) == -1)
  168. goto out;
  169. if (S_ISDIR(st.st_mode)) {
  170. free(hmagicpath);
  171. if (asprintf(&hmagicpath, "%s/%s", home, hmagic) < 0)
  172. return MAGIC;
  173. if (access(hmagicpath, R_OK) == -1)
  174. goto out;
  175. }
  176. }
  177. if (asprintf(&default_magic, "%s:%s", hmagicpath, MAGIC) < 0)
  178. goto out;
  179. free(hmagicpath);
  180. return default_magic;
  181. out:
  182. default_magic = NULL;
  183. free(hmagicpath);
  184. return MAGIC;
  185. #else
  186. hmagicpath = NULL;
  187. if (default_magic) {
  188. free(default_magic);
  189. default_magic = NULL;
  190. }
  191. /* First, try to get a magic file from user-application data */
  192. if ((home = getenv("LOCALAPPDATA")) != NULL)
  193. _w32_append_path(&hmagicpath, "%s%s", home, hmagic);
  194. /* Second, try to get a magic file from the user profile data */
  195. if ((home = getenv("USERPROFILE")) != NULL)
  196. _w32_append_path(&hmagicpath,
  197. "%s/Local Settings/Application Data%s", home, hmagic);
  198. /* Third, try to get a magic file from Common Files */
  199. if ((home = getenv("COMMONPROGRAMFILES")) != NULL)
  200. _w32_append_path(&hmagicpath, "%s%s", home, hmagic);
  201. /* Fourth, try to get magic file relative to exe location */
  202. _w32_get_magic_relative_to(&hmagicpath, NULL);
  203. /* Fifth, try to get magic file relative to dll location */
  204. _w32_get_magic_relative_to(&hmagicpath, _w32_dll_instance);
  205. /* Avoid MAGIC constant - it likely points to a file within MSys tree */
  206. default_magic = hmagicpath;
  207. return default_magic;
  208. #endif
  209. }
  210. public const char *
  211. magic_getpath(const char *magicfile, int action)
  212. {
  213. if (magicfile != NULL)
  214. return magicfile;
  215. magicfile = getenv("MAGIC");
  216. if (magicfile != NULL)
  217. return magicfile;
  218. return action == FILE_LOAD ? get_default_magic() : MAGIC;
  219. }
  220. public struct magic_set *
  221. magic_open(int flags)
  222. {
  223. return file_ms_alloc(flags);
  224. }
  225. private int
  226. unreadable_info(struct magic_set *ms, mode_t md, const char *file)
  227. {
  228. if (file) {
  229. /* We cannot open it, but we were able to stat it. */
  230. if (access(file, W_OK) == 0)
  231. if (file_printf(ms, "writable, ") == -1)
  232. return -1;
  233. if (access(file, X_OK) == 0)
  234. if (file_printf(ms, "executable, ") == -1)
  235. return -1;
  236. }
  237. if (S_ISREG(md))
  238. if (file_printf(ms, "regular file, ") == -1)
  239. return -1;
  240. if (file_printf(ms, "no read permission") == -1)
  241. return -1;
  242. return 0;
  243. }
  244. public void
  245. magic_close(struct magic_set *ms)
  246. {
  247. if (ms == NULL)
  248. return;
  249. file_ms_free(ms);
  250. }
  251. /*
  252. * load a magic file
  253. */
  254. public int
  255. magic_load(struct magic_set *ms, const char *magicfile)
  256. {
  257. if (ms == NULL)
  258. return -1;
  259. return file_apprentice(ms, magicfile, FILE_LOAD);
  260. }
  261. #ifndef COMPILE_ONLY
  262. /*
  263. * Install a set of compiled magic buffers.
  264. */
  265. public int
  266. magic_load_buffers(struct magic_set *ms, void **bufs, size_t *sizes,
  267. size_t nbufs)
  268. {
  269. if (ms == NULL)
  270. return -1;
  271. return buffer_apprentice(ms, RCAST(struct magic **, bufs),
  272. sizes, nbufs);
  273. }
  274. #endif
  275. public int
  276. magic_compile(struct magic_set *ms, const char *magicfile)
  277. {
  278. if (ms == NULL)
  279. return -1;
  280. return file_apprentice(ms, magicfile, FILE_COMPILE);
  281. }
  282. public int
  283. magic_check(struct magic_set *ms, const char *magicfile)
  284. {
  285. if (ms == NULL)
  286. return -1;
  287. return file_apprentice(ms, magicfile, FILE_CHECK);
  288. }
  289. public int
  290. magic_list(struct magic_set *ms, const char *magicfile)
  291. {
  292. if (ms == NULL)
  293. return -1;
  294. return file_apprentice(ms, magicfile, FILE_LIST);
  295. }
  296. private void
  297. close_and_restore(const struct magic_set *ms, const char *name, int fd,
  298. const struct stat *sb)
  299. {
  300. if (fd == STDIN_FILENO || name == NULL)
  301. return;
  302. (void) close(fd);
  303. if ((ms->flags & MAGIC_PRESERVE_ATIME) != 0) {
  304. /*
  305. * Try to restore access, modification times if read it.
  306. * This is really *bad* because it will modify the status
  307. * time of the file... And of course this will affect
  308. * backup programs
  309. */
  310. #ifdef HAVE_UTIMES
  311. struct timeval utsbuf[2];
  312. (void)memset(utsbuf, 0, sizeof(utsbuf));
  313. utsbuf[0].tv_sec = sb->st_atime;
  314. utsbuf[1].tv_sec = sb->st_mtime;
  315. (void) utimes(name, utsbuf); /* don't care if loses */
  316. #elif defined(HAVE_UTIME_H) || defined(HAVE_SYS_UTIME_H)
  317. struct utimbuf utbuf;
  318. (void)memset(&utbuf, 0, sizeof(utbuf));
  319. utbuf.actime = sb->st_atime;
  320. utbuf.modtime = sb->st_mtime;
  321. (void) utime(name, &utbuf); /* don't care if loses */
  322. #endif
  323. }
  324. }
  325. #ifndef COMPILE_ONLY
  326. /*
  327. * find type of descriptor
  328. */
  329. public const char *
  330. magic_descriptor(struct magic_set *ms, int fd)
  331. {
  332. if (ms == NULL)
  333. return NULL;
  334. return file_or_fd(ms, NULL, fd);
  335. }
  336. /*
  337. * find type of named file
  338. */
  339. public const char *
  340. magic_file(struct magic_set *ms, const char *inname)
  341. {
  342. if (ms == NULL)
  343. return NULL;
  344. return file_or_fd(ms, inname, STDIN_FILENO);
  345. }
  346. private const char *
  347. file_or_fd(struct magic_set *ms, const char *inname, int fd)
  348. {
  349. int rv = -1;
  350. unsigned char *buf;
  351. struct stat sb;
  352. ssize_t nbytes = 0; /* number of bytes read from a datafile */
  353. int ispipe = 0;
  354. int okstat = 0;
  355. off_t pos = CAST(off_t, -1);
  356. if (file_reset(ms, 1) == -1)
  357. goto out;
  358. /*
  359. * one extra for terminating '\0', and
  360. * some overlapping space for matches near EOF
  361. */
  362. #define SLOP (1 + sizeof(union VALUETYPE))
  363. if ((buf = CAST(unsigned char *, malloc(ms->bytes_max + SLOP))) == NULL)
  364. return NULL;
  365. switch (file_fsmagic(ms, inname, &sb)) {
  366. case -1: /* error */
  367. goto done;
  368. case 0: /* nothing found */
  369. break;
  370. default: /* matched it and printed type */
  371. rv = 0;
  372. goto done;
  373. }
  374. #ifdef WIN32
  375. /* Place stdin in binary mode, so EOF (Ctrl+Z) doesn't stop early. */
  376. if (fd == STDIN_FILENO)
  377. _setmode(STDIN_FILENO, O_BINARY);
  378. #endif
  379. if (inname != NULL) {
  380. int flags = O_RDONLY|O_BINARY|O_NONBLOCK|O_CLOEXEC;
  381. errno = 0;
  382. if ((fd = open(inname, flags)) < 0) {
  383. okstat = stat(inname, &sb) == 0;
  384. if (okstat && S_ISFIFO(sb.st_mode))
  385. ispipe = 1;
  386. #ifdef WIN32
  387. /*
  388. * Can't stat, can't open. It may have been opened in
  389. * fsmagic, so if the user doesn't have read permission,
  390. * allow it to say so; otherwise an error was probably
  391. * displayed in fsmagic.
  392. */
  393. if (!okstat && errno == EACCES) {
  394. sb.st_mode = S_IFBLK;
  395. okstat = 1;
  396. }
  397. #endif
  398. if (okstat &&
  399. unreadable_info(ms, sb.st_mode, inname) == -1)
  400. goto done;
  401. rv = 0;
  402. goto done;
  403. }
  404. #if O_CLOEXEC == 0
  405. (void)fcntl(fd, F_SETFD, FD_CLOEXEC);
  406. #endif
  407. }
  408. if (fd != -1) {
  409. okstat = fstat(fd, &sb) == 0;
  410. if (okstat && S_ISFIFO(sb.st_mode))
  411. ispipe = 1;
  412. if (inname == NULL)
  413. pos = lseek(fd, CAST(off_t, 0), SEEK_CUR);
  414. }
  415. /*
  416. * try looking at the first ms->bytes_max bytes
  417. */
  418. if (ispipe) {
  419. if (fd != -1) {
  420. ssize_t r = 0;
  421. while ((r = sread(fd, RCAST(void *, &buf[nbytes]),
  422. CAST(size_t, ms->bytes_max - nbytes), 1)) > 0) {
  423. nbytes += r;
  424. if (r < PIPE_BUF) break;
  425. }
  426. }
  427. if (nbytes == 0 && inname) {
  428. /* We can not read it, but we were able to stat it. */
  429. if (unreadable_info(ms, sb.st_mode, inname) == -1)
  430. goto done;
  431. rv = 0;
  432. goto done;
  433. }
  434. } else if (fd != -1) {
  435. /* Windows refuses to read from a big console buffer. */
  436. size_t howmany =
  437. #if defined(WIN32)
  438. _isatty(fd) ? 8 * 1024 :
  439. #endif
  440. ms->bytes_max;
  441. if ((nbytes = read(fd, RCAST(void *, buf), howmany)) == -1) {
  442. if (inname == NULL && fd != STDIN_FILENO)
  443. file_error(ms, errno, "cannot read fd %d", fd);
  444. else
  445. file_error(ms, errno, "cannot read `%s'",
  446. inname == NULL ? "/dev/stdin" : inname);
  447. goto done;
  448. }
  449. }
  450. (void)memset(buf + nbytes, 0, SLOP); /* NUL terminate */
  451. if (file_buffer(ms, fd, okstat ? &sb : NULL, inname, buf, CAST(size_t, nbytes)) == -1)
  452. goto done;
  453. rv = 0;
  454. done:
  455. free(buf);
  456. if (fd != -1) {
  457. if (pos != CAST(off_t, -1))
  458. (void)lseek(fd, pos, SEEK_SET);
  459. close_and_restore(ms, inname, fd, &sb);
  460. }
  461. out:
  462. return rv == 0 ? file_getbuffer(ms) : NULL;
  463. }
  464. public const char *
  465. magic_buffer(struct magic_set *ms, const void *buf, size_t nb)
  466. {
  467. if (ms == NULL)
  468. return NULL;
  469. if (file_reset(ms, 1) == -1)
  470. return NULL;
  471. /*
  472. * The main work is done here!
  473. * We have the file name and/or the data buffer to be identified.
  474. */
  475. if (file_buffer(ms, -1, NULL, NULL, buf, nb) == -1) {
  476. return NULL;
  477. }
  478. return file_getbuffer(ms);
  479. }
  480. #endif
  481. public const char *
  482. magic_error(struct magic_set *ms)
  483. {
  484. if (ms == NULL)
  485. return "Magic database is not open";
  486. return (ms->event_flags & EVENT_HAD_ERR) ? ms->o.buf : NULL;
  487. }
  488. public int
  489. magic_errno(struct magic_set *ms)
  490. {
  491. if (ms == NULL)
  492. return EINVAL;
  493. return (ms->event_flags & EVENT_HAD_ERR) ? ms->error : 0;
  494. }
  495. public int
  496. magic_getflags(struct magic_set *ms)
  497. {
  498. if (ms == NULL)
  499. return -1;
  500. return ms->flags;
  501. }
  502. public int
  503. magic_setflags(struct magic_set *ms, int flags)
  504. {
  505. if (ms == NULL)
  506. return -1;
  507. #if !defined(HAVE_UTIME) && !defined(HAVE_UTIMES)
  508. if (flags & MAGIC_PRESERVE_ATIME)
  509. return -1;
  510. #endif
  511. ms->flags = flags;
  512. return 0;
  513. }
  514. public int
  515. magic_version(void)
  516. {
  517. return MAGIC_VERSION;
  518. }
  519. public int
  520. magic_setparam(struct magic_set *ms, int param, const void *val)
  521. {
  522. if (ms == NULL)
  523. return -1;
  524. switch (param) {
  525. case MAGIC_PARAM_INDIR_MAX:
  526. ms->indir_max = CAST(uint16_t, *CAST(const size_t *, val));
  527. return 0;
  528. case MAGIC_PARAM_NAME_MAX:
  529. ms->name_max = CAST(uint16_t, *CAST(const size_t *, val));
  530. return 0;
  531. case MAGIC_PARAM_ELF_PHNUM_MAX:
  532. ms->elf_phnum_max = CAST(uint16_t, *CAST(const size_t *, val));
  533. return 0;
  534. case MAGIC_PARAM_ELF_SHNUM_MAX:
  535. ms->elf_shnum_max = CAST(uint16_t, *CAST(const size_t *, val));
  536. return 0;
  537. case MAGIC_PARAM_ELF_NOTES_MAX:
  538. ms->elf_notes_max = CAST(uint16_t, *CAST(const size_t *, val));
  539. return 0;
  540. case MAGIC_PARAM_REGEX_MAX:
  541. ms->regex_max = CAST(uint16_t, *CAST(const size_t *, val));
  542. return 0;
  543. case MAGIC_PARAM_BYTES_MAX:
  544. ms->bytes_max = *CAST(const size_t *, val);
  545. return 0;
  546. case MAGIC_PARAM_ENCODING_MAX:
  547. ms->encoding_max = *CAST(const size_t *, val);
  548. return 0;
  549. default:
  550. errno = EINVAL;
  551. return -1;
  552. }
  553. }
  554. public int
  555. magic_getparam(struct magic_set *ms, int param, void *val)
  556. {
  557. if (ms == NULL)
  558. return -1;
  559. switch (param) {
  560. case MAGIC_PARAM_INDIR_MAX:
  561. *CAST(size_t *, val) = ms->indir_max;
  562. return 0;
  563. case MAGIC_PARAM_NAME_MAX:
  564. *CAST(size_t *, val) = ms->name_max;
  565. return 0;
  566. case MAGIC_PARAM_ELF_PHNUM_MAX:
  567. *CAST(size_t *, val) = ms->elf_phnum_max;
  568. return 0;
  569. case MAGIC_PARAM_ELF_SHNUM_MAX:
  570. *CAST(size_t *, val) = ms->elf_shnum_max;
  571. return 0;
  572. case MAGIC_PARAM_ELF_NOTES_MAX:
  573. *CAST(size_t *, val) = ms->elf_notes_max;
  574. return 0;
  575. case MAGIC_PARAM_REGEX_MAX:
  576. *CAST(size_t *, val) = ms->regex_max;
  577. return 0;
  578. case MAGIC_PARAM_BYTES_MAX:
  579. *CAST(size_t *, val) = ms->bytes_max;
  580. return 0;
  581. case MAGIC_PARAM_ENCODING_MAX:
  582. *CAST(size_t *, val) = ms->encoding_max;
  583. return 0;
  584. default:
  585. errno = EINVAL;
  586. return -1;
  587. }
  588. }