I _think_ this should fix the problem reported by `Stacey': failure

to fclose a private key file.

[originally from svn r3552]
This commit is contained in:
Simon Tatham 2003-11-19 17:30:16 +00:00
Родитель a9e286ad57
Коммит a06375ab96
1 изменённых файлов: 9 добавлений и 2 удалений

Просмотреть файл

@ -182,6 +182,9 @@ int loadrsakey(const Filename *filename, struct RSAKey *key, char *passphrase,
* key file. * key file.
*/ */
if (fgets(buf, sizeof(buf), fp) && !strcmp(buf, rsa_signature)) { if (fgets(buf, sizeof(buf), fp) && !strcmp(buf, rsa_signature)) {
/*
* This routine will take care of calling fclose() for us.
*/
ret = loadrsakey_main(fp, key, FALSE, NULL, passphrase, &error); ret = loadrsakey_main(fp, key, FALSE, NULL, passphrase, &error);
goto end; goto end;
} }
@ -189,10 +192,10 @@ int loadrsakey(const Filename *filename, struct RSAKey *key, char *passphrase,
/* /*
* Otherwise, we have nothing. Return empty-handed. * Otherwise, we have nothing. Return empty-handed.
*/ */
fclose(fp);
error = "not an SSH-1 RSA file"; error = "not an SSH-1 RSA file";
end: end:
fclose(fp);
if ((ret != 1) && errorstr) if ((ret != 1) && errorstr)
*errorstr = error; *errorstr = error;
return ret; return ret;
@ -217,6 +220,9 @@ int rsakey_encrypted(const Filename *filename, char **comment)
*/ */
if (fgets(buf, sizeof(buf), fp) && !strcmp(buf, rsa_signature)) { if (fgets(buf, sizeof(buf), fp) && !strcmp(buf, rsa_signature)) {
const char *dummy; const char *dummy;
/*
* This routine will take care of calling fclose() for us.
*/
return loadrsakey_main(fp, NULL, FALSE, comment, NULL, &dummy); return loadrsakey_main(fp, NULL, FALSE, comment, NULL, &dummy);
} }
fclose(fp); fclose(fp);
@ -261,10 +267,11 @@ int rsakey_pubblob(const Filename *filename, void **blob, int *bloblen,
} }
} else { } else {
error = "not an SSH-1 RSA file"; error = "not an SSH-1 RSA file";
fclose(fp);
} }
end: end:
if (fp)
fclose(fp);
if ((ret != 1) && errorstr) if ((ret != 1) && errorstr)
*errorstr = error; *errorstr = error;
return ret; return ret;