|
|
4d476f |
autofs-5.1.0 - fix buffer size checks in merge_options()
|
|
|
4d476f |
|
|
|
4d476f |
From: Ian Kent <raven@themaw.net>
|
|
|
4d476f |
|
|
|
4d476f |
Fix some buffer size overflow checks in merge_options().
|
|
|
4d476f |
---
|
|
|
4d476f |
CHANGELOG | 1 +
|
|
|
4d476f |
lib/parse_subs.c | 25 +++++++++++++++++++++----
|
|
|
4d476f |
2 files changed, 22 insertions(+), 4 deletions(-)
|
|
|
4d476f |
|
|
|
4d476f |
--- autofs-5.0.7.orig/CHANGELOG
|
|
|
4d476f |
+++ autofs-5.0.7/CHANGELOG
|
|
|
4d476f |
@@ -137,6 +137,7 @@
|
|
|
4d476f |
- fix signed comparison in inet_fill_net().
|
|
|
4d476f |
- fix buffer size checks in get_network_proximity().
|
|
|
4d476f |
- fix leak in get_network_proximity().
|
|
|
4d476f |
+- fix buffer size checks in merge_options().
|
|
|
4d476f |
|
|
|
4d476f |
25/07/2012 autofs-5.0.7
|
|
|
4d476f |
=======================
|
|
|
4d476f |
--- autofs-5.0.7.orig/lib/parse_subs.c
|
|
|
4d476f |
+++ autofs-5.0.7/lib/parse_subs.c
|
|
|
4d476f |
@@ -886,11 +886,11 @@ static char *hasopt(const char *str, con
|
|
|
4d476f |
|
|
|
4d476f |
char *merge_options(const char *opt1, const char *opt2)
|
|
|
4d476f |
{
|
|
|
4d476f |
- char str[MAX_OPTIONS_LEN];
|
|
|
4d476f |
- char result[MAX_OPTIONS_LEN];
|
|
|
4d476f |
- char neg[MAX_OPTION_LEN];
|
|
|
4d476f |
+ char str[MAX_OPTIONS_LEN + 1];
|
|
|
4d476f |
+ char result[MAX_OPTIONS_LEN + 1];
|
|
|
4d476f |
+ char neg[MAX_OPTION_LEN + 1];
|
|
|
4d476f |
char *tok, *ptr = NULL;
|
|
|
4d476f |
- size_t len;
|
|
|
4d476f |
+ size_t resultlen, len;
|
|
|
4d476f |
|
|
|
4d476f |
if ((!opt1 || !*opt1) && (!opt2 || !*opt2))
|
|
|
4d476f |
return NULL;
|
|
|
4d476f |
@@ -910,9 +910,12 @@ char *merge_options(const char *opt1, co
|
|
|
4d476f |
if (!strcmp(opt1, opt2))
|
|
|
4d476f |
return strdup(opt1);
|
|
|
4d476f |
|
|
|
4d476f |
+ if (strlen(str) > MAX_OPTIONS_LEN)
|
|
|
4d476f |
+ return NULL;
|
|
|
4d476f |
memset(result, 0, sizeof(result));
|
|
|
4d476f |
strcpy(str, opt1);
|
|
|
4d476f |
|
|
|
4d476f |
+ resultlen = 0;
|
|
|
4d476f |
tok = strtok_r(str, ",", &ptr);
|
|
|
4d476f |
while (tok) {
|
|
|
4d476f |
const char *this = (const char *) tok;
|
|
|
4d476f |
@@ -920,12 +923,15 @@ char *merge_options(const char *opt1, co
|
|
|
4d476f |
if (eq) {
|
|
|
4d476f |
*eq = '\0';
|
|
|
4d476f |
if (!hasopt(opt2, this)) {
|
|
|
4d476f |
+ if (resultlen + strlen(this) > MAX_OPTIONS_LEN)
|
|
|
4d476f |
+ return NULL;
|
|
|
4d476f |
*eq = '=';
|
|
|
4d476f |
if (!*result)
|
|
|
4d476f |
strcpy(result, this);
|
|
|
4d476f |
else
|
|
|
4d476f |
strcat(result, this);
|
|
|
4d476f |
strcat(result, ",");
|
|
|
4d476f |
+ resultlen += strlen(this) + 1;
|
|
|
4d476f |
goto next;
|
|
|
4d476f |
}
|
|
|
4d476f |
}
|
|
|
4d476f |
@@ -946,10 +952,14 @@ char *merge_options(const char *opt1, co
|
|
|
4d476f |
goto next;
|
|
|
4d476f |
|
|
|
4d476f |
if (!strncmp(this, "no", 2)) {
|
|
|
4d476f |
+ if (strlen(this + 2) > MAX_OPTION_LEN)
|
|
|
4d476f |
+ return NULL;
|
|
|
4d476f |
strcpy(neg, this + 2);
|
|
|
4d476f |
if (hasopt(opt2, neg))
|
|
|
4d476f |
goto next;
|
|
|
4d476f |
} else {
|
|
|
4d476f |
+ if ((strlen(this) + 2) > MAX_OPTION_LEN)
|
|
|
4d476f |
+ return NULL;
|
|
|
4d476f |
strcpy(neg, "no");
|
|
|
4d476f |
strcat(neg, this);
|
|
|
4d476f |
if (hasopt(opt2, neg))
|
|
|
4d476f |
@@ -959,15 +969,22 @@ char *merge_options(const char *opt1, co
|
|
|
4d476f |
if (hasopt(opt2, tok))
|
|
|
4d476f |
goto next;
|
|
|
4d476f |
|
|
|
4d476f |
+ if (resultlen + strlen(this) + 1 > MAX_OPTIONS_LEN)
|
|
|
4d476f |
+ return NULL;
|
|
|
4d476f |
+
|
|
|
4d476f |
if (!*result)
|
|
|
4d476f |
strcpy(result, this);
|
|
|
4d476f |
else
|
|
|
4d476f |
strcat(result, this);
|
|
|
4d476f |
strcat(result, ",");
|
|
|
4d476f |
+ resultlen =+ strlen(this) + 1;
|
|
|
4d476f |
next:
|
|
|
4d476f |
tok = strtok_r(NULL, ",", &ptr);
|
|
|
4d476f |
}
|
|
|
4d476f |
|
|
|
4d476f |
+ if (resultlen + strlen(opt2) > MAX_OPTIONS_LEN)
|
|
|
4d476f |
+ return NULL;
|
|
|
4d476f |
+
|
|
|
4d476f |
if (!*result)
|
|
|
4d476f |
strcpy(result, opt2);
|
|
|
4d476f |
else
|