Bug 39549 - add public API to validate various fixed-syntax strings
Summary: add public API to validate various fixed-syntax strings
Status: RESOLVED FIXED
Alias: None
Product: dbus
Classification: Unclassified
Component: core (show other bugs)
Version: 1.5
Hardware: Other All
: medium enhancement
Assignee: Simon McVittie
QA Contact: John (J5) Palmieri
URL: http://cgit.freedesktop.org/~smcv/dbu...
Whiteboard:
Keywords: patch
Depends on:
Blocks: dbus-1.5 40817
  Show dependency treegraph
 
Reported: 2011-07-26 04:20 UTC by Simon McVittie
Modified: 2012-02-24 04:47 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments
[PATCH 1/3] Remove declaration of _dbus_type_is_fixed, no longer exists (1.04 KB, patch)
2011-07-26 04:21 UTC, Simon McVittie
Details | Splinter Review
[PATCH 2/3] Add dbus-syntax.[ch] (14.91 KB, patch)
2011-07-26 04:21 UTC, Simon McVittie
Details | Splinter Review
[PATCH 3/3] Add a regression test for validating various string types with the public API (8.13 KB, patch)
2011-07-26 04:21 UTC, Simon McVittie
Details | Splinter Review

Description Simon McVittie 2011-07-26 04:20:44 UTC
It'd be good to have public versions of _dbus_check_is_valid_bus_name() etc., as part of the general principle of "if a function has preconditions, then language bindings should find it easy to check those preconditions themselves".

The API I propose matches the current dbus_signature_validate and dbus_signature_validate_single functions:

/*
 * Assumes that the string is '\0'-terminated, so you must check lengths
 * separately if dealing with untrusted data from the network.
 *
 * Passing a NULL string is considered to be a programming error; callers
 * are expected to check for NULL themselves.
 *
 * If valid (which is flagged as _DBUS_LIKELY), returns TRUE.
 *
 * If invalid, raises an error (currently DBUS_ERROR_INVALID_ARGS) and
 * returns FALSE. The error message is currently generic; as a future
 * refinement, we could include a hint appropriate to the validity
 * failure in the error message, e.g.
 * "com.example.a&b" -> "name components may only contain [A-Za-z0-9_]".
 */
dbus_bool_t dbus_validate_THING (const char *, DBusError *);

with the following validators available:

* dbus_validate_path
* dbus_validate_interface
* dbus_validate_member
* dbus_validate_error_name
* dbus_validate_bus_name (accepts both unique and well-known names)
* dbus_validate_utf8

Thread: http://lists.freedesktop.org/archives/dbus/2011-July/014528.html
Comment 1 Simon McVittie 2011-07-26 04:21:13 UTC
Created attachment 49562 [details] [review]
[PATCH 1/3] Remove declaration of _dbus_type_is_fixed, no longer  exists
Comment 2 Simon McVittie 2011-07-26 04:21:28 UTC
Created attachment 49563 [details] [review]
[PATCH 2/3] Add dbus-syntax.[ch]
Comment 3 Simon McVittie 2011-07-26 04:21:43 UTC
Created attachment 49564 [details] [review]
[PATCH 3/3] Add a regression test for validating various string  types with the public API
Comment 4 Simon McVittie 2012-02-08 11:24:17 UTC
Branch updated for current master (just patches 2 and 3, I've moved the first one to a trivia branch):

ssh://people.freedesktop.org/~smcv/dbus.git validation-39549
Comment 5 Will Thompson 2012-02-23 07:48:27 UTC
Comment on attachment 49562 [details] [review]
[PATCH 1/3] Remove declaration of _dbus_type_is_fixed, no longer  exists

Review of attachment 49562 [details] [review]:
-----------------------------------------------------------------

Looks fine.
Comment 6 Will Thompson 2012-02-23 08:01:41 UTC
Comment on attachment 49563 [details] [review]
[PATCH 2/3] Add dbus-syntax.[ch]

Review of attachment 49563 [details] [review]:
-----------------------------------------------------------------

This look reasonable too.
Comment 7 Will Thompson 2012-02-23 08:17:45 UTC
Comment on attachment 49564 [details] [review]
[PATCH 3/3] Add a regression test for validating various string  types with the public API

Review of attachment 49564 [details] [review]:
-----------------------------------------------------------------

Looks fine.
Comment 8 Simon McVittie 2012-02-24 04:47:41 UTC
Thanks, fixed in git for 1.5.12


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.