aboutsummaryrefslogtreecommitdiff
path: root/modules/pam_limits
diff options
context:
space:
mode:
authorTobias Stoeckmann <tobias@stoeckmann.org>2024-02-02 18:01:57 +0100
committerTobias Stoeckmann <tobias@stoeckmann.org>2024-02-06 18:12:26 +0100
commit9228077d762fc94ebc8d9fb4edfe9b481d96318d (patch)
tree885cbb893a6017ace51d59723e5c633da24af1a0 /modules/pam_limits
parent644dc6f0c15bccc7401e47785753e9c8d01018d3 (diff)
downloadpam-9228077d762fc94ebc8d9fb4edfe9b481d96318d.tar.gz
pam-9228077d762fc94ebc8d9fb4edfe9b481d96318d.tar.bz2
pam-9228077d762fc94ebc8d9fb4edfe9b481d96318d.zip
pam_limits: remove whitespaces around value
Trim all whitespaces before and after value. Resolves: https://github.com/linux-pam/linux-pam/pull/760 Fixes: eec4358a49dc ("pam_limits: avoid sscanf in parse_config_file") Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Diffstat (limited to 'modules/pam_limits')
-rw-r--r--modules/pam_limits/pam_limits.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/modules/pam_limits/pam_limits.c b/modules/pam_limits/pam_limits.c
index 1f420bf8..c2ca7abb 100644
--- a/modules/pam_limits/pam_limits.c
+++ b/modules/pam_limits/pam_limits.c
@@ -832,6 +832,26 @@ set_if_null(char **dest, char *def)
return 1;
}
+static char *
+trim(char *s)
+{
+ char *p;
+
+ if (s == NULL)
+ return NULL;
+
+ while (*s == ' ' || *s == '\t')
+ s++;
+
+ if (*s == '\0')
+ return NULL;
+
+ p = s + strlen(s) - 1;
+ while (p >= s && (*p == ' ' || *p == '\t'))
+ *p-- = '\0';
+ return s;
+}
+
static int
split(char *line, char **domain, char **ltype, char **item, char **value)
{
@@ -844,7 +864,7 @@ split(char *line, char **domain, char **ltype, char **item, char **value)
*domain = strtok_r(line, " \t", &saveptr);
*ltype = strtok_r(NULL, " \t", &saveptr);
*item = strtok_r(NULL, " \t", &saveptr);
- *value = strtok_r(NULL, "", &saveptr);
+ *value = trim(strtok_r(NULL, "", &saveptr));
count = 0;
count += set_if_null(domain, blank);