astfd.c: Avoid calling fclose with NULL argument.#901
Conversation
|
cherry-pick-to: 18 |
|
@InterLinked1 I was trying to determine if we should apply this patch to the certified branches but I can't seem to reproduce the issue. I'm using Ubuntu22 with gcc 13.2.0 and have tried with and without devmode and with and without COMPILE_DOUBLE. Can you reproduce the issue with a |
seanbright
left a comment
There was a problem hiding this comment.
Now that I look at both the POSIX docs and fclose(3) on Linux ("The behaviour of fclose() is undefined if the stream parameter is an illegal pointer"), setting errno here is probably not technically correct. I think returning -1 is fine though.
I believe I noticed this on an Ubuntu 24.04 build with gcc 13.2.0, but not Ubuntu 22.04 or any other distro. Builds were in devmode with DONT_OPTIMIZE as well (oh, and DEBUG_FD_LEAKS too, obviously). I think this might have happened only in a GitHub runner and not other Ubuntu images but I don't remember for sure now. |
Yeah, it's undefined behavior, but is there a reason it's better not to set errno here anyways? I was thinking there should be some way to indicate what the issue is, but both an assertion and even a log message seemed too harsh. It's only if we compile with |
Sorry, I could have been more clear before. I don't necessarily object to
I don't feel strongly either way, so if you'd prefer to keep it as-is that's fine. |
Actually, after thinking about this, I don't think the version of gcc matters. It has to do with when the nonnull attribute would've been added, which looks like glibc 2.38: bminor/glibc@71d9e0f I'm guessing your Ubuntu system has something older, even 24.04 seems to come with 2.36 by default. My guess is glibc got upgraded on that system and the newer header file then triggered the build failure. |
Okay, thanks for clarifying... I guess "file descriptor underlying stream is not valid" is different from "stream itself is not valid". I'll see if there's a more appropriate value to use or remove it otherwise. |
ff9ea99 to
390a4cf
Compare
| #undef fclose | ||
| int __ast_fdleak_fclose(FILE *ptr) | ||
| { | ||
| int __ast_fdleak_fclose(FILE *ptr) { |
There was a problem hiding this comment.
Not sure why this happened, but I'm working on it
Ah, that's what I was missing. Since it only happens with that flag we'll skip the certified branches. |
Don't pass through a NULL argument to fclose, which is undefined behavior, and instead return -1 and set errno appropriately. This also avoids a compiler warning with glibc 2.38 and newer, as glibc commit 71d9e0fe766a3c22a730995b9d024960970670af added the nonnull attribute to this argument. Resolves: asterisk#900
390a4cf to
beb456c
Compare
|
Successfully merged to branch master and cherry-picked to ["18","20","21","22"] |
Don't pass through a NULL argument to fclose, which is undefined behavior, and instead return -1 and set errno appropriately. This avoids a compiler warning with gcc 13.2.0.
Resolves: #900