summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoryixiangzhike <yixiangzhike007@163.com>2023-01-13 17:21:40 +0800
committeryixiangzhike <yixiangzhike007@163.com>2023-01-13 17:21:40 +0800
commit61afdd35ffc9478fe9cba2d0a3a575ec9004136b (patch)
tree6e552722a26fe628925f08131ee644d2a67593cb /src
parentaf50859ed95d2fe6d5a46792b4b7666a3d02e6f3 (diff)
downloadcracklib-61afdd35ffc9478fe9cba2d0a3a575ec9004136b.tar.gz
Fix an issue that all words are deleted when there is no valid input data
Fix an issue that dict words in the file pw_dict are deleted when create-cracklib-dict or cracklib-packer has no valid input data. For example: Give an empty file or a file that does't exist or a file has no valid input words to create-cracklib-dict, all words in pw_dict are deleted. $ cracklib-create-dict test Run cracklib-packer and press Enter, all words in pw_dict are deleted. $ cracklib-packer
Diffstat (limited to 'src')
-rw-r--r--src/util/packer.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/util/packer.c b/src/util/packer.c
index e3f9500..be6fbf5 100644
--- a/src/util/packer.c
+++ b/src/util/packer.c
@@ -22,6 +22,7 @@ main(argc, argv)
PWDICT *pwp;
char buffer[STRINGSIZE], prev[STRINGSIZE];
char *file;
+ char opened = 0;
if (argc <= 1)
{
@@ -39,12 +40,6 @@ main(argc, argv)
return (-1);
}
- if (!(pwp = PWOpen(file, "w")))
- {
- perror(file);
- return (-1);
- }
-
wrote = 0;
prev[0] = '\0';
@@ -62,6 +57,16 @@ main(argc, argv)
continue;
}
+ if (!opened)
+ {
+ if (!(pwp = PWOpen(file, "w")))
+ {
+ perror(file);
+ return (-1);
+ }
+ opened = 1;
+ }
+
/*
* If this happens, strcmp() in FindPW() in packlib.c will be unhappy.
*/
@@ -79,7 +84,8 @@ main(argc, argv)
wrote++;
}
- PWClose(pwp);
+ if (opened)
+ PWClose(pwp);
printf("%lu %lu\n", readed, wrote);