patch-gnats_cmds_c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. $OpenBSD: patch-gnats_cmds_c,v 1.1 2011/07/08 11:32:17 jasper Exp $
  2. --- gnats/cmds.c.orig Sun Feb 4 21:56:10 2001
  3. +++ gnats/cmds.c Fri Jul 8 13:28:43 2011
  4. @@ -115,28 +115,26 @@ get_text ()
  5. {
  6. register FILE *tf;
  7. char *path = (char *) xmalloc (PATH_MAX);
  8. -#ifndef HAVE_MKTEMP
  9. - char name[L_tmpnam];
  10. -#endif
  11. char *buf, *tmpdir;
  12. MsgType r;
  13. - int i;
  14. + int i, fd;
  15. tmpdir = getenv ("TMPDIR");
  16. if (tmpdir == NULL)
  17. tmpdir = "/tmp"; /* XXX */
  18. -#ifdef HAVE_MKTEMP
  19. - sprintf (path, "%s/gnatsXXXXXX", tmpdir);
  20. - mktemp (path);
  21. -#else
  22. - tmpnam (name);
  23. - strcpy (path, name);
  24. -#endif
  25. -
  26. - if ((tf = fopen (path, "w")) == (FILE *) NULL)
  27. +
  28. + snprintf (path, PATH_MAX, "%s/gnatsXXXXXX", tmpdir);
  29. + if ((fd = mkstemp (path)) < 0)
  30. {
  31. + xfree(path);
  32. + return (NULL);
  33. + }
  34. +
  35. + if ((tf = fdopen (fd, "w")) == (FILE *) NULL)
  36. + {
  37. /* give error that we can't create the temp and leave. */
  38. - xfree (path);
  39. + close(fd);
  40. + xfree(path);
  41. return NULL;
  42. }
  43. @@ -228,8 +226,8 @@ do_query (ac, av)
  44. p = av[i];
  45. if ((n = (char *) strchr (p, '/')) != NULL) /* Remove the category */
  46. p = ++n;
  47. - strcpy (pat, p);
  48. - strcat (pat, "\\'");
  49. + strlcpy (pat, p, sizeof(pat));
  50. + strlcat (pat, "\\'", sizeof(pat));
  51. for (j = index_chain ; j ; j = j->next)
  52. if (regcmp (pat, j->number) == 0)
  53. {
  54. @@ -352,12 +350,13 @@ GNATS_lock (ac, av)
  55. /* XXX FIXME -- we need a cleaner approach to this. */
  56. for (i = 2, len = 0; i < ac; i++)
  57. len += strlen (av[i]);
  58. - l = (char *) xmalloc (sizeof (char) * len + ac - 2);
  59. - sprintf (l, "%s", av[2]);
  60. + len += ac - 2;
  61. + l = (char *) xmalloc (len);
  62. + snprintf (l, len, "%s", av[2]);
  63. for (i = 3; i < ac; i++)
  64. {
  65. - strcat (l, " ");
  66. - strcat (l, av[i]);
  67. + strlcat (l, " ", len);
  68. + strlcat (l, av[i], len);
  69. }
  70. }
  71. @@ -461,7 +460,7 @@ GNATS_user (ac, av)
  72. }
  73. path = (char *) xmalloc (PATH_MAX);
  74. - sprintf (path, "%s/gnats-adm/%s", gnats_root, DB_ACCESS_FILE);
  75. + snprintf (path, PATH_MAX, "%s/gnats-adm/%s", gnats_root, DB_ACCESS_FILE);
  76. access = get_user_access (gnats_root, path, av[0], av[1]);
  77. xfree (path);
  78. @@ -1531,8 +1530,8 @@ GNATS_auth (ac, av)
  79. return;
  80. }
  81. - strcpy (keyfile, gnats_root);
  82. - strcat (keyfile, "/gnats-adm/srvtab");
  83. + strlcpy (keyfile, gnats_root, sizeof(keyfile));
  84. + strlcat (keyfile, "/gnats-adm/srvtab", sizeof(keyfile));
  85. /* Sanity-check installation. */
  86. {
  87. struct stat statbuf;
  88. @@ -1601,7 +1600,7 @@ GNATS_auth (ac, av)
  89. p += 8;
  90. k.ticket.length = strlen (p) / 2;
  91. fromhex (k.ticket.dat, p, k.ticket.length);
  92. - strcpy (instance, "*");
  93. + strlcpy (instance, "*", sizeof(instance));
  94. status = krb_rd_req (&k.ticket, GNATS_KRB4_PRINCIPAL_NAME, instance,
  95. peer.sin_addr.s_addr, &k.auth, keyfile);
  96. if (status != KSUCCESS)