result.data = malloc(inText->len+1); result.len = inText->len+1;
result.data = NULL; result.len  = 0;
main (int argc, char **argv){    int		 retval = 0;  /* 0 - test succeeded.  -1 - test failed */    SECStatus	 rv;    PLOptState	*optstate;    char	*program_name;    char  *input_file = NULL; 	/* read encrypted data from here (or create) */    char  *output_file = NULL;	/* write new encrypted data here */    char  *log_file = NULL;	/* write new encrypted data here */    FILE	*inFile = stdin;    FILE	*outFile = stdout;    FILE	*logFile = NULL;    PLOptStatus optstatus;    SECItem	result;    int		c;    result.data = 0;    program_name = PL_strrchr(argv[0], '/');    program_name = program_name ? (program_name + 1) : argv[0];    optstate = PL_CreateOptState (argc, argv, "Hd:i:o:l:?");    if (optstate == NULL) {	SECU_PrintError (program_name, "PL_CreateOptState failed");	return 1;    }    while ((optstatus = PL_GetNextOpt(optstate)) == PL_OPT_OK) {	switch (optstate->option) {	  case '?':	    short_usage (program_name);	    return 1;	  case 'H':	    long_usage (program_name);	    return 1;	  case 'd':	    SECU_ConfigDirectory(optstate->value);	    break;          case 'i':            input_file = PL_strdup(optstate->value);            break;          case 'o':            output_file = PL_strdup(optstate->value);            break;          case 'l':            log_file = PL_strdup(optstate->value);            break;	}    }    PL_DestroyOptState(optstate);    if (optstatus == PL_OPT_BAD) {	short_usage (program_name);	return 1;    }    if (input_file) {      inFile = fopen(input_file,"r");      if (inFile == NULL) {	perror(input_file);	return 1;      }      PR_Free(input_file);    }    if (output_file) {      outFile = fopen(output_file,"w+");      if (outFile == NULL) {	perror(output_file);	return 1;      }      PR_Free(output_file);    }    if (log_file) {      logFile = fopen(log_file,"w+");      if (logFile == NULL) {	perror(log_file);	return 1;      }      PR_Free(log_file);    }    /*     * Initialize the Security libraries.     */    PK11_SetPasswordFunc(SECU_GetModulePassword);    rv = NSS_Init(SECU_ConfigDirectory(NULL));    if (rv != SECSuccess) {	SECU_PrintError (program_name, "NSS_Init failed");	retval = 1;	goto prdone;    }    /* Get the encrypted result, either from the input file     * or from encrypting the plaintext value     */    while ((c = getc(inFile)) != EOF) {	if (c == 'M') {	   char *dataString = NULL;	   SECItem *inText;	   rv = getData(inFile, &dataString);	   if (!rv) {		fputs(dataString,outFile);		free(dataString);		continue;	   }	   inText = NSSBase64_DecodeBuffer(NULL, NULL, dataString,							strlen(dataString));	   if ((inText == NULL) || (inText->len == 0)) {		if (logFile) {		    fprintf(logFile,"Base 64 decode failed on <%s>\n",								dataString);		    fprintf(logFile," Error %x: %s\n",PORT_GetError(),			SECU_Strerror(PORT_GetError()));		}		fputs(dataString,outFile);		free(dataString);		continue;	   }	   result.data = malloc(inText->len+1);	   result.len = inText->len+1;	   rv = PK11SDR_Decrypt(inText, &result, NULL);	   SECITEM_FreeItem(inText, PR_TRUE);	   if (rv != SECSuccess) {		if (logFile) {		    fprintf(logFile,"SDR decrypt failed on <%s>\n",								dataString);		    fprintf(logFile," Error %x: %s\n",PORT_GetError(),			SECU_Strerror(PORT_GetError()));		}		fputs(dataString,outFile);		free(dataString);		free(result.data);		continue;	   }	   result.data[result.len] = 0;	   fputs(result.data,outFile);	   free(result.data);         } else {	   putc(c,outFile);         }    }    fclose(outFile);    fclose(inFile);    if (logFile) {	fclose(logFile);    }    if (NSS_Shutdown() != SECSuccess) {	SECU_PrintError (program_name, "NSS_Shutdown failed");       exit(1);    }prdone:    PR_Cleanup ();    return retval;}