ldd.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * A small little ldd implementation for uClibc
  4. *
  5. * Copyright (C) 2000 by Lineo, inc and Erik Andersen
  6. * Copyright (C) 2000-2002 Erik Andersen <andersee@debian.org>
  7. *
  8. * Several functions in this file (specifically, elf_find_section_type(),
  9. * elf_find_phdr_type(), and elf_find_dynamic(), were stolen from elflib.c from
  10. * elfvector (http://www.BitWagon.com/elfvector.html) by John F. Reiser
  11. * <jreiser@BitWagon.com>, which is copyright 2000 BitWagon Software LLC
  12. * (GPL2).
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  22. * General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  27. *
  28. */
  29. #define _GNU_SOURCE
  30. #include <stdlib.h>
  31. #include <stdio.h>
  32. #include <fcntl.h>
  33. #include <string.h>
  34. #include <unistd.h>
  35. #include <sys/mman.h>
  36. #include <sys/stat.h>
  37. #include <sys/types.h>
  38. #include <sys/types.h>
  39. #include <sys/wait.h>
  40. #include "bswap.h"
  41. #if defined (sun)
  42. #include "link.h"
  43. #else
  44. #include "elf.h"
  45. #endif
  46. #ifdef DMALLOC
  47. #include <dmalloc.h>
  48. #endif
  49. #if defined(__arm__)
  50. #define MATCH_MACHINE(x) (x == EM_ARM)
  51. #define ELFCLASSM ELFCLASS32
  52. #endif
  53. #if defined(__s390__)
  54. #define MATCH_MACHINE(x) (x == EM_S390)
  55. #define ELFCLASSM ELFCLASS32
  56. #endif
  57. #if defined(__i386__)
  58. #ifndef EM_486
  59. #define MATCH_MACHINE(x) (x == EM_386)
  60. #else
  61. #define MATCH_MACHINE(x) (x == EM_386 || x == EM_486)
  62. #endif
  63. #define ELFCLASSM ELFCLASS32
  64. #endif
  65. #if defined(__mc68000__)
  66. #define MATCH_MACHINE(x) (x == EM_68K)
  67. #define ELFCLASSM ELFCLASS32
  68. #endif
  69. #if defined(__mips__)
  70. #define MATCH_MACHINE(x) (x == EM_MIPS || x == EM_MIPS_RS3_LE)
  71. #define ELFCLASSM ELFCLASS32
  72. #endif
  73. #if defined(__powerpc__)
  74. #define MATCH_MACHINE(x) (x == EM_PPC)
  75. #define ELFCLASSM ELFCLASS32
  76. #endif
  77. #if defined(__sh__)
  78. #define MATCH_MACHINE(x) (x == EM_SH)
  79. #define ELFCLASSM ELFCLASS32
  80. #endif
  81. #if defined (__v850e__)
  82. #define MATCH_MACHINE(x) ((x) == EM_V850 || (x) == EM_CYGNUS_V850)
  83. #define ELFCLASSM ELFCLASS32
  84. #endif
  85. #if defined (__sparc__)
  86. #define MATCH_MACHINE(x) ((x) == EM_SPARC || (x) == EM_SPARC32PLUS)
  87. #define ELFCLASSM ELFCLASS32
  88. #endif
  89. #ifndef MATCH_MACHINE
  90. #warning "You really should add a MATCH_MACHINE() macro for your architecture"
  91. #endif
  92. #if __BYTE_ORDER == __LITTLE_ENDIAN
  93. #define ELFDATAM ELFDATA2LSB
  94. #elif __BYTE_ORDER == __BIG_ENDIAN
  95. #define ELFDATAM ELFDATA2MSB
  96. #endif
  97. struct library {
  98. char *name;
  99. int resolved;
  100. char *path;
  101. struct library *next;
  102. };
  103. struct library *lib_list = NULL;
  104. char not_found[] = "not found";
  105. char *interp = NULL;
  106. char *interp_dir = NULL;
  107. int byteswap;
  108. inline uint32_t byteswap32_to_host(uint32_t value)
  109. {
  110. if (byteswap==1) {
  111. return(bswap_32(value));
  112. } else {
  113. return(value);
  114. }
  115. }
  116. Elf32_Shdr * elf_find_section_type( int key, Elf32_Ehdr *ehdr)
  117. {
  118. int j;
  119. Elf32_Shdr *shdr;
  120. shdr = (Elf32_Shdr *)(ehdr->e_shoff + (char *)ehdr);
  121. for (j = ehdr->e_shnum; --j>=0; ++shdr) {
  122. if (key==(int)byteswap32_to_host(shdr->sh_type)) {
  123. return shdr;
  124. }
  125. }
  126. return NULL;
  127. }
  128. Elf32_Phdr * elf_find_phdr_type( int type, Elf32_Ehdr *ehdr)
  129. {
  130. int j;
  131. Elf32_Phdr *phdr = (Elf32_Phdr *)(ehdr->e_phoff + (char *)ehdr);
  132. for (j = ehdr->e_phnum; --j>=0; ++phdr) {
  133. if (type==(int)byteswap32_to_host(phdr->p_type)) {
  134. return phdr;
  135. }
  136. }
  137. return NULL;
  138. }
  139. /* Returns value if return_val==1, ptr otherwise */
  140. void * elf_find_dynamic(int const key, Elf32_Dyn *dynp,
  141. Elf32_Ehdr *ehdr, int return_val)
  142. {
  143. Elf32_Phdr *pt_text = elf_find_phdr_type(PT_LOAD, ehdr);
  144. unsigned tx_reloc = byteswap32_to_host(pt_text->p_vaddr) - byteswap32_to_host(pt_text->p_offset);
  145. for (; DT_NULL!=byteswap32_to_host(dynp->d_tag); ++dynp) {
  146. if (key == (int)byteswap32_to_host(dynp->d_tag)) {
  147. if (return_val == 1)
  148. return (void *)(intptr_t)byteswap32_to_host(dynp->d_un.d_val);
  149. else
  150. return (void *)(byteswap32_to_host(dynp->d_un.d_val) - tx_reloc + (char *)ehdr );
  151. }
  152. }
  153. return NULL;
  154. }
  155. int check_elf_header(Elf32_Ehdr *const ehdr)
  156. {
  157. if (! ehdr || strncmp((void *)ehdr, ELFMAG, SELFMAG) != 0 ||
  158. ehdr->e_ident[EI_CLASS] != ELFCLASS32 ||
  159. ehdr->e_ident[EI_VERSION] != EV_CURRENT)
  160. {
  161. return 1;
  162. }
  163. /* Check if the target endianness matches the host's endianness */
  164. byteswap = 0;
  165. #if __BYTE_ORDER == __LITTLE_ENDIAN
  166. if (ehdr->e_ident[5] == ELFDATA2MSB) {
  167. /* Ick -- we will have to byte-swap everything */
  168. byteswap = 1;
  169. }
  170. #elif __BYTE_ORDER == __BIG_ENDIAN
  171. if (ehdr->e_ident[5] == ELFDATA2LSB) {
  172. /* Ick -- we will have to byte-swap everything */
  173. byteswap = 1;
  174. }
  175. #else
  176. #error Unknown host byte order!
  177. #endif
  178. /* Be vary lazy, and only byteswap the stuff we use */
  179. if (byteswap==1) {
  180. ehdr->e_type=bswap_16(ehdr->e_type);
  181. ehdr->e_phoff=bswap_32(ehdr->e_phoff);
  182. ehdr->e_shoff=bswap_32(ehdr->e_shoff);
  183. ehdr->e_phnum=bswap_16(ehdr->e_phnum);
  184. ehdr->e_shnum=bswap_16(ehdr->e_shnum);
  185. }
  186. return 0;
  187. }
  188. /* This function's behavior must exactly match that
  189. * in uClibc/ldso/d-link/readelflib1.c */
  190. static void search_for_named_library(char *name, char *result, const char *path_list)
  191. {
  192. int i, count = 1;
  193. char *path, *path_n;
  194. struct stat filestat;
  195. /* We need a writable copy of this string */
  196. path = strdup(path_list);
  197. if (!path) {
  198. fprintf(stderr, "Out of memory!\n");
  199. exit(EXIT_FAILURE);
  200. }
  201. /* Eliminate all double //s */
  202. path_n=path;
  203. while((path_n=strstr(path_n, "//"))) {
  204. i = strlen(path_n);
  205. memmove(path_n, path_n+1, i-1);
  206. }
  207. /* Replace colons with zeros in path_list and count them */
  208. for(i=strlen(path); i > 0; i--) {
  209. if (path[i]==':') {
  210. path[i]=0;
  211. count++;
  212. }
  213. }
  214. path_n = path;
  215. for (i = 0; i < count; i++) {
  216. strcpy(result, path_n);
  217. strcat(result, "/");
  218. strcat(result, name);
  219. if (stat (result, &filestat) == 0 && filestat.st_mode & S_IRUSR) {
  220. free(path);
  221. return;
  222. }
  223. path_n += (strlen(path_n) + 1);
  224. }
  225. free(path);
  226. *result = '\0';
  227. }
  228. void locate_library_file(Elf32_Ehdr* ehdr, Elf32_Dyn* dynamic, int is_suid, struct library *lib)
  229. {
  230. char *buf;
  231. char *path;
  232. struct stat filestat;
  233. /* If this is a fully resolved name, our job is easy */
  234. if (stat (lib->name, &filestat) == 0) {
  235. lib->path = lib->name;
  236. return;
  237. }
  238. /* We need some elbow room here. Make some room...*/
  239. buf = malloc(1024);
  240. if (!buf) {
  241. fprintf(stderr, "Out of memory!\n");
  242. exit(EXIT_FAILURE);
  243. }
  244. /* This function must match the behavior of _dl_load_shared_library
  245. * in readelflib1.c or things won't work out as expected... */
  246. /* The ABI specifies that RPATH is searched first, so do that now. */
  247. path = (char *)elf_find_dynamic(DT_RPATH, dynamic, ehdr, 0);
  248. if (path) {
  249. search_for_named_library(lib->name, buf, path);
  250. if (*buf != '\0') {
  251. lib->path = buf;
  252. return;
  253. }
  254. }
  255. /* Next check LD_{ELF_}LIBRARY_PATH if specified and allowed.
  256. * Since this app doesn't actually run an executable I will skip
  257. * the suid check, and just use LD_{ELF_}LIBRARY_PATH if set */
  258. if (is_suid==1)
  259. path = NULL;
  260. else
  261. path = getenv("LD_LIBRARY_PATH");
  262. if (path) {
  263. search_for_named_library(lib->name, buf, path);
  264. if (*buf != '\0') {
  265. lib->path = buf;
  266. return;
  267. }
  268. }
  269. #ifdef USE_CACHE
  270. /* FIXME -- add code to check the Cache here */
  271. #endif
  272. /* Next look for libraries wherever the shared library
  273. * loader was installed -- this is usually where we
  274. * should find things... */
  275. if (interp_dir) {
  276. search_for_named_library(lib->name, buf, interp_dir);
  277. if (*buf != '\0') {
  278. lib->path = buf;
  279. return;
  280. }
  281. }
  282. /* Lastly, search the standard list of paths for the library.
  283. This list must exactly match the list in uClibc/ldso/d-link/readelflib1.c */
  284. path = UCLIBC_TARGET_PREFIX "/usr/lib:"
  285. UCLIBC_TARGET_PREFIX "/lib:"
  286. UCLIBC_DEVEL_PREFIX "/lib:"
  287. UCLIBC_BUILD_DIR "/lib:"
  288. "/usr/lib:"
  289. "/lib";
  290. search_for_named_library(lib->name, buf, path);
  291. if (*buf != '\0') {
  292. lib->path = buf;
  293. } else {
  294. free(buf);
  295. lib->path = not_found;
  296. }
  297. }
  298. static int add_library(Elf32_Ehdr* ehdr, Elf32_Dyn* dynamic, int is_setuid, char *s)
  299. {
  300. char *tmp, *tmp1, *tmp2;
  301. struct library *cur, *newlib=lib_list;
  302. if (!s || !strlen(s))
  303. return 1;
  304. tmp = s;
  305. while (*tmp) {
  306. if (*tmp == '/')
  307. s = tmp + 1;
  308. tmp++;
  309. }
  310. /* We add libc.so.0 elsewhere */
  311. if ((tmp=strrchr(interp, '/')) != NULL)
  312. {
  313. int len = strlen(interp_dir);
  314. if (strcmp(s, interp+1+len)==0)
  315. return 1;
  316. }
  317. for (cur = lib_list; cur; cur=cur->next) {
  318. /* Check if this library is already in the list */
  319. tmp1 = tmp2 = cur->name;
  320. while (*tmp1) {
  321. if (*tmp1 == '/')
  322. tmp2 = tmp1 + 1;
  323. tmp1++;
  324. }
  325. if(strcmp(tmp2, s)==0) {
  326. //printf("find_elf_interpreter is skipping '%s' (already in list)\n", cur->name);
  327. return 0;
  328. }
  329. }
  330. /* Ok, this lib needs to be added to the list */
  331. newlib = malloc(sizeof(struct library));
  332. if (!newlib)
  333. return 1;
  334. newlib->name = malloc(strlen(s)+1);
  335. strcpy(newlib->name, s);
  336. newlib->resolved = 0;
  337. newlib->path = NULL;
  338. newlib->next = NULL;
  339. /* Now try and locate where this library might be living... */
  340. locate_library_file(ehdr, dynamic, is_setuid, newlib);
  341. //printf("add_library is adding '%s' to '%s'\n", newlib->name, newlib->path);
  342. if (!lib_list) {
  343. lib_list = newlib;
  344. } else {
  345. for (cur = lib_list; cur->next; cur=cur->next); /* nothing */
  346. cur->next = newlib;
  347. }
  348. return 0;
  349. }
  350. static void find_needed_libraries(Elf32_Ehdr* ehdr, Elf32_Dyn* dynamic, char *strtab, int is_setuid)
  351. {
  352. Elf32_Dyn *dyns;
  353. for (dyns=dynamic; byteswap32_to_host(dyns->d_tag)!=DT_NULL; ++dyns) {
  354. if (DT_NEEDED == byteswap32_to_host(dyns->d_tag)) {
  355. add_library(ehdr, dynamic, is_setuid,
  356. (char*)strtab + byteswap32_to_host(dyns->d_un.d_val));
  357. }
  358. }
  359. }
  360. static int interpreter_already_found=0;
  361. static struct library * find_elf_interpreter(Elf32_Ehdr* ehdr)
  362. {
  363. Elf32_Phdr *phdr;
  364. if (interpreter_already_found==1)
  365. return NULL;
  366. interpreter_already_found=1;
  367. phdr = elf_find_phdr_type(PT_INTERP, ehdr);
  368. if (phdr) {
  369. struct library *cur, *newlib=NULL;
  370. char *s = (char*)ehdr + byteswap32_to_host(phdr->p_offset);
  371. char *tmp, *tmp1;
  372. interp = strdup(s);
  373. interp_dir = strdup(s);
  374. tmp = strrchr(interp_dir, '/');
  375. if (*tmp)
  376. *tmp = '\0';
  377. else {
  378. free(interp_dir);
  379. interp_dir = interp;
  380. }
  381. tmp1 = tmp = s;
  382. while (*tmp) {
  383. if (*tmp == '/')
  384. tmp1 = tmp + 1;
  385. tmp++;
  386. }
  387. for (cur = lib_list; cur; cur=cur->next) {
  388. /* Check if this library is already in the list */
  389. if(strcmp(cur->name, tmp1)==0) {
  390. //printf("find_elf_interpreter is replacing '%s' (already in list)\n", cur->name);
  391. newlib = cur;
  392. free(newlib->name);
  393. free(newlib->path);
  394. return NULL;
  395. }
  396. }
  397. if (newlib == NULL)
  398. newlib = malloc(sizeof(struct library));
  399. if (!newlib)
  400. return NULL;
  401. newlib->name = malloc(strlen(s)+1);
  402. strcpy(newlib->name, s);
  403. newlib->path = newlib->name;
  404. newlib->resolved = 1;
  405. newlib->next = NULL;
  406. #if 0
  407. //printf("find_elf_interpreter is adding '%s' to '%s'\n", newlib->name, newlib->path);
  408. if (!lib_list) {
  409. lib_list = newlib;
  410. } else {
  411. for (cur = lib_list; cur->next; cur=cur->next); /* nothing */
  412. cur->next = newlib;
  413. }
  414. #endif
  415. return newlib;
  416. }
  417. return NULL;
  418. }
  419. /* map the .so, and locate interesting pieces */
  420. int find_dependancies(char* filename)
  421. {
  422. int is_suid = 0;
  423. FILE *thefile;
  424. struct stat statbuf;
  425. char *dynstr=NULL;
  426. Elf32_Ehdr *ehdr = NULL;
  427. Elf32_Shdr *dynsec = NULL;
  428. Elf32_Dyn *dynamic = NULL;
  429. struct library *interp;
  430. if (filename == not_found)
  431. return 0;
  432. if (!filename) {
  433. fprintf(stderr, "No filename specified.\n");
  434. return -1;
  435. }
  436. if (!(thefile = fopen(filename, "r"))) {
  437. perror(filename);
  438. return -1;
  439. }
  440. if (fstat(fileno(thefile), &statbuf) < 0) {
  441. perror(filename);
  442. return -1;
  443. }
  444. if ((size_t)statbuf.st_size < sizeof(Elf32_Ehdr))
  445. goto foo;
  446. /* mmap the file to make reading stuff from it effortless */
  447. ehdr = (Elf32_Ehdr *)mmap(0, statbuf.st_size,
  448. PROT_READ|PROT_WRITE, MAP_PRIVATE, fileno(thefile), 0);
  449. foo:
  450. /* Check if this looks like a legit ELF file */
  451. if (check_elf_header(ehdr)) {
  452. fprintf(stderr, "%s: not an ELF file.\n", filename);
  453. return -1;
  454. }
  455. /* Check if this is the right kind of ELF file */
  456. if (ehdr->e_type != ET_EXEC && ehdr->e_type != ET_DYN) {
  457. fprintf(stderr, "%s: not a dynamic executable\n", filename);
  458. return -1;
  459. }
  460. if (ehdr->e_type == ET_EXEC) {
  461. if (statbuf.st_mode & S_ISUID)
  462. is_suid = 1;
  463. if ((statbuf.st_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
  464. is_suid = 1;
  465. /* FIXME */
  466. if (is_suid)
  467. fprintf(stderr, "%s: is setuid\n", filename);
  468. }
  469. interpreter_already_found=0;
  470. interp = find_elf_interpreter(ehdr);
  471. #ifdef __LDSO_LDD_SUPPORT
  472. if (interp && ehdr->e_ident[EI_CLASS] == ELFCLASSM && ehdr->e_ident[EI_DATA] == ELFDATAM
  473. && ehdr->e_ident[EI_VERSION] == EV_CURRENT && MATCH_MACHINE(ehdr->e_machine))
  474. {
  475. struct stat statbuf;
  476. if (stat(interp->path, &statbuf) == 0 && S_ISREG(statbuf.st_mode)) {
  477. pid_t pid;
  478. int status;
  479. static const char * const environment[] = {
  480. "PATH=/usr/bin:/bin:/usr/sbin:/sbin",
  481. "SHELL=/bin/sh",
  482. "LD_TRACE_LOADED_OBJECTS=1",
  483. NULL
  484. };
  485. if ((pid = fork()) == 0) {
  486. /* Cool, it looks like we should be able to actually
  487. * run this puppy. Do so now... */
  488. execle(filename, filename, NULL, environment);
  489. _exit(0xdead);
  490. }
  491. /* Wait till it returns */
  492. waitpid(pid, &status, 0);
  493. if (WIFEXITED(status)!=0xdead) {
  494. return 1;
  495. }
  496. /* If the exec failed, we fall through to trying to find
  497. * all the needed libraries ourselves by rummaging about
  498. * in the ELF headers... */
  499. }
  500. }
  501. #endif
  502. dynsec = elf_find_section_type(SHT_DYNAMIC, ehdr);
  503. if (dynsec) {
  504. dynamic = (Elf32_Dyn*)(byteswap32_to_host(dynsec->sh_offset) + (intptr_t)ehdr);
  505. dynstr = (char *)elf_find_dynamic(DT_STRTAB, dynamic, ehdr, 0);
  506. find_needed_libraries(ehdr, dynamic, dynstr, is_suid);
  507. }
  508. return 0;
  509. }
  510. int main( int argc, char** argv)
  511. {
  512. int multi=0;
  513. int got_em_all=1;
  514. char *filename = NULL;
  515. struct library *cur;
  516. if (argc < 2) {
  517. fprintf(stderr, "ldd: missing file arguments\n");
  518. fprintf(stderr, "Try `ldd --help' for more information.\n");
  519. exit(EXIT_FAILURE);
  520. }
  521. if (argc > 2) {
  522. multi++;
  523. }
  524. while (--argc > 0) {
  525. ++argv;
  526. if(strcmp(*argv, "--")==0) {
  527. /* Ignore "--" */
  528. continue;
  529. }
  530. if(strcmp(*argv, "--help")==0) {
  531. fprintf(stderr, "Usage: ldd [OPTION]... FILE...\n");
  532. fprintf(stderr, "\t--help\t\tprint this help and exit\n");
  533. exit(EXIT_FAILURE);
  534. }
  535. filename=*argv;
  536. if (!filename) {
  537. fprintf(stderr, "No filename specified.\n");
  538. exit(EXIT_FAILURE);
  539. }
  540. if (multi) {
  541. printf("%s:\n", *argv);
  542. }
  543. if (find_dependancies(filename)!=0)
  544. continue;
  545. while(got_em_all) {
  546. got_em_all=0;
  547. /* Keep walking the list till everybody is resolved */
  548. for (cur = lib_list; cur; cur=cur->next) {
  549. if (cur->resolved == 0 && cur->path) {
  550. got_em_all=1;
  551. //printf("checking sub-depends for '%s\n", cur->path);
  552. find_dependancies(cur->path);
  553. cur->resolved = 1;
  554. }
  555. }
  556. }
  557. /* Print the list */
  558. got_em_all=0;
  559. for (cur = lib_list; cur; cur=cur->next) {
  560. got_em_all=1;
  561. printf("\t%s => %s (0x00000000)\n", cur->name, cur->path);
  562. }
  563. if (interp_dir && got_em_all==1)
  564. printf("\t%s => %s (0x00000000)\n", interp, interp);
  565. if (got_em_all==0)
  566. printf("\tnot a dynamic executable\n");
  567. for (cur = lib_list; cur; cur=cur->next) {
  568. free(cur->name);
  569. cur->name=NULL;
  570. free(cur->path);
  571. cur->path=NULL;
  572. }
  573. lib_list=NULL;
  574. }
  575. return 0;
  576. }