I'm trying to decide whether you should write len instead of sizeof(errstr) here (and in the other lines of your patch).  len is assigned to sizeof(errstr) and in fact it's used in a bunch of places earlier in the function.  On one hand switching to use len would be more consistent, but on the other hand the way you wrote the code makes it obvious exactly what it's supposed to be doing.  Clearly either way is better than how the code stands now.