Enforce valid Rhizome 'service' and 'name' strings

This commit is contained in:
Andrew Bettison 2013-12-02 11:12:31 +10:30
parent 6bff87f7e5
commit 2bb0d2047a
3 changed files with 16 additions and 0 deletions

View File

@ -171,6 +171,19 @@ int rhizome_str_is_manifest_service(const char *text)
return *text == '\0';
}
/* A name cannot contain a LF because that is the Rhizome text manifest field terminator. For the
* time being, CR is not allowed either, because the Rhizome field terminator includes an optional
* CR. See rhizome_manifest_parse().
*
* @author Andrew Bettison <andrew@servalproject.com>
*/
int rhizome_str_is_manifest_name(const char *text)
{
while (*text && *text != '\n' && *text != '\r')
++text;
return *text == '\0';
}
int str_is_did(const char *did)
{
size_t len = 0;

View File

@ -15,6 +15,7 @@ int rhizome_str_is_bundle_crypt_key(const char *text);
int rhizome_strn_is_file_hash(const char *text);
int rhizome_str_is_file_hash(const char *text);
int rhizome_str_is_manifest_service(const char *text);
int rhizome_str_is_manifest_name(const char *text);
void write_uint64(unsigned char *o,uint64_t v);
void write_uint16(unsigned char *o,uint16_t v);

View File

@ -204,6 +204,7 @@ void _rhizome_manifest_del_bundle_key(struct __sourceloc __whence, rhizome_manif
void _rhizome_manifest_set_service(struct __sourceloc __whence, rhizome_manifest *m, const char *service)
{
if (service) {
assert(rhizome_str_is_manifest_service(service));
const char *v = rhizome_manifest_set(m, "service", service);
assert(v); // TODO: remove known manifest fields from vars[]
m->service = v;
@ -223,6 +224,7 @@ void _rhizome_manifest_del_service(struct __sourceloc __whence, rhizome_manifest
void _rhizome_manifest_set_name(struct __sourceloc __whence, rhizome_manifest *m, const char *name)
{
if (name) {
assert(rhizome_str_is_manifest_name(name));
const char *v = rhizome_manifest_set(m, "name", name);
assert(v); // TODO: remove known manifest fields from vars[]
m->name = v;