This is an archive of the discontinued Mercurial Phabricator instance.

fsmonitor: handle unicode keys in tuples
ClosedPublic

Authored by indygreg on Nov 2 2019, 6:03 PM.

Details

Summary

In Python 3, keys in the bset tuple are typically str, not
bytes. PyBytes_AsString() would return NULL. But we weren't
checking the return value and this would lead to a segfault.

This commit makes the code type and Python version aware. The
Python version specific code is to allow us to utilize a
modern API for converting str -> char* without having to
allocate an extra PyObject.

FWIW I wanted to assume that keys were always str. However,
there appear to be some bytes keys in some cases. I haven't
debugged this further.

Diff Detail

Repository
rHG Mercurial
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

indygreg created this revision.Nov 2 2019, 6:03 PM
indygreg edited the summary of this revision. (Show Details)Nov 2 2019, 6:15 PM
indygreg updated this revision to Diff 17513.
durin42 added inline comments.
hgext/fsmonitor/pywatchman/bser.c
182

By reading this code, I believe sval should have been key, so I've fixed that in flight.

This revision was not accepted when it landed; it landed in state Needs Review.
This revision was automatically updated to reflect the committed changes.