diff --git a/lib/util/utilmod.c b/lib/util/utilmod.c
--- a/lib/util/utilmod.c
+++ b/lib/util/utilmod.c
@@ -227,20 +227,25 @@ nssutil_ReadSecmodDB(const char *appName
* the following loop takes line separated config lines and collapses
* the lines to a single string, escaping and quoting as necessary.
*/
/* loop state variables */
moduleString = NULL; /* current concatenated string */
internal = PR_FALSE; /* is this an internal module */
skipParams = PR_FALSE; /* did we find an override parameter block*/
paramsValue = NULL; /* the current parameter block value */
- while (fgets(line, sizeof(line), fd) != NULL) {
- int len = PORT_Strlen(line);
+ do {
+ int len;
+
+ if (fgets(line, sizeof(line), fd) == NULL) {
+ goto endloop;
+ }
/* remove the ending newline */
+ len = PORT_Strlen(line);
if (len && line[len - 1] == '\n') {
len--;
line[len] = 0;
}
if (*line == '#') {
continue;
}
if (*line != 0) {
@@ -339,16 +344,17 @@ nssutil_ReadSecmodDB(const char *appName
}
}
continue;
}
if ((moduleString == NULL) || (*moduleString == 0)) {
continue;
}
+ endloop:
/*
* if we are here, we have found a complete stanza. Now write out
* any param section we may have found.
*/
if (paramsValue) {
/* we had an override */
if (!skipParams) {
moduleString = nssutil_DupnCat(moduleString, " parameters=", 12);
@@ -374,17 +380,17 @@ nssutil_ReadSecmodDB(const char *appName
moduleList[0] = moduleString;
} else {
moduleList[moduleCount] = moduleString;
moduleCount++;
}
moduleString = NULL;
internal = PR_FALSE;
skipParams = PR_FALSE;
- }
+ } while (!feof(fd));
if (moduleString) {
PORT_Free(moduleString);
moduleString = NULL;
}
done:
/* if we couldn't open a pkcs11 database, look for the old one */
if (fd == NULL) {