0013-Don-t-use-la-files-for-opening-plugins.patch 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. From: Debian Cyrus SASL Team
  2. <pkg-cyrus-sasl2-debian-devel@lists.alioth.debian.org>
  3. Date: Thu, 24 Mar 2016 11:35:04 +0100
  4. Subject: Don't use la files for opening plugins
  5. ---
  6. lib/dlopen.c | 121 ++++-------------------------------------------------------
  7. 1 file changed, 7 insertions(+), 114 deletions(-)
  8. diff --git a/lib/dlopen.c b/lib/dlopen.c
  9. index 8284cd8..ef90b11 100644
  10. --- a/lib/dlopen.c
  11. +++ b/lib/dlopen.c
  12. @@ -246,113 +246,6 @@ static int _sasl_plugin_load(char *plugin, void *library,
  13. return result;
  14. }
  15. -/* this returns the file to actually open.
  16. - * out should be a buffer of size PATH_MAX
  17. - * and may be the same as in. */
  18. -
  19. -/* We'll use a static buffer for speed unless someone complains */
  20. -#define MAX_LINE 2048
  21. -
  22. -static int _parse_la(const char *prefix, const char *in, char *out)
  23. -{
  24. - FILE *file;
  25. - size_t length;
  26. - char line[MAX_LINE];
  27. - char *ntmp = NULL;
  28. -
  29. - if(!in || !out || !prefix || out == in) return SASL_BADPARAM;
  30. -
  31. - /* Set this so we can detect failure */
  32. - *out = '\0';
  33. -
  34. - length = strlen(in);
  35. -
  36. - if (strcmp(in + (length - strlen(LA_SUFFIX)), LA_SUFFIX)) {
  37. - if(!strcmp(in + (length - strlen(SO_SUFFIX)),SO_SUFFIX)) {
  38. - /* check for a .la file */
  39. - if (strlen(prefix) + strlen(in) + strlen(LA_SUFFIX) + 1 >= MAX_LINE)
  40. - return SASL_BADPARAM;
  41. - strcpy(line, prefix);
  42. - strcat(line, in);
  43. - length = strlen(line);
  44. - *(line + (length - strlen(SO_SUFFIX))) = '\0';
  45. - strcat(line, LA_SUFFIX);
  46. - file = fopen(line, "r");
  47. - if(file) {
  48. - /* We'll get it on the .la open */
  49. - fclose(file);
  50. - return SASL_FAIL;
  51. - }
  52. - }
  53. - if (strlen(prefix) + strlen(in) + 1 >= PATH_MAX)
  54. - return SASL_BADPARAM;
  55. - strcpy(out, prefix);
  56. - strcat(out, in);
  57. - return SASL_OK;
  58. - }
  59. -
  60. - if (strlen(prefix) + strlen(in) + 1 >= MAX_LINE)
  61. - return SASL_BADPARAM;
  62. - strcpy(line, prefix);
  63. - strcat(line, in);
  64. -
  65. - file = fopen(line, "r");
  66. - if(!file) {
  67. - _sasl_log(NULL, SASL_LOG_WARN,
  68. - "unable to open LA file: %s", line);
  69. - return SASL_FAIL;
  70. - }
  71. -
  72. - while(!feof(file)) {
  73. - if(!fgets(line, MAX_LINE, file)) break;
  74. - if(line[strlen(line) - 1] != '\n') {
  75. - _sasl_log(NULL, SASL_LOG_WARN,
  76. - "LA file has too long of a line: %s", in);
  77. - fclose(file);
  78. - return SASL_BUFOVER;
  79. - }
  80. - if(line[0] == '\n' || line[0] == '#') continue;
  81. - if(!strncmp(line, "dlname=", sizeof("dlname=") - 1)) {
  82. - /* We found the line with the name in it */
  83. - char *end;
  84. - char *start;
  85. - size_t len;
  86. - end = strrchr(line, '\'');
  87. - if(!end) continue;
  88. - start = &line[sizeof("dlname=")-1];
  89. - len = strlen(start);
  90. - if(len > 3 && start[0] == '\'') {
  91. - ntmp=&start[1];
  92. - *end='\0';
  93. - /* Do we have dlname="" ? */
  94. - if(ntmp == end) {
  95. - _sasl_log(NULL, SASL_LOG_DEBUG,
  96. - "dlname is empty in .la file: %s", in);
  97. - fclose(file);
  98. - return SASL_FAIL;
  99. - }
  100. - strcpy(out, prefix);
  101. - strcat(out, ntmp);
  102. - }
  103. - break;
  104. - }
  105. - }
  106. - if(ferror(file) || feof(file)) {
  107. - _sasl_log(NULL, SASL_LOG_WARN,
  108. - "Error reading .la: %s\n", in);
  109. - fclose(file);
  110. - return SASL_FAIL;
  111. - }
  112. - fclose(file);
  113. -
  114. - if(!(*out)) {
  115. - _sasl_log(NULL, SASL_LOG_WARN,
  116. - "Could not find a dlname line in .la file: %s", in);
  117. - return SASL_FAIL;
  118. - }
  119. -
  120. - return SASL_OK;
  121. -}
  122. #endif /* DO_DLOPEN */
  123. /* loads a plugin library */
  124. @@ -506,18 +399,18 @@ int _sasl_load_plugins(const add_plugin_list_t *entrypoints,
  125. if (length + pos>=PATH_MAX) continue; /* too big */
  126. if (strcmp(dir->d_name + (length - strlen(SO_SUFFIX)),
  127. - SO_SUFFIX)
  128. - && strcmp(dir->d_name + (length - strlen(LA_SUFFIX)),
  129. - LA_SUFFIX))
  130. + SO_SUFFIX))
  131. continue;
  132. + /* We only use .so files for loading plugins */
  133. +
  134. memcpy(name,dir->d_name,length);
  135. name[length]='\0';
  136. - result = _parse_la(prefix, name, tmp);
  137. - if(result != SASL_OK)
  138. - continue;
  139. -
  140. + /* Create full name with path */
  141. + strncpy(tmp, prefix, PATH_MAX);
  142. + strncat(tmp, name, PATH_MAX);
  143. +
  144. /* skip "lib" and cut off suffix --
  145. this only need be approximate */
  146. strcpy(plugname, name + 3);