Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maximum supported line length is BUFSIZ (8192) #192

Closed
stoeckmann opened this issue Jan 20, 2024 · 2 comments
Closed

Maximum supported line length is BUFSIZ (8192) #192

stoeckmann opened this issue Jan 20, 2024 · 2 comments

Comments

@stoeckmann
Copy link
Contributor

This is a follow-up of a discussion at Linux-PAM about differences in line parsers. Linux-PAM supports arbitrary line lengths now.

According to @thkukuk in comment linux-pam/linux-pam#741 (comment) this should be true for libeconf, too.

See this proof of concept that BUFSIZ has consequences on line parser:

  1. Create a file with a line longer than BUFSIZ (8192)
    python -c 'print(8200*"a" + "=b")' > test.txt
  2. Run following example program (shorter version of what pam_env.so does)
#include <libeconf.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
        econf_file *key_file = NULL;
        econf_err error;
        char **keys = NULL;
        size_t key_number = 0;

        if (argc != 2) {
                fprintf(stderr, "supply file name to parse\n");
                return 1;
        }

        error = econf_readFile(&key_file, argv[1], "=", "#");
        if (error != ECONF_SUCCESS) {
                fprintf(stderr, "Unable to open file: %s: %s", argv[1],
                    econf_errString(error));
                return 2;
        }

        error = econf_getKeys(key_file, NULL, &key_number, &keys);
        if (error != ECONF_SUCCESS) {
                fprintf(stderr, "Unable to read keys: %s",
                    econf_errString(error));
                return 3;
        }

        for (size_t i = 0; i < key_number; i++) {
                char *val;

                error = econf_getStringValue(key_file, NULL, keys[i], &val);
                if (error != ECONF_SUCCESS) {
                        fprintf(stderr, "Unable tto get string from key %s: %s",
                            keys[i], econf_errString(error));
                        return 4;
                }
                printf("key: '%s', value: '%s'\n", keys[i], val);
        }

        return 0;
}

The output will be:

key: 'a....a', value: '(null)'
key: 'aaaaaaaaaa', value: 'b'

It shows that this one line is split into two. See https://github.com/openSUSE/libeconf/blob/master/lib/getfilecontents.c#L268 for relevant fgets usage.

I've seen this code part in the past, so I was fairly sure that this limitation still exists. And I think it should not be just replaced with getline without thinking about possible consequences of programs which use libeconf. Linux-PAM for example trusted in some parts of the code that parsed lines wouldn't be longer (imagine strcpy usages, for an over-simplified example).

@schubi2
Copy link
Collaborator

schubi2 commented Jan 22, 2024

Fixed with #195 and version 0.6.1.
Thank you !

@schubi2
Copy link
Collaborator

schubi2 commented Jan 22, 2024

closing....

@schubi2 schubi2 closed this as completed Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants