summaryrefslogtreecommitdiffabout
path: root/lib/env.c
Side-by-side diff
Diffstat (limited to 'lib/env.c') (more/less context) (ignore whitespace changes)
-rw-r--r--lib/env.c66
1 files changed, 49 insertions, 17 deletions
diff --git a/lib/env.c b/lib/env.c
index 83152e4..b1da177 100644
--- a/lib/env.c
+++ b/lib/env.c
@@ -94,7 +94,7 @@ gray_env_read_tr(const char *file_name, struct gray_env **penv, char **trmap)
return 1;
}
- while (p = fgets(buf, sizeof buf, fp)) {
+ while ((p = fgets(buf, sizeof buf, fp))) {
int len;
struct gray_env *env;
@@ -105,17 +105,28 @@ gray_env_read_tr(const char *file_name, struct gray_env **penv, char **trmap)
if (len == 0)
continue;
if (p[len-1] != '\n') {
- if (!slist)
+ if (!slist) {
slist = gray_slist_create();
- gray_slist_append(slist, p, len);
- while (p = fgets(buf, sizeof buf, fp)) {
+ if (!slist) {
+ rc = errno;
+ break;
+ }
+ }
+ if (gray_slist_append(slist, p, len) != len) {
+ rc = errno;
+ break;
+ }
+ while ((p = fgets(buf, sizeof buf, fp))) {
len = strlen(p);
gray_slist_append(slist, p, len);
if (p[len - 1] == '\n')
break;
}
- gray_slist_append_char(slist, 0);
- p = gray_slist_finish(slist);
+ if (gray_slist_append_char(slist, 0) != 1
+ || (p = gray_slist_finish(slist)) == NULL) {
+ rc = errno;
+ break;
+ }
len = strlen(p);
}
@@ -129,10 +140,19 @@ gray_env_read_tr(const char *file_name, struct gray_env **penv, char **trmap)
int err = 0;
/* Collect continuation lines */
- if (!slist)
+ if (!slist) {
slist = gray_slist_create();
+ if (!slist) {
+ rc = errno;
+ break;
+ }
+ }
do {
- gray_slist_append(slist, p, len - 1);
+ if (gray_slist_append(slist, p, len - 1)
+ != len - 1) {
+ rc = errno;
+ break;
+ }
p = fgets (buf, sizeof buf, fp);
if (!p)
break;
@@ -150,26 +170,33 @@ gray_env_read_tr(const char *file_name, struct gray_env **penv, char **trmap)
p[len-1] = 0;
len = gray_trim_ws(p);
} while (p[len-1] == '\\');
- if (len)
- gray_slist_append(slist, p, len);
- gray_slist_append_char(slist, 0);
- p = gray_slist_finish(slist);
+ if (rc)
+ break;
+ if (len) {
+ if (gray_slist_append(slist, p, len) != len) {
+ rc = errno;
+ break;
+ }
+ }
+ if (gray_slist_append_char(slist, 0) != 1
+ || (p = gray_slist_finish(slist)) == NULL) {
+ rc = errno;
+ break;
+ }
if (err)
continue;
}
env = malloc(sizeof *env);
if (!env) {
- _pam_log(LOG_EMERG, "not enough memory");
- rc = 1;
+ rc = errno;
break;
}
env->name = strdup(p);
if (!env->name) {
- _pam_log(LOG_EMERG, "not enough memory");
+ rc = errno;
free(env);
- rc = 1;
break;
}
@@ -195,7 +222,12 @@ gray_env_read_tr(const char *file_name, struct gray_env **penv, char **trmap)
gray_slist_free(&slist);
fclose(fp);
- *penv = config_env;
+ if (rc) {
+ _pam_log(LOG_EMERG, "%s", strerror(rc));
+ gray_env_free(config_env);
+ } else {
+ *penv = config_env;
+ }
return rc;
}

Return to:

Send suggestions and report system problems to the System administrator.