OpenSSH 9.2 released
      Posted Feb 2, 2023 23:09 UTC (Thu)
                               by ibukanov (subscriber, #3942)
                              [Link] (8 responses)
       
     
    
      Posted Feb 3, 2023 0:27 UTC (Fri)
                               by wahern (subscriber, #37304)
                              [Link] (6 responses)
       
But if the *architecture* of OpenSSH seems messy, that's because it is messy. It's a fork of the *original* SSH implementation by Tatu Ylönen, and like any such original piece of software which coevolved with the functional concepts, the awkwardness is evident (and challenging). The codebase has seen tremendous changes, but the basic program layout and processing architecture, including the peculiar event loop, data model, etc, remain. That fundamental flavor of the codebase could never really be extirpated without effectively doing a complete rewrite. Newer components, which I think account for the majority of SLoC, still necessarily reflect the design (such as it is) of the original codebase. 
Sudo has similar problems for similar reasons--original software that created its niche--though sudo is 10-15 years older and corporate demands and funding resulted in sudo growing much more complex than was probably reasonable. That's why OpenBSD switched to doas, with the blessing and assistance of the long-time sudo maintainer. 
     
    
      Posted Feb 3, 2023 1:17 UTC (Fri)
                               by ibukanov (subscriber, #3942)
                              [Link] (5 responses)
       
Cryptic names of variables 
And the rules are violated in a single function in new code written in C in a system-critical service...  
     
    
      Posted Feb 3, 2023 17:39 UTC (Fri)
                               by mss (subscriber, #138799)
                              [Link] (4 responses)
       
     
    
      Posted Feb 3, 2023 18:11 UTC (Fri)
                               by ibukanov (subscriber, #3942)
                              [Link] (2 responses)
       
As for rarely used cleanup paths a rather effective strategy IMO is to ban use of early return in C and always use goto instead to jump to the common cleanup code shared between success and error paths. 
     
    
      Posted Feb 12, 2023 12:07 UTC (Sun)
                               by nix (subscriber, #2304)
                              [Link] (1 responses)
       
Aren't you optimizing for entirely the wrong thing here? 
     
    
      Posted Feb 16, 2023 17:18 UTC (Thu)
                               by mrugiero (guest, #153040)
                              [Link] 
       
     
      Posted Feb 7, 2023 9:58 UTC (Tue)
                               by paulj (subscriber, #341)
                              [Link] 
       
Far from perfect, the caller or other code may have stashed other pointers, but at least it ensures 'ownership' at the call site is cleanly transferred and destroyed. 
More complete solutions would involve providing functions to handle transfer of assignment, rather than using C =, and/or weak pointer/reference abstraction. Whether that's worth it depends on the complexity of the lifetime management of whatever objects you're dealing with. (And many will say "Why not Rust these days instead?"). 
     
      Posted Feb 7, 2023 13:27 UTC (Tue)
                               by smoogen (subscriber, #97)
                              [Link] 
       
Changes in coding dialect usually require an outside force to bring in the changes and show how they work.  
     
    OpenSSH 9.2 released
      
OpenSSH 9.2 released
      
OpenSSH 9.2 released
      
Unclear ownership of memory not reflected in comments.
free() and similar destructor-type functions in the middle of the function with no comments and no assignments of the pointer to NULL after that.  
Reuse of pointers to point to different memory-allocated things instead of introducing a new name for the new pointer.
Attempts to save vertical space via combing memory-allocating assignments and the if check.
OpenSSH 9.2 released
      free() and similar destructor-type functions in the middle of the function with no comments and no assignments of the pointer to NULL after that.
+1 for that, there's no reason not to set the object pointer to NULL after freeing the pointed-to object.
This turns a possible re-use into a NULL pointer dereference, which is almost always "just" a DoS risk.
For example, Glib has a nice g_clear_pointer () macro for doing exactly that, which makes it easy to audit the code that it does this clearing everywhere - just by searching for freestanding free () calls.
However, this does not replace clear object ownership rules and annotations.
For function-local objects or for holding a temporary object reference in a code block RAII-like self-freeing constructs as Glib's g_autoptr(TypeName) are very useful.
These especially make error cleanups much simpler (and these paths are often not well tested and bit-rot quickly).
AFAIK, Linux kernel would benefit from these constructs, too.
      
          OpenSSH 9.2 released
      
 
OpenSSH 9.2 released
      
OpenSSH 9.2 released
      
OpenSSH 9.2 released
      
OpenSSH 9.2 released
      
 
           