]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - lib/env.c
Merge branch 'pager/less-quirk' of https://github.com/t-8ch/util-linux
[thirdparty/util-linux.git] / lib / env.c
index 5c385f934b91f1272472e2f24189adf269761558..2bdfe5697e900fdf0273ee83125ff60e2cb39918 100644 (file)
--- a/lib/env.c
+++ b/lib/env.c
@@ -89,19 +89,22 @@ static struct ul_env_list *env_list_add(struct ul_env_list *ls0, const char *str
 */
 struct ul_env_list *env_from_fd(int fd)
 {
-       char *buf = NULL;
-       size_t rc = 0;
+       char *buf = NULL, *p;
+       ssize_t rc = 0;
        struct ul_env_list *ls = NULL;
 
        if ((rc = read_all_alloc(fd, &buf)) < 1)
                return NULL;
        buf[rc] = '\0';
+       p = buf;
 
        while (rc > 0) {
-               ls = env_list_add(ls, buf);
-               buf += strlen(buf) + 1;
-               rc -= strlen(buf) + 1;
+               ls = env_list_add(ls, p);
+               p += strlen(p) + 1;
+               rc -= strlen(p) + 1;
        }
+
+       free(buf);
        return ls;
 }
 
@@ -156,7 +159,7 @@ void __sanitize_env(struct ul_env_list **org)
                         if (strncmp(*cur, *bad, strlen(*bad)) == 0) {
                                if (org)
                                        *org = env_list_add(*org, *cur);
-                                last = remote_entry(envp, cur - envp, last);
+                                last = remove_entry(envp, cur - envp, last);
                                 cur--;
                                 break;
                         }
@@ -171,7 +174,7 @@ void __sanitize_env(struct ul_env_list **org)
                                 continue;  /* OK */
                        if (org)
                                *org = env_list_add(*org, *cur);
-                        last = remote_entry(envp, cur - envp, last);
+                        last = remove_entry(envp, cur - envp, last);
                         cur--;
                         break;
                 }