summaryrefslogtreecommitdiff
path: root/security/nss/cmd
diff options
context:
space:
mode:
authornelson%bolyard.com <devnull@localhost>2008-06-13 05:28:55 +0000
committernelson%bolyard.com <devnull@localhost>2008-06-13 05:28:55 +0000
commitd0f905b55bce29b850e9f8480da2cdb9f844939b (patch)
tree4cab2ec5027ad32d45c6b4ec9601a44240790ed6 /security/nss/cmd
parentfc7013a0ed553ab0f780e4ec55c6052843767a20 (diff)
downloadnss-hg-d0f905b55bce29b850e9f8480da2cdb9f844939b.tar.gz
Back out last checkin, which introduced crashes in pk12util. Sheriff Nelson
Diffstat (limited to 'security/nss/cmd')
-rw-r--r--security/nss/cmd/lib/secutil.c60
1 files changed, 11 insertions, 49 deletions
diff --git a/security/nss/cmd/lib/secutil.c b/security/nss/cmd/lib/secutil.c
index 364ff9879..8f24884d8 100644
--- a/security/nss/cmd/lib/secutil.c
+++ b/security/nss/cmd/lib/secutil.c
@@ -213,75 +213,37 @@ SECU_GetPasswordString(void *arg, char *prompt)
char *
SECU_FilePasswd(PK11SlotInfo *slot, PRBool retry, void *arg)
{
- char* phrases, *phrase;
+ unsigned char phrase[200];
PRFileDesc *fd;
PRInt32 nb;
char *pwFile = arg;
int i;
- const long maxPwdFileSize = 4096;
- char* tokenName;
- int tokenLen;
if (!pwFile)
return 0;
if (retry) {
return 0; /* no good retrying - the files contents will be the same */
- }
-
- phrases = PORT_ZAlloc(maxPwdFileSize);
-
- if (!phrases) {
- return 0; /* out of memory */
- }
+ }
fd = PR_Open(pwFile, PR_RDONLY, 0);
if (!fd) {
fprintf(stderr, "No password file \"%s\" exists.\n", pwFile);
- PORT_Free(phrases);
return NULL;
}
- nb = PR_Read(fd, phrases, maxPwdFileSize);
+ nb = PR_Read(fd, phrase, sizeof(phrase));
PR_Close(fd);
-
+ /* handle the Windows EOL case */
+ i = 0;
+ while (phrase[i] != '\r' && phrase[i] != '\n' && i < nb) i++;
+ phrase[i] = '\0';
if (nb == 0) {
- fprintf(stderr,"password file contains no data\n");
- PORT_Free(phrases);
- return NULL;
+ fprintf(stderr,"password file contains no data\n");
+ return NULL;
}
-
- tokenName = PK11_GetTokenName(slot);
- tokenLen = PORT_Strlen(tokenName);
- i = 0;
- do
- {
- int startphrase = i;
- int phraseLen;
-
- /* handle the Windows EOL case */
- while (phrases[i] != '\r' && phrases[i] != '\n' && i < nb) i++;
- /* terminate passphrase */
- phrases[i++] = '\0';
- /* clean up any EOL before the start of the next passphrase */
- while ( (i<nb) && (phrases[i] == '\r' || phrases[i] == '\n')) {
- phrases[i++] = '\0';
- }
- /* now analyze the current passphrase */
- phrase = &phrases[startphrase];
- if (PORT_Strncmp(phrase, tokenName, tokenLen)) continue;
- phraseLen = PORT_Strlen(phrase);
- if (phraseLen < (tokenLen+1)) continue;
- if (phrase[tokenLen] != ':') continue;
- phrase = &phrase[tokenLen+1];
- break;
-
- } while (i<nb);
-
- phrase = PORT_Strdup((char*)phrase);
- PORT_Free(phrases);
- return phrase;
+ return (char*) PORT_Strdup((char*)phrase);
}
char *
@@ -3314,7 +3276,7 @@ SECU_ParseCommandLine(int argc, char **argv, char *progName,
int i, j;
int lcmd = 0, lopt = 0;
- optstring = (char *)PORT_Alloc(cmd->numCommands + 2*cmd->numOptions+1);
+ optstring = (char *)PORT_Alloc(cmd->numCommands + 2*cmd->numOptions);
if (optstring == NULL)
return SECFailure;