CVS commit: src/bin/sh
"Robert Elz" <[email protected]>
| Newsgroups | gmane.os.netbsd.devel.cvs |
|---|---|
| Message-ID | <[email protected]> |
Module Name: src Committed By: kre Date: Sat Apr 18 14:35:52 UTC 2026 Modified Files: src/bin/sh: var.c Log Message: Fix an unlikely possible var sorting problem Now that CHECKSTRSPACE() is usable, use it when sorting var names (for "set" (no args or options) and similar uses (export -p etc)) which sort the vars. The previous use of STPUTC() was unsafe, as the buffer the name was being moved into could move that way, but nothing was allowing for that, possibly instead using the (only part completed and unterminated) old pre-move version of the name for use when comparing. The only likely effect would be incorrectly sorted vars in the output, and that would have been quite rare (and probably never happened), but now we can safely use CHECKSTRSPACE() for an arbitrary size, use that to ensure that the entire var name will fit without moving the string (and use USTPUTC() to guarantee that doesn't happen - and it is faster). While here, add lots of comments to explain what is going on, and why, in the var name comparison function (sort_var()), as at first glance, what it is doing looks absurd ... it just isn't. While here, avoid doing strchr() [sic] to discover the lengths of the var names, as the var struct contains that info already (that change could have been made any time.) To generate a diff of this commit: cvs rdiff -u -r1.89 -r1.90 src/bin/sh/var.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.