On 6/6/25 8:13 PM, Mike Pattrick wrote:
> On Fri, Jun 6, 2025 at 7:23 AM Ilya Maximets <i.maxim...@ovn.org> wrote:
>>
>> We'll be changing the way strings are stored, so the direct access
>> will not be safe anymore.  Change all the users to use the proper
>> API as they should have been doing anyway.
>>
>> The only code outside of json implementation for which direct access
>> is preserved is substitute_uuids() in test-ovsdb.c.  It's an unusual
>> string manipulation that is only needed for the testing, so doesn't
>> seem worthy adding a new API function.  We could introduce something
>> like json_string_replace() if this use case will appear somewhere
>> else in the future.
>>
>> Signed-off-by: Ilya Maximets <i.maxim...@ovn.org>
>> ---
>>  lib/db-ctl-base.c      |  8 +++++---
>>  lib/json.c             | 12 ++++++------
>>  lib/jsonrpc.c          |  4 ++--
>>  lib/ovsdb-cs.c         |  2 +-
>>  lib/ovsdb-data.c       |  4 ++--
>>  lib/ovsdb-idl.c        | 16 +++++++++-------
>>  lib/ovsdb-parser.c     |  2 +-
>>  lib/ovsdb-types.c      |  4 ++--
>>  ovsdb/column.c         |  2 +-
>>  ovsdb/execution.c      |  2 +-
>>  ovsdb/jsonrpc-server.c |  6 +++---
>>  ovsdb/log.c            |  2 +-
>>  ovsdb/ovsdb-client.c   |  4 ++--
>>  ovsdb/ovsdb-idlc.in    | 12 ++++++++++--
>>  ovsdb/ovsdb-tool.c     |  2 +-
>>  ovsdb/ovsdb-util.c     |  8 ++++----
>>  ovsdb/replication.c    |  2 +-
>>  python/ovs/_json.c     |  2 +-
>>  python/ovs/db/types.py |  2 +-
>>  tests/test-json.c      |  6 +++---
>>  tests/test-jsonrpc.c   |  2 +-
>>  tests/test-ovsdb.c     |  7 ++++---
>>  22 files changed, 62 insertions(+), 49 deletions(-)
>>
>> diff --git a/lib/db-ctl-base.c b/lib/db-ctl-base.c
>> index 1f157e46c..eee9646de 100644
>> --- a/lib/db-ctl-base.c
>> +++ b/lib/db-ctl-base.c
>> @@ -247,15 +247,17 @@ record_id_equals(const union ovsdb_atom *name, enum 
>> ovsdb_atomic_type type,
>>                   const char *record_id)
>>  {
>>      if (type == OVSDB_TYPE_STRING) {
>> -        if (!strcmp(name->s->string, record_id)) {
>> +        const char *name_str = json_string(name->s);
>> +
>> +        if (!strcmp(name_str, record_id)) {
>>              return true;
>>          }
>>
>>          struct uuid uuid;
>>          size_t len = strlen(record_id);
>>          if (len >= 4
>> -            && uuid_from_string(&uuid, name->s->string)
>> -            && !strncmp(name->s->string, record_id, len)) {
>> +            && uuid_from_string(&uuid, name_str)
>> +            && !strncmp(name_str, record_id, len)) {
>>              return true;
>>          }
>>
>> diff --git a/lib/json.c b/lib/json.c
>> index 2649e8e12..20626c445 100644
>> --- a/lib/json.c
>> +++ b/lib/json.c
>> @@ -493,7 +493,7 @@ json_deep_clone(const struct json *json)
>>          return json_deep_clone_array(&json->array);
>>
>>      case JSON_STRING:
>> -        return json_string_create(json->string);
>> +        return json_string_create(json_string(json));
>>
>>      case JSON_SERIALIZED_OBJECT:
>>          return json_serialized_object_create(json);
>> @@ -589,7 +589,7 @@ json_hash(const struct json *json, size_t basis)
>>
>>      case JSON_STRING:
>>      case JSON_SERIALIZED_OBJECT:
>> -        return hash_string(json->string, basis);
>> +        return hash_string(json_string(json), basis);
> 
> Hello Ilya,
> 
> I got a SIGABORT here due to json->type != JSON_STRING in json_string().

Good point.  I fixed that in the second patch by splitting the cases
and always using the pointer for serialized objects.  But I need to
move these changes to the first patch.

I'll wait a bit more for feedback before porting v2.

Best regards, Ilya Maximets.
_______________________________________________
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to