patch-smtpclient_main_c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. $OpenBSD: patch-smtpclient_main_c,v 1.2 2003/04/01 18:52:05 sturm Exp $
  2. --- smtpclient_main.c.orig Wed Aug 1 15:25:22 2001
  3. +++ smtpclient_main.c Wed Aug 1 15:33:07 2001
  4. @@ -86,7 +86,7 @@ void log(char *str, ...)
  5. char buf[1024];
  6. va_start(ap, str);
  7. - vsprintf(buf, str, ap);
  8. + vsnprintf(buf, 1024, str, ap);
  9. if (usesyslog)
  10. syslog(LOG_ERR, "SMTPclient: %s", buf);
  11. else
  12. @@ -306,6 +306,7 @@
  13. int s;
  14. int r;
  15. int i;
  16. + size_t ll;
  17. struct passwd *pwd;
  18. char *cp;
  19. @@ -395,16 +395,16 @@ int main(int argc, char **argv)
  20. log("%s: unknown host\n", my_name);
  21. exit(1);
  22. }
  23. - strcpy(my_name, hp->h_name);
  24. + strlcpy(my_name, hp->h_name, sizeof(my_name));
  25. /*
  26. * Determine from address.
  27. */
  28. if (from_addr == NULL) {
  29. if ((pwd = getpwuid(getuid())) == 0) {
  30. - sprintf(buf, "userid-%d@%s", getuid(), my_name);
  31. + snprintf(buf, (sizeof(buf) - 1), "userid-%d@%s", getuid(), my_name);
  32. } else {
  33. - sprintf(buf, "%s@%s", pwd->pw_name, my_name);
  34. + snprintf(buf, (sizeof(buf) - 1), "%s@%s", pwd->pw_name, my_name);
  35. }
  36. from_addr = strdup(buf);
  37. }
  38. @@ -496,12 +497,13 @@
  39. toqp(stdin, sfp);
  40. } else {
  41. while (fgets(buf, sizeof(buf), stdin)) {
  42. - buf[strlen(buf)-1] = 0;
  43. - if (strcmp(buf, ".") == 0) { /* quote alone dots */
  44. - fprintf(sfp, "..\r\n");
  45. - } else { /* pass thru mode */
  46. - fprintf(sfp, "%s\r\n", buf);
  47. + if ((ll = strlen(buf)) > 0 && buf[ll-1] == '\n') {
  48. + buf[ll-1] = 0;
  49. }
  50. + if (buf[0] == '.') { /* quote dots */
  51. + fprintf(sfp, ".");
  52. + }
  53. + fprintf(sfp, "%s\r\n", buf);
  54. }
  55. }