Patch for plugin/auth-pam.c
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 21 lines · David Sommerseth
I just decided to do a quick review, I don't believe this has made it into openvpn-2.1.0. But from what I see, I have one concern in regards to a potential memory leak.
The
pam_server()function receives a "message" which puts the information into a "static" memory area which is using structuser_pass. This is fine. Then it callspam_auth()with a pointer to this memory region.The
pam_auth()function callsmy_conv(), and if this function gets a match on USERNAME or PASSWORD value in the block around line 562, it callssearchandreplace()which does astrdup(). This is dynamically allocated withstrdup()and saved intoreturn_value. But! In line 569, you have this line:aresp[i].resp = strdup (return_value);I presume that the aresp[] struct is freed somehow, I have not dug into that now. But you have here a double
strdup()situation if you get a match on USERNAME or PASSWORD. It's almost like saying:
Quoted 8 lines
char *ptr = strdup (strdup ("string")); free(ptr);This code will give you a memory leak.
Please confirm if my assumptions are correct. I would probably suggest to move the
strdup()on line 569 and skip using thereturn_valueat all. Just use aresp[i].resp directly.
OK, I think I'm following you. It seems to me that the strdup() isn't even needed for the no-match case, but I'm leaving it in there lest I break something.
http://thor.chguernsey.com/temp/auth-pam.patch2
http://thor.chguernsey.com/temp/auth-pam.patch2.sig
Patch MD5: 50c9ba7923fe9f60ef73c2d772c62a43 *auth-pam.patch2
Daniel Johnson
[email protected]...
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
iD8DBQFLJEJT6vGcUBY+ge8RAr2PAKD/ID2pAYgoCml3Vfofcm1Xt55T3ACg0138 cC0XIgm13q1xJMMIx13ISNM=
=wG3O
-----END PGP SIGNATURE-----
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 18 lines · Daniel Johnson
Quoted 16 lines · David Sommerseth
The
pam_auth()function callsmy_conv(), and if this function gets a match on USERNAME or PASSWORD value in the block around line 562, it callssearchandreplace()which does astrdup(). This is dynamically allocated withstrdup()and saved intoreturn_value. But! In line 569, you have this line:aresp[i].resp = strdup (return_value);I presume that the aresp[] struct is freed somehow, I have not dug into that now. But you have here a double
strdup()situation if you get a match on USERNAME or PASSWORD. It's almost like saying:char *ptr = strdup (strdup ("string")); free(ptr);This code will give you a memory leak.
Quoted 7 lines
Quoted 3 lines
Please confirm if my assumptions are correct. I would probably suggest to move the
strdup()on line 569 and skip using thereturn_valueat all. Just use aresp[i].resp directly.OK, I think I'm following you. It seems to me that the
strdup()isn't even needed for the no-match case, but I'm leaving it in there lest I break something.
Yes, you followed my thoughts very well :) And doing the strdup() is probably clever in this case in searchandreplace(). But I think I now did spot another potential issue.
- - const char *return_value = NULL;
+ aresp[i].resp = NULL;
This I didn't think about, but I saw another potential leak. However, your idea here is clever! But I would probably suggest:
if( aresp[i].resp ) {
free(aresp[i].resp);
aresp[i].resp = NULL;
}But! The potential culprit here is if the aresp[i] struct is not zeroed before usage. If it is not and this pointer is pointing at something it do not own, your patch is definitely more the correct approach.
Kind regards,
David Sommerseth
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/
iEYEARECAAYFAksktv8ACgkQDC186MBRfrqFOQCeMqU4uF3NrrmBfUo0C3NbDAac zwwAn29ZjHoRk2EdiAd4hr/GVsXTZnJM
=iEdJ
-----END PGP SIGNATURE-----