[PATCH] Strip quotes and newline, take two.

Christopher Brannon cmbrannon at cox.net
Thu May 28 11:50:37 EDT 2009


When the user reads the contents of a STRING parameter via sysfs, Speakup
surrounds the data with a balanced pair of quotes.  Example:
"\x01+3p"
The kernel appends a newline.
When the user tries to set a parameter via sysfs, Speakup should strip
away the newline and balanced quotes.  Thus, reads and writes of files
under /sys/modules/speakup/parameters should be inverses of one another.
This patch guarantees such behavior.
---
 src/paramhelpers.c |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/src/paramhelpers.c b/src/paramhelpers.c
index 7dbd060..55e05e8 100644
--- a/src/paramhelpers.c
+++ b/src/paramhelpers.c
@@ -755,8 +755,9 @@ static int set_vars(const char *val, struct kernel_param *kp)
 		return 0;
 
 	ret = 0;
-	len = strlen(val);
 	cp = xlate((char *) val);
+	len = strlen(val); /* xlate may have changed the length of the string */
+
 	switch (param->var_type) {
 	case VAR_NUM:
 	case VAR_TIME:
@@ -776,6 +777,16 @@ static int set_vars(const char *val, struct kernel_param *kp)
 		}
 		break;
 	case VAR_STRING:
+		/*
+		 * Strip balanced quote and newline character, if present.
+		*/
+		if((len >= 1) && (val[len - 1] == '\n'))
+			--len;
+		if((len >= 2) && (val[0] == '"') && (val[len - 1] == '"')) {
+			++val;
+			len -= 2;
+		}
+		cp[len] = '\0'; /* Ensure NUL-termination. */
 		ret = set_string_var(val, param, len);
 		if (ret == E_TOOLONG)
 			pr_warn("value too long for %s\n",
-- 
1.6.3.1




More information about the Speakup mailing list