Menu

#7 load_map: missing check on fgets calls

1.0
closed
nobody
None
2015-06-01
2015-05-31
No

load_map in main.c doesn't check the result of fgets calls which might fail when reading an empty line at EOF. This leads to duplicate configuration pairs whenever there's a non-empty configuration line with a trailing newline immediately before EOF.

Witness test.omm is attached (it's the same example as in my previous ticket):

/1/fader1 f, val : controlchange( 0, 1, 127*val );

This yields:

$ osc2midi -v -m test.omm 
Using map file test.omm
pair created: /1/fader1 f, a : controlchange( 0, 1, 127.00*a )
pair created: /1/fader1 f, a : controlchange( 0, 1, 127.00*a )
2 pairs created.

Note the duplication of the last line. This only happens if the last line of the file is nonempty and has a trailing newline, as in the provided example. The call to fgets then fails, and since the result is not checked, the same line (which is still stored in the line variable) is parsed once again. The EOF condition is then detected by the while loop (call to feof(map)) but it's already too late (note that feof() won't become true until fgets() actually hits EOF while reading).

The solution is to check the result of fgets() and bail out of the while loop if it is NULL. Suggested patch is attached (load_map-fgets.diff).

1 Attachments

Discussion

  • Albert Graef

    Albert Graef - 2015-05-31

    Witness test.omm.

     
  • ssj71

    ssj71 - 2015-06-01

    patch applied. thanks.

     
  • ssj71

    ssj71 - 2015-06-01
    • status: open --> closed
     

Log in to post a comment.