0001-Fix-error-handling-in-gdbm.patch 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. From 6b638fa9afbeb54dfa19378e391465a5284ce1ad Mon Sep 17 00:00:00 2001
  2. From: Changqing Li <changqing.li@windriver.com>
  3. Date: Wed, 12 Sep 2018 17:16:36 +0800
  4. Subject: [PATCH] Fix error handling in gdbm
  5. Only check for gdbm_errno if the return value of the called gdbm_*
  6. function says so. This fixes apr-util with gdbm 1.14, which does not
  7. seem to always reset gdbm_errno.
  8. Also make the gdbm driver return error codes starting with
  9. APR_OS_START_USEERR instead of always returning APR_EGENERAL. This is
  10. what the berkleydb driver already does.
  11. Also ensure that dsize is 0 if dptr == NULL.
  12. Upstream-Status: Backport[https://svn.apache.org/viewvc?
  13. view=revision&amp;revision=1825311]
  14. Signed-off-by: Changqing Li <changqing.li@windriver.com>
  15. ---
  16. dbm/apr_dbm_gdbm.c | 47 +++++++++++++++++++++++++++++------------------
  17. 1 file changed, 29 insertions(+), 18 deletions(-)
  18. diff --git a/dbm/apr_dbm_gdbm.c b/dbm/apr_dbm_gdbm.c
  19. index 749447a..1c86327 100644
  20. --- a/dbm/apr_dbm_gdbm.c
  21. +++ b/dbm/apr_dbm_gdbm.c
  22. @@ -36,13 +36,25 @@
  23. static apr_status_t g2s(int gerr)
  24. {
  25. if (gerr == -1) {
  26. - /* ### need to fix this */
  27. - return APR_EGENERAL;
  28. + if (gdbm_errno == GDBM_NO_ERROR)
  29. + return APR_SUCCESS;
  30. + return APR_OS_START_USEERR + gdbm_errno;
  31. }
  32. return APR_SUCCESS;
  33. }
  34. +static apr_status_t gdat2s(datum d)
  35. +{
  36. + if (d.dptr == NULL) {
  37. + if (gdbm_errno == GDBM_NO_ERROR || gdbm_errno == GDBM_ITEM_NOT_FOUND)
  38. + return APR_SUCCESS;
  39. + return APR_OS_START_USEERR + gdbm_errno;
  40. + }
  41. +
  42. + return APR_SUCCESS;
  43. +}
  44. +
  45. static apr_status_t datum_cleanup(void *dptr)
  46. {
  47. if (dptr)
  48. @@ -53,22 +65,15 @@ static apr_status_t datum_cleanup(void *dptr)
  49. static apr_status_t set_error(apr_dbm_t *dbm, apr_status_t dbm_said)
  50. {
  51. - apr_status_t rv = APR_SUCCESS;
  52. - /* ### ignore whatever the DBM said (dbm_said); ask it explicitly */
  53. + dbm->errcode = dbm_said;
  54. - if ((dbm->errcode = gdbm_errno) == GDBM_NO_ERROR) {
  55. + if (dbm_said == APR_SUCCESS)
  56. dbm->errmsg = NULL;
  57. - }
  58. - else {
  59. - dbm->errmsg = gdbm_strerror(gdbm_errno);
  60. - rv = APR_EGENERAL; /* ### need something better */
  61. - }
  62. -
  63. - /* captured it. clear it now. */
  64. - gdbm_errno = GDBM_NO_ERROR;
  65. + else
  66. + dbm->errmsg = gdbm_strerror(dbm_said - APR_OS_START_USEERR);
  67. - return rv;
  68. + return dbm_said;
  69. }
  70. /* --------------------------------------------------------------------------
  71. @@ -107,7 +112,7 @@ static apr_status_t vt_gdbm_open(apr_dbm_t **pdb, const char *pathname,
  72. NULL);
  73. if (file == NULL)
  74. - return APR_EGENERAL; /* ### need a better error */
  75. + return APR_OS_START_USEERR + gdbm_errno; /* ### need a better error */
  76. /* we have an open database... return it */
  77. *pdb = apr_pcalloc(pool, sizeof(**pdb));
  78. @@ -141,10 +146,12 @@ static apr_status_t vt_gdbm_fetch(apr_dbm_t *dbm, apr_datum_t key,
  79. if (pvalue->dptr)
  80. apr_pool_cleanup_register(dbm->pool, pvalue->dptr, datum_cleanup,
  81. apr_pool_cleanup_null);
  82. + else
  83. + pvalue->dsize = 0;
  84. /* store the error info into DBM, and return a status code. Also, note
  85. that *pvalue should have been cleared on error. */
  86. - return set_error(dbm, APR_SUCCESS);
  87. + return set_error(dbm, gdat2s(rd));
  88. }
  89. static apr_status_t vt_gdbm_store(apr_dbm_t *dbm, apr_datum_t key,
  90. @@ -201,9 +208,11 @@ static apr_status_t vt_gdbm_firstkey(apr_dbm_t *dbm, apr_datum_t *pkey)
  91. if (pkey->dptr)
  92. apr_pool_cleanup_register(dbm->pool, pkey->dptr, datum_cleanup,
  93. apr_pool_cleanup_null);
  94. + else
  95. + pkey->dsize = 0;
  96. /* store any error info into DBM, and return a status code. */
  97. - return set_error(dbm, APR_SUCCESS);
  98. + return set_error(dbm, gdat2s(rd));
  99. }
  100. static apr_status_t vt_gdbm_nextkey(apr_dbm_t *dbm, apr_datum_t *pkey)
  101. @@ -221,9 +230,11 @@ static apr_status_t vt_gdbm_nextkey(apr_dbm_t *dbm, apr_datum_t *pkey)
  102. if (pkey->dptr)
  103. apr_pool_cleanup_register(dbm->pool, pkey->dptr, datum_cleanup,
  104. apr_pool_cleanup_null);
  105. + else
  106. + pkey->dsize = 0;
  107. /* store any error info into DBM, and return a status code. */
  108. - return set_error(dbm, APR_SUCCESS);
  109. + return set_error(dbm, gdat2s(rd));
  110. }
  111. static void vt_gdbm_freedatum(apr_dbm_t *dbm, apr_datum_t data)
  112. --
  113. 2.7.4