[v3,2/4] eal: fix errno not set if strftime return zero

Message ID 20220617022913.47564-3-fengchengwen@huawei.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series eal: fix segment fault when exit trace |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS

Commit Message

fengchengwen June 17, 2022, 2:29 a.m. UTC
  The trace_session_name_generate() takes errno as the return value, but
the errno was not set if strftime return zero, the previously set errno
is returned in this case, this will result in inaccurate prompting.

This patch sets errno to ENOSPC if strftime return zero to fix it.

Fixes: 321dd5f8fa62 ("trace: add internal init and fini interface")
Cc: stable@dpdk.org

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
---
 lib/eal/common/eal_common_trace_utils.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
  

Comments

David Marchand June 21, 2022, 9:05 a.m. UTC | #1
On Fri, Jun 17, 2022 at 4:35 AM Chengwen Feng <fengchengwen@huawei.com> wrote:
>
> The trace_session_name_generate() takes errno as the return value, but
> the errno was not set if strftime return zero, the previously set errno
> is returned in this case, this will result in inaccurate prompting.
>
> This patch sets errno to ENOSPC if strftime return zero to fix it.
>
> Fixes: 321dd5f8fa62 ("trace: add internal init and fini interface")
> Cc: stable@dpdk.org
>
> Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>

Good catch.

With the next fix, the error condition (on trace_dir being too short
to accomodate with formatted date) cannot be reached anymore.
I squashed those two patches together.
I also updated the commitlog to give some details why we were getting
a EEXIST (or ENOENT) errno.
  

Patch

diff --git a/lib/eal/common/eal_common_trace_utils.c b/lib/eal/common/eal_common_trace_utils.c
index 64f58fb66a..09f97d3c34 100644
--- a/lib/eal/common/eal_common_trace_utils.c
+++ b/lib/eal/common/eal_common_trace_utils.c
@@ -109,8 +109,10 @@  trace_session_name_generate(char *trace_dir)
 
 	rc = strftime(trace_dir + rc, TRACE_DIR_STR_LEN - rc,
 			"%Y-%m-%d-%p-%I-%M-%S", tm_result);
-	if (rc == 0)
+	if (rc == 0) {
+		errno = ENOSPC;
 		goto fail;
+	}
 
 	return rc;
 fail: