* Perform very rudimentary validation of a proposed script. It would be * easy to imagine something more comprehensive. The script string is * validated in a static buffer. */
| 161 | * validated in a static buffer. |
| 162 | */ |
| 163 | static int |
| 164 | db_script_valid(const char *scriptname, const char *script) |
| 165 | { |
| 166 | char *buffer, *command; |
| 167 | |
| 168 | if (strlen(scriptname) == 0) |
| 169 | return (EINVAL); |
| 170 | if (strlen(scriptname) >= DB_MAXSCRIPTNAME) |
| 171 | return (EINVAL); |
| 172 | if (strlen(script) >= DB_MAXSCRIPTLEN) |
| 173 | return (EINVAL); |
| 174 | buffer = db_static_buffer; |
| 175 | strcpy(buffer, script); |
| 176 | while ((command = strsep(&buffer, ";")) != NULL) { |
| 177 | if (strlen(command) >= DB_MAXLINE) |
| 178 | return (EINVAL); |
| 179 | } |
| 180 | return (0); |
| 181 | } |
| 182 | |
| 183 | /* |
| 184 | * Modify an existing script or add a new script with the specified script |
no test coverage detected