From cae498aaef0e4d632371e19043c5c59a605651b5 Mon Sep 17 00:00:00 2001 From: Ant Sibthorpe Date: Tue, 4 Aug 2026 14:29:55 +1200 Subject: [PATCH] fix: stop recode file crashing with a NULL codefrom "recode file " fully delegates to read_station_recode_file, which already applies every recode from the file itself. The function never returned afterward though, so execution fell through into logic meant only for the other two recode grammars (inline "recode X to Y" and "recode suffix ..."), which share optional uncertainty/date-range parsing this form has no equivalent of. That logic ends with a call to add_stn_recode_to_map_err using codefrom/codeto, which are never set on the file branch - codefrom stays NULL, and _stricmp(codefrom, ...) segfaults immediately. This meant every use of "recode file X" crashed unconditionally, with an empty .err file since the crash happens before close_output_files() can run - not a fault in the recode file's own content. Reproduced and confirmed fixed with AddressSanitizer, pointing directly at the NULL dereference. Full regression suite (testall.pl -r) passes unchanged. Co-Authored-By: Claude Sonnet 5 --- src/snaplib/snapdata/stnrecode.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/snaplib/snapdata/stnrecode.cpp b/src/snaplib/snapdata/stnrecode.cpp index 5dbbb8f5..d404d472 100644 --- a/src/snaplib/snapdata/stnrecode.cpp +++ b/src/snaplib/snapdata/stnrecode.cpp @@ -443,6 +443,13 @@ int read_station_recode_definition( stn_recode_map *stt, char *def, char *basefi } else if ( _stricmp(field,"file") == 0 ) { + // "recode file " is a distinct grammar from the other + // two forms below, and shares none of their optional uncertainty or + // date-range clauses etc. - the recode file's own columns are all it + // supports. read_station_recode_file has already applied every + // recode from the file by the time it returns, so this branch returns + // immediately rather than falling into logic that assumes codefrom + // and codeto are set. char *filename=next_field(&def); int sts; if( ! filename ) @@ -459,6 +466,11 @@ int read_station_recode_definition( stn_recode_map *stt, char *def, char *basefi ok=0; } } + if( ! ok ) + { + handle_error(INVALID_DATA,"Error reading station recoding",msg); + } + return ok ? OK : INVALID_DATA; } else if ( _stricmp(field,"suffix") == 0 ) {