Ticket #722 (new defect)
Opened 14 months ago
pdl2ark network code handling needs better fix (this is in pdl2ew)
Reported by: | paulf | Owned by: | somebody |
---|---|---|---|
Priority: | major | Milestone: | |
Component: | ALL modules | Version: | |
Keywords: | Cc: |
Description
Paul H of UCSB recommended the following:
Comment about pdl2ark.c Changeset 8085 – Earthworm TRAC Very low priority... but I think the "fix" for pdl2ark.c you made 2 months ago is slightly flawed, not broken per-se but flawed... msg.pad_eventid is not an explicitly Null-terminated string (its just a field in a big space-filled "memset" buffer), so the simple sprintf with the %s makes the .ark filename "<net><eventID> (what we want) plus whatever else is in the msg buffer" up until there is a Null (which is I think always, at the moment anyway, 12 space characters). This sort-of explains the why the original code did the character by character over-write of the "_"s to build the filename (but the original author never anticipated the networks moving to 10 characters plus network code for event-ids). Its maybe a bit ugly but my solution is to replace the single sprintf (line 272) with: 272 sprintf( path, "%s/", argv[1] ); 273 for (i=0; i<sizeof(msg.pad_eventid); i++) { 274 strncat(path, msg.pad_eventid+i, (isblank(msg.pad_eventid[i])) ? 0:1); 275 } 276 strcat(path, ".ark"); This way the filename will never use more characters than there are in the 'pad_eventid' struct field, and any whitespace will be eliminated (true to the original code). I also added a bounds check for writing to the msg.pad_eventid (even though PDL should never pass a evid greater than 12 characters (2-network + 10-id (up from the old 8-id characters which is the change that broke pdl2ark in the first place)). 232 for ( j=0, off=strlen(myargs[EVENTID_ARG]); test_arg[j+off] != 0 && j < sizeof( msg.pad_eventid); j++ ) As someone else has noted in the comments there is plenty else that could be improved in the coding and structure of this contributed code but I have a version now that I think will work for the VA SHM systems (and I think my next pass I may just replace pdl2ark with a python script that can also on-the-fly do the simple filtering based just on mag and distance that I need (which is currently separately handled by an instance of eqfilter)).
Note: See
TracTickets for help on using
tickets.