A local copy of OpenSSL from GitHub
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.

726 lines
18 KiB

  1. /*
  2. * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (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. #include <stdio.h>
  10. #include <ctype.h>
  11. #include <limits.h>
  12. #include "internal/cryptlib.h"
  13. #include <openssl/lhash.h>
  14. #include <openssl/asn1.h>
  15. #include "internal/objects.h"
  16. #include <openssl/bn.h>
  17. #include "internal/asn1_int.h"
  18. #include "obj_lcl.h"
  19. /* obj_dat.h is generated from objects.h by obj_dat.pl */
  20. #include "obj_dat.h"
  21. DECLARE_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, sn);
  22. DECLARE_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, ln);
  23. DECLARE_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, obj);
  24. #define ADDED_DATA 0
  25. #define ADDED_SNAME 1
  26. #define ADDED_LNAME 2
  27. #define ADDED_NID 3
  28. struct added_obj_st {
  29. int type;
  30. ASN1_OBJECT *obj;
  31. };
  32. static int new_nid = NUM_NID;
  33. static LHASH_OF(ADDED_OBJ) *added = NULL;
  34. static int sn_cmp(const ASN1_OBJECT *const *a, const unsigned int *b)
  35. {
  36. return (strcmp((*a)->sn, nid_objs[*b].sn));
  37. }
  38. IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, sn);
  39. static int ln_cmp(const ASN1_OBJECT *const *a, const unsigned int *b)
  40. {
  41. return (strcmp((*a)->ln, nid_objs[*b].ln));
  42. }
  43. IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, ln);
  44. static unsigned long added_obj_hash(const ADDED_OBJ *ca)
  45. {
  46. const ASN1_OBJECT *a;
  47. int i;
  48. unsigned long ret = 0;
  49. unsigned char *p;
  50. a = ca->obj;
  51. switch (ca->type) {
  52. case ADDED_DATA:
  53. ret = a->length << 20L;
  54. p = (unsigned char *)a->data;
  55. for (i = 0; i < a->length; i++)
  56. ret ^= p[i] << ((i * 3) % 24);
  57. break;
  58. case ADDED_SNAME:
  59. ret = lh_strhash(a->sn);
  60. break;
  61. case ADDED_LNAME:
  62. ret = lh_strhash(a->ln);
  63. break;
  64. case ADDED_NID:
  65. ret = a->nid;
  66. break;
  67. default:
  68. /* abort(); */
  69. return 0;
  70. }
  71. ret &= 0x3fffffffL;
  72. ret |= ((unsigned long)ca->type) << 30L;
  73. return (ret);
  74. }
  75. static int added_obj_cmp(const ADDED_OBJ *ca, const ADDED_OBJ *cb)
  76. {
  77. ASN1_OBJECT *a, *b;
  78. int i;
  79. i = ca->type - cb->type;
  80. if (i)
  81. return (i);
  82. a = ca->obj;
  83. b = cb->obj;
  84. switch (ca->type) {
  85. case ADDED_DATA:
  86. i = (a->length - b->length);
  87. if (i)
  88. return (i);
  89. return (memcmp(a->data, b->data, (size_t)a->length));
  90. case ADDED_SNAME:
  91. if (a->sn == NULL)
  92. return (-1);
  93. else if (b->sn == NULL)
  94. return (1);
  95. else
  96. return (strcmp(a->sn, b->sn));
  97. case ADDED_LNAME:
  98. if (a->ln == NULL)
  99. return (-1);
  100. else if (b->ln == NULL)
  101. return (1);
  102. else
  103. return (strcmp(a->ln, b->ln));
  104. case ADDED_NID:
  105. return (a->nid - b->nid);
  106. default:
  107. /* abort(); */
  108. return 0;
  109. }
  110. }
  111. static int init_added(void)
  112. {
  113. if (added != NULL)
  114. return (1);
  115. added = lh_ADDED_OBJ_new(added_obj_hash, added_obj_cmp);
  116. return (added != NULL);
  117. }
  118. static void cleanup1_doall(ADDED_OBJ *a)
  119. {
  120. a->obj->nid = 0;
  121. a->obj->flags |= ASN1_OBJECT_FLAG_DYNAMIC |
  122. ASN1_OBJECT_FLAG_DYNAMIC_STRINGS | ASN1_OBJECT_FLAG_DYNAMIC_DATA;
  123. }
  124. static void cleanup2_doall(ADDED_OBJ *a)
  125. {
  126. a->obj->nid++;
  127. }
  128. static void cleanup3_doall(ADDED_OBJ *a)
  129. {
  130. if (--a->obj->nid == 0)
  131. ASN1_OBJECT_free(a->obj);
  132. OPENSSL_free(a);
  133. }
  134. void obj_cleanup_int(void)
  135. {
  136. if (added == NULL)
  137. return;
  138. lh_ADDED_OBJ_set_down_load(added, 0);
  139. lh_ADDED_OBJ_doall(added, cleanup1_doall); /* zero counters */
  140. lh_ADDED_OBJ_doall(added, cleanup2_doall); /* set counters */
  141. lh_ADDED_OBJ_doall(added, cleanup3_doall); /* free objects */
  142. lh_ADDED_OBJ_free(added);
  143. added = NULL;
  144. }
  145. int OBJ_new_nid(int num)
  146. {
  147. int i;
  148. i = new_nid;
  149. new_nid += num;
  150. return (i);
  151. }
  152. int OBJ_add_object(const ASN1_OBJECT *obj)
  153. {
  154. ASN1_OBJECT *o;
  155. ADDED_OBJ *ao[4] = { NULL, NULL, NULL, NULL }, *aop;
  156. int i;
  157. if (added == NULL)
  158. if (!init_added())
  159. return (0);
  160. if ((o = OBJ_dup(obj)) == NULL)
  161. goto err;
  162. if ((ao[ADDED_NID] = OPENSSL_malloc(sizeof(*ao[0]))) == NULL)
  163. goto err2;
  164. if ((o->length != 0) && (obj->data != NULL))
  165. if ((ao[ADDED_DATA] = OPENSSL_malloc(sizeof(*ao[0]))) == NULL)
  166. goto err2;
  167. if (o->sn != NULL)
  168. if ((ao[ADDED_SNAME] = OPENSSL_malloc(sizeof(*ao[0]))) == NULL)
  169. goto err2;
  170. if (o->ln != NULL)
  171. if ((ao[ADDED_LNAME] = OPENSSL_malloc(sizeof(*ao[0]))) == NULL)
  172. goto err2;
  173. for (i = ADDED_DATA; i <= ADDED_NID; i++) {
  174. if (ao[i] != NULL) {
  175. ao[i]->type = i;
  176. ao[i]->obj = o;
  177. aop = lh_ADDED_OBJ_insert(added, ao[i]);
  178. /* memory leak, buit should not normally matter */
  179. OPENSSL_free(aop);
  180. }
  181. }
  182. o->flags &=
  183. ~(ASN1_OBJECT_FLAG_DYNAMIC | ASN1_OBJECT_FLAG_DYNAMIC_STRINGS |
  184. ASN1_OBJECT_FLAG_DYNAMIC_DATA);
  185. return (o->nid);
  186. err2:
  187. OBJerr(OBJ_F_OBJ_ADD_OBJECT, ERR_R_MALLOC_FAILURE);
  188. err:
  189. for (i = ADDED_DATA; i <= ADDED_NID; i++)
  190. OPENSSL_free(ao[i]);
  191. OPENSSL_free(o);
  192. return (NID_undef);
  193. }
  194. ASN1_OBJECT *OBJ_nid2obj(int n)
  195. {
  196. ADDED_OBJ ad, *adp;
  197. ASN1_OBJECT ob;
  198. if ((n >= 0) && (n < NUM_NID)) {
  199. if ((n != NID_undef) && (nid_objs[n].nid == NID_undef)) {
  200. OBJerr(OBJ_F_OBJ_NID2OBJ, OBJ_R_UNKNOWN_NID);
  201. return (NULL);
  202. }
  203. return ((ASN1_OBJECT *)&(nid_objs[n]));
  204. } else if (added == NULL)
  205. return (NULL);
  206. else {
  207. ad.type = ADDED_NID;
  208. ad.obj = &ob;
  209. ob.nid = n;
  210. adp = lh_ADDED_OBJ_retrieve(added, &ad);
  211. if (adp != NULL)
  212. return (adp->obj);
  213. else {
  214. OBJerr(OBJ_F_OBJ_NID2OBJ, OBJ_R_UNKNOWN_NID);
  215. return (NULL);
  216. }
  217. }
  218. }
  219. const char *OBJ_nid2sn(int n)
  220. {
  221. ADDED_OBJ ad, *adp;
  222. ASN1_OBJECT ob;
  223. if ((n >= 0) && (n < NUM_NID)) {
  224. if ((n != NID_undef) && (nid_objs[n].nid == NID_undef)) {
  225. OBJerr(OBJ_F_OBJ_NID2SN, OBJ_R_UNKNOWN_NID);
  226. return (NULL);
  227. }
  228. return (nid_objs[n].sn);
  229. } else if (added == NULL)
  230. return (NULL);
  231. else {
  232. ad.type = ADDED_NID;
  233. ad.obj = &ob;
  234. ob.nid = n;
  235. adp = lh_ADDED_OBJ_retrieve(added, &ad);
  236. if (adp != NULL)
  237. return (adp->obj->sn);
  238. else {
  239. OBJerr(OBJ_F_OBJ_NID2SN, OBJ_R_UNKNOWN_NID);
  240. return (NULL);
  241. }
  242. }
  243. }
  244. const char *OBJ_nid2ln(int n)
  245. {
  246. ADDED_OBJ ad, *adp;
  247. ASN1_OBJECT ob;
  248. if ((n >= 0) && (n < NUM_NID)) {
  249. if ((n != NID_undef) && (nid_objs[n].nid == NID_undef)) {
  250. OBJerr(OBJ_F_OBJ_NID2LN, OBJ_R_UNKNOWN_NID);
  251. return (NULL);
  252. }
  253. return (nid_objs[n].ln);
  254. } else if (added == NULL)
  255. return (NULL);
  256. else {
  257. ad.type = ADDED_NID;
  258. ad.obj = &ob;
  259. ob.nid = n;
  260. adp = lh_ADDED_OBJ_retrieve(added, &ad);
  261. if (adp != NULL)
  262. return (adp->obj->ln);
  263. else {
  264. OBJerr(OBJ_F_OBJ_NID2LN, OBJ_R_UNKNOWN_NID);
  265. return (NULL);
  266. }
  267. }
  268. }
  269. static int obj_cmp(const ASN1_OBJECT *const *ap, const unsigned int *bp)
  270. {
  271. int j;
  272. const ASN1_OBJECT *a = *ap;
  273. const ASN1_OBJECT *b = &nid_objs[*bp];
  274. j = (a->length - b->length);
  275. if (j)
  276. return (j);
  277. if (a->length == 0)
  278. return 0;
  279. return (memcmp(a->data, b->data, a->length));
  280. }
  281. IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, obj);
  282. int OBJ_obj2nid(const ASN1_OBJECT *a)
  283. {
  284. const unsigned int *op;
  285. ADDED_OBJ ad, *adp;
  286. if (a == NULL)
  287. return (NID_undef);
  288. if (a->nid != 0)
  289. return (a->nid);
  290. if (a->length == 0)
  291. return NID_undef;
  292. if (added != NULL) {
  293. ad.type = ADDED_DATA;
  294. ad.obj = (ASN1_OBJECT *)a; /* XXX: ugly but harmless */
  295. adp = lh_ADDED_OBJ_retrieve(added, &ad);
  296. if (adp != NULL)
  297. return (adp->obj->nid);
  298. }
  299. op = OBJ_bsearch_obj(&a, obj_objs, NUM_OBJ);
  300. if (op == NULL)
  301. return (NID_undef);
  302. return (nid_objs[*op].nid);
  303. }
  304. /*
  305. * Convert an object name into an ASN1_OBJECT if "noname" is not set then
  306. * search for short and long names first. This will convert the "dotted" form
  307. * into an object: unlike OBJ_txt2nid it can be used with any objects, not
  308. * just registered ones.
  309. */
  310. ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name)
  311. {
  312. int nid = NID_undef;
  313. ASN1_OBJECT *op = NULL;
  314. unsigned char *buf;
  315. unsigned char *p;
  316. const unsigned char *cp;
  317. int i, j;
  318. if (!no_name) {
  319. if (((nid = OBJ_sn2nid(s)) != NID_undef) ||
  320. ((nid = OBJ_ln2nid(s)) != NID_undef))
  321. return OBJ_nid2obj(nid);
  322. }
  323. /* Work out size of content octets */
  324. i = a2d_ASN1_OBJECT(NULL, 0, s, -1);
  325. if (i <= 0) {
  326. /* Don't clear the error */
  327. /*
  328. * ERR_clear_error();
  329. */
  330. return NULL;
  331. }
  332. /* Work out total size */
  333. j = ASN1_object_size(0, i, V_ASN1_OBJECT);
  334. if ((buf = OPENSSL_malloc(j)) == NULL)
  335. return NULL;
  336. p = buf;
  337. /* Write out tag+length */
  338. ASN1_put_object(&p, 0, i, V_ASN1_OBJECT, V_ASN1_UNIVERSAL);
  339. /* Write out contents */
  340. a2d_ASN1_OBJECT(p, i, s, -1);
  341. cp = buf;
  342. op = d2i_ASN1_OBJECT(NULL, &cp, j);
  343. OPENSSL_free(buf);
  344. return op;
  345. }
  346. int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name)
  347. {
  348. int i, n = 0, len, nid, first, use_bn;
  349. BIGNUM *bl;
  350. unsigned long l;
  351. const unsigned char *p;
  352. char tbuf[DECIMAL_SIZE(i) + DECIMAL_SIZE(l) + 2];
  353. /* Ensure that, at every state, |buf| is NUL-terminated. */
  354. if (buf && buf_len > 0)
  355. buf[0] = '\0';
  356. if ((a == NULL) || (a->data == NULL))
  357. return (0);
  358. if (!no_name && (nid = OBJ_obj2nid(a)) != NID_undef) {
  359. const char *s;
  360. s = OBJ_nid2ln(nid);
  361. if (s == NULL)
  362. s = OBJ_nid2sn(nid);
  363. if (s) {
  364. if (buf)
  365. OPENSSL_strlcpy(buf, s, buf_len);
  366. n = strlen(s);
  367. return n;
  368. }
  369. }
  370. len = a->length;
  371. p = a->data;
  372. first = 1;
  373. bl = NULL;
  374. while (len > 0) {
  375. l = 0;
  376. use_bn = 0;
  377. for (;;) {
  378. unsigned char c = *p++;
  379. len--;
  380. if ((len == 0) && (c & 0x80))
  381. goto err;
  382. if (use_bn) {
  383. if (!BN_add_word(bl, c & 0x7f))
  384. goto err;
  385. } else
  386. l |= c & 0x7f;
  387. if (!(c & 0x80))
  388. break;
  389. if (!use_bn && (l > (ULONG_MAX >> 7L))) {
  390. if (bl == NULL && (bl = BN_new()) == NULL)
  391. goto err;
  392. if (!BN_set_word(bl, l))
  393. goto err;
  394. use_bn = 1;
  395. }
  396. if (use_bn) {
  397. if (!BN_lshift(bl, bl, 7))
  398. goto err;
  399. } else
  400. l <<= 7L;
  401. }
  402. if (first) {
  403. first = 0;
  404. if (l >= 80) {
  405. i = 2;
  406. if (use_bn) {
  407. if (!BN_sub_word(bl, 80))
  408. goto err;
  409. } else
  410. l -= 80;
  411. } else {
  412. i = (int)(l / 40);
  413. l -= (long)(i * 40);
  414. }
  415. if (buf && (buf_len > 1)) {
  416. *buf++ = i + '0';
  417. *buf = '\0';
  418. buf_len--;
  419. }
  420. n++;
  421. }
  422. if (use_bn) {
  423. char *bndec;
  424. bndec = BN_bn2dec(bl);
  425. if (!bndec)
  426. goto err;
  427. i = strlen(bndec);
  428. if (buf) {
  429. if (buf_len > 1) {
  430. *buf++ = '.';
  431. *buf = '\0';
  432. buf_len--;
  433. }
  434. OPENSSL_strlcpy(buf, bndec, buf_len);
  435. if (i > buf_len) {
  436. buf += buf_len;
  437. buf_len = 0;
  438. } else {
  439. buf += i;
  440. buf_len -= i;
  441. }
  442. }
  443. n++;
  444. n += i;
  445. OPENSSL_free(bndec);
  446. } else {
  447. BIO_snprintf(tbuf, sizeof tbuf, ".%lu", l);
  448. i = strlen(tbuf);
  449. if (buf && (buf_len > 0)) {
  450. OPENSSL_strlcpy(buf, tbuf, buf_len);
  451. if (i > buf_len) {
  452. buf += buf_len;
  453. buf_len = 0;
  454. } else {
  455. buf += i;
  456. buf_len -= i;
  457. }
  458. }
  459. n += i;
  460. l = 0;
  461. }
  462. }
  463. BN_free(bl);
  464. return n;
  465. err:
  466. BN_free(bl);
  467. return -1;
  468. }
  469. int OBJ_txt2nid(const char *s)
  470. {
  471. ASN1_OBJECT *obj;
  472. int nid;
  473. obj = OBJ_txt2obj(s, 0);
  474. nid = OBJ_obj2nid(obj);
  475. ASN1_OBJECT_free(obj);
  476. return nid;
  477. }
  478. int OBJ_ln2nid(const char *s)
  479. {
  480. ASN1_OBJECT o;
  481. const ASN1_OBJECT *oo = &o;
  482. ADDED_OBJ ad, *adp;
  483. const unsigned int *op;
  484. o.ln = s;
  485. if (added != NULL) {
  486. ad.type = ADDED_LNAME;
  487. ad.obj = &o;
  488. adp = lh_ADDED_OBJ_retrieve(added, &ad);
  489. if (adp != NULL)
  490. return (adp->obj->nid);
  491. }
  492. op = OBJ_bsearch_ln(&oo, ln_objs, NUM_LN);
  493. if (op == NULL)
  494. return (NID_undef);
  495. return (nid_objs[*op].nid);
  496. }
  497. int OBJ_sn2nid(const char *s)
  498. {
  499. ASN1_OBJECT o;
  500. const ASN1_OBJECT *oo = &o;
  501. ADDED_OBJ ad, *adp;
  502. const unsigned int *op;
  503. o.sn = s;
  504. if (added != NULL) {
  505. ad.type = ADDED_SNAME;
  506. ad.obj = &o;
  507. adp = lh_ADDED_OBJ_retrieve(added, &ad);
  508. if (adp != NULL)
  509. return (adp->obj->nid);
  510. }
  511. op = OBJ_bsearch_sn(&oo, sn_objs, NUM_SN);
  512. if (op == NULL)
  513. return (NID_undef);
  514. return (nid_objs[*op].nid);
  515. }
  516. const void *OBJ_bsearch_(const void *key, const void *base, int num, int size,
  517. int (*cmp) (const void *, const void *))
  518. {
  519. return OBJ_bsearch_ex_(key, base, num, size, cmp, 0);
  520. }
  521. const void *OBJ_bsearch_ex_(const void *key, const void *base_, int num,
  522. int size,
  523. int (*cmp) (const void *, const void *),
  524. int flags)
  525. {
  526. const char *base = base_;
  527. int l, h, i = 0, c = 0;
  528. const char *p = NULL;
  529. if (num == 0)
  530. return (NULL);
  531. l = 0;
  532. h = num;
  533. while (l < h) {
  534. i = (l + h) / 2;
  535. p = &(base[i * size]);
  536. c = (*cmp) (key, p);
  537. if (c < 0)
  538. h = i;
  539. else if (c > 0)
  540. l = i + 1;
  541. else
  542. break;
  543. }
  544. #ifdef CHARSET_EBCDIC
  545. /*
  546. * THIS IS A KLUDGE - Because the *_obj is sorted in ASCII order, and I
  547. * don't have perl (yet), we revert to a *LINEAR* search when the object
  548. * wasn't found in the binary search.
  549. */
  550. if (c != 0) {
  551. for (i = 0; i < num; ++i) {
  552. p = &(base[i * size]);
  553. c = (*cmp) (key, p);
  554. if (c == 0 || (c < 0 && (flags & OBJ_BSEARCH_VALUE_ON_NOMATCH)))
  555. return p;
  556. }
  557. }
  558. #endif
  559. if (c != 0 && !(flags & OBJ_BSEARCH_VALUE_ON_NOMATCH))
  560. p = NULL;
  561. else if (c == 0 && (flags & OBJ_BSEARCH_FIRST_VALUE_ON_MATCH)) {
  562. while (i > 0 && (*cmp) (key, &(base[(i - 1) * size])) == 0)
  563. i--;
  564. p = &(base[i * size]);
  565. }
  566. return (p);
  567. }
  568. int OBJ_create_objects(BIO *in)
  569. {
  570. char buf[512];
  571. int i, num = 0;
  572. char *o, *s, *l = NULL;
  573. for (;;) {
  574. s = o = NULL;
  575. i = BIO_gets(in, buf, 512);
  576. if (i <= 0)
  577. return (num);
  578. buf[i - 1] = '\0';
  579. if (!isalnum((unsigned char)buf[0]))
  580. return (num);
  581. o = s = buf;
  582. while (isdigit((unsigned char)*s) || (*s == '.'))
  583. s++;
  584. if (*s != '\0') {
  585. *(s++) = '\0';
  586. while (isspace((unsigned char)*s))
  587. s++;
  588. if (*s == '\0')
  589. s = NULL;
  590. else {
  591. l = s;
  592. while ((*l != '\0') && !isspace((unsigned char)*l))
  593. l++;
  594. if (*l != '\0') {
  595. *(l++) = '\0';
  596. while (isspace((unsigned char)*l))
  597. l++;
  598. if (*l == '\0')
  599. l = NULL;
  600. } else
  601. l = NULL;
  602. }
  603. } else
  604. s = NULL;
  605. if ((o == NULL) || (*o == '\0'))
  606. return (num);
  607. if (!OBJ_create(o, s, l))
  608. return (num);
  609. num++;
  610. }
  611. /* return(num); */
  612. }
  613. int OBJ_create(const char *oid, const char *sn, const char *ln)
  614. {
  615. ASN1_OBJECT *tmpoid = NULL;
  616. int ok = 0;
  617. /* Check to see if short or long name already present */
  618. if (OBJ_sn2nid(sn) != NID_undef || OBJ_ln2nid(ln) != NID_undef) {
  619. OBJerr(OBJ_F_OBJ_CREATE, OBJ_R_OID_EXISTS);
  620. return 0;
  621. }
  622. /* Convert numerical OID string to an ASN1_OBJECT structure */
  623. tmpoid = OBJ_txt2obj(oid, 1);
  624. /* If NID is not NID_undef then object already exists */
  625. if (OBJ_obj2nid(tmpoid) != NID_undef) {
  626. OBJerr(OBJ_F_OBJ_CREATE, OBJ_R_OID_EXISTS);
  627. goto err;
  628. }
  629. tmpoid->nid = OBJ_new_nid(1);
  630. tmpoid->sn = (char *)sn;
  631. tmpoid->ln = (char *)ln;
  632. ok = OBJ_add_object(tmpoid);
  633. tmpoid->sn = NULL;
  634. tmpoid->ln = NULL;
  635. err:
  636. ASN1_OBJECT_free(tmpoid);
  637. return ok;
  638. }
  639. size_t OBJ_length(const ASN1_OBJECT *obj)
  640. {
  641. if (obj == NULL)
  642. return 0;
  643. return obj->length;
  644. }
  645. const unsigned char *OBJ_get0_data(const ASN1_OBJECT *obj)
  646. {
  647. if (obj == NULL)
  648. return NULL;
  649. return obj->data;
  650. }