Skip to content

Commit b1765c9

Browse files
InterLinked1kharwell
authored andcommitted
func_db: Add validity check for key names when writing.
Adds a simple sanity check for key names when users are writing data to AstDB. This captures four cases indicating malformed keynames that generally result in bad data going into the DB that the user didn't intend: an empty key name, a key name beginning or ending with a slash, and a key name containing two slashes in a row. Generally, this is the result of a variable being used in the key name being empty. If a malformed key name is detected, a warning is emitted to indicate the bug in the dialplan. ASTERISK-29925 #close Change-Id: Ifc08a9fe532a519b1b80caca1aafed7611d573bf
1 parent 4722c8b commit b1765c9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

funcs/func_db.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,13 @@ static int function_db_write(struct ast_channel *chan, const char *cmd, char *pa
173173
ast_log(LOG_WARNING, "DB requires an argument, DB(<family>/<key>)=value\n");
174174
return -1;
175175
}
176-
176+
/*
177+
* When keynames are dynamically created using variables, if the variable is empty, this put bad data into the DB.
178+
* In particular, a few cases: an empty key name, a key starting or ending with a /, and a key containing // two slashes.
179+
* If this happens, allow it to go in, but warn the user of the issue and possible data corruption. */
180+
if (ast_strlen_zero(args.key) || args.key[0] == '/' || args.key[strlen(args.key) - 1] == '/' || strstr(args.key, "//")) {
181+
ast_log(LOG_WARNING, "DB: key '%s' seems malformed\n", args.key);
182+
}
177183
if (ast_db_put(args.family, args.key, value)) {
178184
ast_log(LOG_WARNING, "DB: Error writing value to database.\n");
179185
}

0 commit comments

Comments
 (0)