Skip to content

Fix segmentation fault when trying to save invalid long strings #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 21, 2025

Conversation

simon-ess
Copy link
Contributor

@simon-ess simon-ess commented Feb 23, 2024

This can occur if you have something like the following:

record(waveform, "foo") {
  field(FTVL, "CHAR")
  field(NELM, "10")
  info(autosaveFields, "VAL VAL$")
}

The VAL$ field will cause a segmentation fault when it tries to save it to disk. The reason this seems to happen is that on one hand, VAL$ is regarded by autosave as a valid field (it is a field, but with a $ at the end). On the other hand, when connecting a monitor, the connection fails as the VAL field is not of the correcct type as defined in dbChannelCreate from EPICS base.

This means that autosave will try to save the date from an unconnected array, with uninitialised pArray, causing a segmentation fault.

Fixes #59

@anjohnson
Copy link
Member

I'd recommend testing this change against the lsi & lso (long string in/out) record types too, they provide access to the VAL field slightly differently than a waveform record although I doubt the code would need to be any different for them. Using these types instead of a CHAR waveform makes the database designer's intention clearer when they're available (since Base 3.15).

@simon-ess
Copy link
Contributor Author

@anjohnson - Having just picked up this ball that I dropped quite a while ago, I can report the following:

  • lsi records save in "the same way" as before with this change, in the sense that the exact same data is saved; however in neither case is the long string actually saved. That is, if you have
record(lsi, "lsi") {
    field(SIZV, "70")
    field(INP,  {"const": "0xxxxxxxx1xxxxxxxx2xxxxxxxx3xxxxxxxx4xxxxxxxx5xxxxxxx"})
    info(autosaveFields, "VAL VAL$")
}

then both before and after this change the saved value is identical: that is, it is a truncated version of the above string, truncated at 39 characters. The only difference is that before this change we save both lsi.VAL and lsi.VAL$ (with the exact same value), whereas after we only save lsi.VAL (with of course the same value).

So this change:

  • slightly modifies autosave for lsi records, but not in a way that affects behaviour
  • fixes a segfault for waveform records

@anjohnson
Copy link
Member

Is there any connection between this and the new PR #73 from SLAC? The subject matter feels similar, but the change is in a different area of the code. There are now conflicts in this branch, so while looking at them could you also take a look at that PR too?

simon-ess added 2 commits May 7, 2025 15:16
This can occur if you have something like the following:
```
record(waveform, "foo") {
  field(FTVL, "CHAR")
  field(NELM, "10")
  info(autosaveFields, "VAL VAL$")
}
```
The `VAL$` field will cause a segmentation fault when it tries to
save it to disk. The reason this seems to happen is that on one hand,
`VAL$` is regarded by autosave as a valid field (it is a field, but
with a `$` at the end). On the other hand, when connecting a monitor,
the connection fails as the `VAL` field is not of the correcct type
as defined in `dbChannelCreate` from EPICS base.

This means that autosave will try to save the date from an unconnected
array, with uninitialised pArray, causing a segmentation fault.
@simon-ess
Copy link
Contributor Author

I have pushed to fix the conflicts, which were formatting ones from #66. However, I should note that the segfault was actually fixed by #67.

The MR #73 does not actually address the issue at hand, either before or after #67. These are independent of each other.

@keenanlang keenanlang merged commit 29ee197 into epics-modules:master May 21, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Segmentation fault when autosaving long string-type fields
3 participants