Skip to content
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

Fix obscure segfault when resizing terminal #248

Conversation

PartialVolume
Copy link
Collaborator

This was a very obscure segmentation fault I stumbled across while testing the drive selection window. I confirmed it exists in all versions at least going back prior to 0.24 and maybe a lot earlier.

It was a very tricky bug to track down as you had to do some very specific things to cause it to occur. Probably most people would not have seen it, however for those that did, this was what you needed to do to trigger it.

  1. First you had to be wiping more than one drive.

  2. Then you needed to scroll down to the bottom drive in the list.

  3. You then needed to minimise the vertical height of the terminal so you could no longer see the selected drive.

  4. Then you needed to expand the vertical height of the terminal. This last step would trigger a segmentation fault and crash nwipe.

So, the theory. nwipe uses four variables to allow you to scroll through multiple displayed drives.

These four variables are:

count = the number of enumerated drives.

slots = the number of available horizontal lines to display the drives. The number of slots varies depending upon vertical resizing of the terminal. So slots is calculated in real time.

focus = which drive the GUI '>' pointer is pointing to.

offset = A value between 0 and slots that describes what drives are displayed in the available slots.

offset is then used along with i in a for loop to index the drive contexts. This is where the segfault occurred.

The calculation failed to take correct account of a varying number of slots so in the condition described above the offset would create an index that was out of bounds.

So first I fixed the miss calculation and second I placed an if statement that acts as a bounds checker so if ever this code is changed by someone in the future and they break the calculation the bounds checker 'if' statement will log the details of the error and prevent a segfault which is far easier to debug.

This was a very obscure segmentation fault I
stumbled across while testing the drive
selection window. I confirmed it exists
in all versions at least going back prior
to 0.24 and maybe a lot earlier.

It was a very tricky bug to track down as you
had to do some very specific things to cause it to
occur. Probably most people would not have seen
it, however for those that did, this was what you
needed to do to trigger it.

1. First you had to be wiping more than one drive.

2. Then you needed to scroll down to the bottom
drive in the list.

3. You then needed to minimise the vertical height
of the terminal so you could no longer see the
selected drive.

4. Then you needed to expand the vertical height
of the terminal. This last step would trigger a
segmentation fault and crash nwipe.

So, the theory. nwipe uses four variables to
allow you to scroll through multiple displayed
drives. These four variables are:

count = the number of enumerated drives.

slots = the number of available horizontal lines
        to display the drives. The number of slots
        varies depending upon vertical resizing
        of the terminal. So slots is calculated
        in real time.

focus = which drive the GUI '>' pointer is pointing to.

offset = A value between 0 and slots that describes
         what drives are displayed in the available
         slots.

offset is then used along with i in a for loop to index
the drive contexts. This is where the segfault
occurred.

The calculation failed to take correct account of a varying
number of slots so in the condition described above the
offset would create an index that was out of bounds.

So first I fixed the miss calculation and second I placed
an if statement that acts as a bounds checker so if
ever this code is changed by someone in the future and
they break the calculation the bounds checker 'if' statement
will log the details of the error and prevent a segfault which
is far easier to debug.
@PartialVolume PartialVolume merged commit c3756e0 into martijnvanbrummelen:master Apr 1, 2020
@PartialVolume PartialVolume deleted the Fix_segfault_when_scrolling_drive_selection_window branch April 1, 2020 20:01
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.

1 participant