patch-gnats_file-pr_c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. $OpenBSD: patch-gnats_file-pr_c,v 1.2 2007/12/28 17:11:25 espie Exp $
  2. --- gnats/file-pr.c.orig Tue May 8 16:09:45 2001
  3. +++ gnats/file-pr.c Fri Dec 28 18:00:24 2007
  4. @@ -51,7 +51,6 @@ gnats (fp)
  5. char *subject = NULL, *synopsis = NULL;
  6. char *p;
  7. char message[STR_MAX];
  8. - char *from_address;
  9. mode_t mode;
  10. struct stat sbuf;
  11. @@ -97,7 +96,8 @@ gnats (fp)
  12. bug_group = field_value (CATEGORY);
  13. if (find_category (&category, bug_group) == -1)
  14. {
  15. - sprintf (message, "%s from: %s\n", default_category, bug_group);
  16. + snprintf (message, sizeof(message), "%s from: %s\n", default_category,
  17. + bug_group);
  18. log_msg (LOG_INFO, 1, "resetting bug category to ", message);
  19. bug_group = default_category;
  20. set_field (CATEGORY, default_category);
  21. @@ -170,7 +170,7 @@ gnats (fp)
  22. /* The `Subject:' line is assumed to have a newline at the end. */
  23. int l = strlen (synopsis);
  24. char *buf = (char *) xmalloc (l + 2);
  25. - strcpy (buf, synopsis);
  26. + strlcpy (buf, synopsis, l + 2);
  27. buf[l] = '\n';
  28. buf[l + 1] = '\0';
  29. set_header (SUBJECT, buf);
  30. @@ -209,7 +209,7 @@ gnats (fp)
  31. /* Put together the path to where the bug will be stored. If the dir
  32. is not there, and the category is the default, auto-create that one,
  33. if we want to. If not, make the bug pending, and store in there. */
  34. - sprintf (path, "%s/%s", gnats_root, bug_group);
  35. + snprintf (path, PATH_MAX, "%s/%s", gnats_root, bug_group);
  36. err = stat (path, &sbuf);
  37. if (err == -1 && !flag_autocreate)
  38. {
  39. @@ -217,7 +217,7 @@ gnats (fp)
  40. set_field (CATEGORY, default_category);
  41. log_msg (LOG_INFO, 1, "directory does not exist, changing to default:",
  42. path);
  43. - sprintf (path, "%s/%s", gnats_root, bug_group);
  44. + snprintf (path, PATH_MAX, "%s/%s", gnats_root, bug_group);
  45. err = stat (path, &sbuf);
  46. }
  47. @@ -254,7 +254,7 @@ gnats (fp)
  48. /* Retrieve a unique bug number. */
  49. bug_number = get_bug_number ();
  50. - sprintf (number, "%d", bug_number);
  51. + snprintf (number, sizeof(number), "%d", bug_number);
  52. set_field (NUMBER, number);
  53. /* Make sure all the values are ok; patch in any bogons, and keep
  54. @@ -262,8 +262,8 @@ gnats (fp)
  55. bad_enums = check_enum_types (1);
  56. /* Write the file out. */
  57. - sprintf (bug_name, "%s/%d", bug_group, bug_number);
  58. - sprintf (path, "%s/%s", gnats_root, bug_name);
  59. + snprintf (bug_name, sizeof(bug_name), "%s/%d", bug_group, bug_number);
  60. + snprintf (path, PATH_MAX, "%s/%s", gnats_root, bug_name);
  61. create_report (path, 1);
  62. log_msg (LOG_INFO, 1, "PR written out:", path);
  63. @@ -345,9 +345,10 @@ run_atpr (submitter, expired, bug_name, path)
  64. int len, i;
  65. static char *ats[] = { "/usr/bin/at", "/bin/at", NULL };
  66. - at_pr = (char *) xmalloc (strlen (bindir) + 7);
  67. - strcpy (at_pr, bindir);
  68. - strcat (at_pr, "/at-pr");
  69. + len = strlen (bindir) + 7;
  70. + at_pr = (char *) xmalloc (len);
  71. + strlcpy (at_pr, bindir, len);
  72. + strlcat (at_pr, "/at-pr", len);
  73. len = strftime (buf, GNATS_TIME_LENGTH, "%H:%M %b %d", expired);
  74. @@ -355,8 +356,9 @@ run_atpr (submitter, expired, bug_name, path)
  75. {
  76. if (access (ats[i], X_OK) == 0)
  77. {
  78. - command = (char *) xmalloc (len + strlen (ats[i]) + 2);
  79. - sprintf (command, "%s %s", ats[i], buf);
  80. + len += strlen (ats[i]) + 2;
  81. + command = (char *) xmalloc (len);
  82. + snprintf (command, len, "%s %s", ats[i], buf);
  83. break;
  84. }
  85. }
  86. @@ -410,7 +412,7 @@ check_if_reply ()
  87. if (*s == '\0')
  88. return NULL;
  89. - strcpy (token, s);
  90. + strlcpy (token, s, sizeof(token));
  91. s = token;
  92. re_set_syntax (RE_NO_BK_PARENS);
  93. @@ -487,7 +489,7 @@ check_if_reply ()
  94. else
  95. {
  96. path = xmalloc (PATH_MAX);
  97. - sprintf (path, "%s/%s", gnats_root, s + start);
  98. + snprintf (path, PATH_MAX, "%s/%s", gnats_root, s + start);
  99. }
  100. if (stat (path, &buf) == -1)
  101. {
  102. @@ -513,12 +515,11 @@ derive_submitter ()
  103. char *compare;
  104. char *name, *alias, *s, *t;
  105. - int i, start, end;
  106. FILE *fp;
  107. from_address = header_value (FROM);
  108. - strcpy (from_string, from_address);
  109. + strlcpy (from_string, from_address, sizeof(from_string));
  110. if ((*from_string == '\0') || (*from_string == '\n'))
  111. {
  112. @@ -540,7 +541,7 @@ derive_submitter ()
  113. if ((*t == ' ') || (*t == '\n'))
  114. *t = '\0';
  115. }
  116. - sprintf (path, "%s/gnats-adm/addresses", gnats_root);
  117. + snprintf (path, sizeof(path), "%s/gnats-adm/addresses", gnats_root);
  118. if ((fp = fopen (path, "r")) == (FILE *) NULL)
  119. {
  120. xfree (token);
  121. @@ -686,8 +687,8 @@ append_notify (person)
  122. notify = (char *) xrealloc (notify, notify_size);
  123. }
  124. - strcat (notify, n);
  125. - strcat (notify, ", ");
  126. + strlcat (notify, n, STR_MAX);
  127. + strlcat (notify, ", ", STR_MAX);
  128. notify_len += i + 2;
  129. p = start;
  130. @@ -701,14 +702,15 @@ append_notify (person)
  131. }
  132. static void
  133. -try_append_notify (notify, string)
  134. +try_append_notify (notify, string, len)
  135. char *notify;
  136. char *string;
  137. + size_t len;
  138. {
  139. char *try = append_notify (string);
  140. if (try != NULL)
  141. {
  142. - strcat (notify, try);
  143. + strlcat (notify, try, len);
  144. xfree (try);
  145. }
  146. }
  147. @@ -729,13 +731,13 @@ notify_responsible (responsible, subcontact, subnotify
  148. notify[0] = '\0';
  149. - try_append_notify (notify, subcontact);
  150. - try_append_notify (notify, subnotify);
  151. - try_append_notify (notify, cnotify);
  152. + try_append_notify (notify, subcontact, BUFSIZ);
  153. + try_append_notify (notify, subnotify, BUFSIZ);
  154. + try_append_notify (notify, cnotify, BUFSIZ);
  155. {
  156. char *gnotify = (char *) strdup (header_value (X_GNATS_NOTIFY));
  157. - try_append_notify (notify, gnotify);
  158. + try_append_notify (notify, gnotify, BUFSIZ);
  159. xfree (gnotify);
  160. }
  161. @@ -897,7 +899,7 @@ append_report (infile, filename)
  162. time_t t;
  163. /* Where to keep the static index if necessary. */
  164. Index *current_index = (Index *)NULL;
  165. - Index *i, *prev_index = NULL, *old_index = NULL;
  166. + Index *i;
  167. /* Save the values we read while in main(). */
  168. from = (char *) strdup (header_value (FROM));
  169. @@ -934,15 +936,15 @@ append_report (infile, filename)
  170. /* Separate this from the rest of the audit trail. */
  171. APPEND_STRING ((char*)"\n", buf, b, buf_len, buf_max, l, 0);
  172. - sprintf (line, "From: %s", from);
  173. + snprintf (line, STR_MAXLONG, "From: %s", from);
  174. APPEND_STRING (line, buf, b, buf_len, buf_max, l, 0);
  175. - sprintf (line, "To: %s", to);
  176. + snprintf (line, STR_MAXLONG, "To: %s", to);
  177. APPEND_STRING (line, buf, b, buf_len, buf_max, l, 0);
  178. - sprintf (line, "Cc: %s", cc);
  179. + snprintf (line, STR_MAXLONG, "Cc: %s", cc);
  180. APPEND_STRING (line, buf, b, buf_len, buf_max, l, 0);
  181. - sprintf (line, "Subject: %s", subject);
  182. + snprintf (line, STR_MAXLONG, "Subject: %s", subject);
  183. APPEND_STRING (line, buf, b, buf_len, buf_max, l, 0);
  184. - sprintf (line, "Date: %s", date);
  185. + snprintf (line, STR_MAXLONG, "Date: %s", date);
  186. APPEND_STRING (line, buf, b, buf_len, buf_max, l, 0);
  187. APPEND_STRING ((char*)"\n", buf, b, buf_len, buf_max, l, 0);
  188. @@ -988,7 +990,7 @@ append_report (infile, filename)
  189. {
  190. t = get_date (date, NULL);
  191. i->last_modified = (char *) xmalloc (18);
  192. - sprintf (i->last_modified, "%d", t);
  193. + snprintf (i->last_modified, 18, "%d", t);
  194. /* write out the new index. */
  195. write_index (current_index);
  196. break;
  197. @@ -1073,7 +1075,7 @@ get_bug_number ()
  198. /* First try to find and lock the gnats lock file. We need this since
  199. they want every bug to have a unique number. If lock doesn't exist,
  200. make it, if possible. */
  201. - sprintf (sbuf, "%s/gnats-adm/current", gnats_root);
  202. + snprintf (sbuf, sizeof(sbuf), "%s/gnats-adm/current", gnats_root);
  203. block_signals ();