[Pcsclite-cvs-commit] r421 - trunk/PKCS11/src
Ludovic Rousseau
rousseau at costa.debian.org
Tue Mar 28 15:25:22 CEST 2006
Author: rousseau
Date: 2006-03-28 13:25:21 +0000 (Tue, 28 Mar 2006)
New Revision: 421
Modified:
trunk/PKCS11/src/p11x_prefs.c
Log:
util_ReadPreferences(): Don't try to dereference NULL ptr if
getenv("HOME") fails - also, look for pkcs11rc in /etc if there's no
$HOME/.pkcs11rc
Thanks to Iain MacDonnell for the patch
Modified: trunk/PKCS11/src/p11x_prefs.c
===================================================================
--- trunk/PKCS11/src/p11x_prefs.c 2006-03-28 13:20:30 UTC (rev 420)
+++ trunk/PKCS11/src/p11x_prefs.c 2006-03-28 13:25:21 UTC (rev 421)
@@ -356,10 +356,10 @@
** Function: util_ReadPreferences
**
** Gets preferences, if available. On UNIX, looks for .pkcs11rc
-** in the $HOME directory, or root directory if $HOME is not
-** defined. Having a preferences file is optional and it is assumed
-** that most of the time users will not have one unless debug/logging
-** or other special settings are required.
+** in the $HOME directory, or /etc/pkcs11rc, if that is not available.
+** Having a preferences file is optional and it is assumed that most of
+** the time users will not have one unless debug/logging or other special
+** settings are required.
**
** On Windows, looks for pkcs11rc in the following sequence:
** 1. directory containing application. Allow per application
@@ -377,15 +377,22 @@
CK_RV util_ReadPreferences()
{
CK_RV rv = CKR_OK;
- FILE *fp;
+ FILE *fp = NULL;
char rcfilepath[256];
char rcfilename[] = "/.pkcs11rc";
+ char sysrcfilepath[] = "/etc/pkcs11rc";
char buf[1024];
+ char *homeenv;
- strncpy(rcfilepath, getenv("HOME"), sizeof(rcfilepath) - sizeof(rcfilename) - 1);
- strcat(rcfilepath, rcfilename);
+ if (homeenv = getenv("HOME")) {
+ strncpy(rcfilepath, homeenv, sizeof(rcfilepath) - sizeof(rcfilename) - 1);
+ strcat(rcfilepath, rcfilename);
+ fp = fopen(rcfilepath, "rb");
+ }
- fp = fopen(rcfilepath, "rb");
+ if (NULL == fp)
+ fp = fopen(sysrcfilepath, "rb");
+
if (fp)
{
while (fgets(buf, sizeof(buf), fp))
More information about the Pcsclite-cvs-commit
mailing list