patch-authenticate_c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. $OpenBSD: patch-authenticate_c,v 1.1 2001/02/19 15:00:55 danh Exp $
  2. --- authenticate.c.orig Tue Jan 30 12:43:55 2001
  3. +++ authenticate.c Tue Jan 30 12:43:55 2001
  4. @@ -28,7 +28,7 @@ static /*const*/char rcsid[]=
  5. #else
  6. #include "config.h"
  7. -#define _XOPEN_SOURCE
  8. +/* #define _XOPEN_SOURCE */
  9. #include <sys/types.h>
  10. #include <unistd.h>
  11. @@ -50,7 +50,7 @@ static /*const*/char rcsid[]=
  12. #define VIRTUALUSER "vpop"
  13. #ifndef MAILSPOOLDIR
  14. -#define MAILSPOOLDIR "/var/spool/mail/" /* watch the trailing / */
  15. +#define MAILSPOOLDIR "/var/mail/" /* watch the trailing / */
  16. #endif
  17. #ifndef MAILSPOOLHASH
  18. #define MAILSPOOLHASH 0 /* 2 would deliver to /var/spool/mail/b/a/bar */
  19. @@ -100,6 +100,7 @@ static void getlogname(user,sock)const c
  20. struct sockaddr_in sockname;
  21. #endif
  22. int namelen=sizeof sockname;const char*retval="";
  23. + void *p;
  24. if(!getsockname(sock,(struct sockaddr*)&sockname,&namelen))
  25. {
  26. #ifdef INET6
  27. @@ -115,16 +116,17 @@ static void getlogname(user,sock)const c
  28. retval=hent->h_name;
  29. #endif
  30. }
  31. - if(auth_logname= /* memory leak when out of memory */
  32. - realloc(auth_logname,(namelen=strlen(retval))+1+strlen(user)+1))
  33. - { strcpy(auth_logname,retval)[namelen]='/';
  34. + if(p=realloc(auth_logname,(namelen=strlen(retval))+1+strlen(user)+1))
  35. + { auth_logname=p;
  36. + strcpy(auth_logname,retval)[namelen]='/';
  37. strcpy(auth_logname+namelen+1,user);
  38. - }
  39. + } else { free(auth_logname); auth_logname=NULL; }
  40. }
  41. static const struct passwd*cgetpwnam(user,sock)const char*user;
  42. const int sock;
  43. {
  44. + void *p;
  45. #ifdef VIRTUALSERVER
  46. DB_ENV dbenv;DB*db;
  47. memset(&dbenv,0,sizeof dbenv);
  48. @@ -155,14 +157,18 @@ freesec: { free(authi.usersecret);
  49. novirt: strcpy(auth_logname,user);
  50. }
  51. db->close(db,0);
  52. - } /* memory leak when out of memory */
  53. - else if(auth_logname=realloc(auth_logname,strlen(user)+1))
  54. - strcpy(auth_logname,user); /* DB doesn't exist */
  55. + }
  56. + else if(p=realloc(auth_logname,strlen(user)+1))
  57. + { auth_logname=p;
  58. + strcpy(auth_logname,user); /* DB doesn't exist */
  59. + } else { free(auth_logname); auth_logname=NULL; }
  60. db_appexit(&dbenv);
  61. }
  62. else /* DB subsystem problem */
  63. - { if(auth_logname=realloc(auth_logname,strlen(user)+1))
  64. - strcpy(auth_logname,user);
  65. + { if(p=realloc(auth_logname,strlen(user)+1))
  66. + { auth_logname=p;
  67. + strcpy(auth_logname,user);
  68. + } else { free(auth_logname); auth_logname=NULL; }
  69. }
  70. #endif
  71. return getpwnam(user); /* this should be selfexplanatory :-) */