Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abnormal Segment Error Problem in version 1.2.18 #267

Closed
breadmechanic opened this issue Aug 22, 2024 · 3 comments
Closed

Abnormal Segment Error Problem in version 1.2.18 #267

breadmechanic opened this issue Aug 22, 2024 · 3 comments

Comments

@breadmechanic
Copy link
Contributor

I found a problem in zlog 1.2.18. When the vzlog interface is used to print logs, the Signal 11 exception occurs. As a result, the process exits.
Parse the library file and find that the following code is incorrect. The code is in the zlog.c file.

void vzlog(...)
{
	if (zlog_category_needless_level(category, level)) return;
...
}

The contents of the expanded macro definition are as follows:

#define zlog_category_needless_level(a_category, lv) \
        a_category && (zlog_env_conf->level > lv || !((a_category->level_bitmap[lv/8] >> (7 - lv % 8)) & 0x01))

By checking the assembly code, we find that the Linux is accessing zlog_env_conf->level when the problem occurs. The null pointer may occur when the parameter is accessed.

I hope you can help analyze the possible causes and assist in fixing the problem.

@breadmechanic
Copy link
Contributor Author

Some additional information:

I was using zlog version 1.2.16 and recently switched to 1.2.18.

The preceding code snippets are modified in version 1.2.17. The Pull Request is #159

The only change is that the determination of zlog_env_conf->level > lv is added.

1.2.16 version of the code is as follows:

#define zlog_category_needless_level(a_category, lv) \
    (a_category && !((a_category->level_bitmap[lv/8] >> (7 - lv % 8)) & 0x01))

1.2.17 version of the code is as follows:

#define zlog_category_needless_level(a_category, lv) \
        a_category && (zlog_env_conf->level > lv || !((a_category->level_bitmap[lv/8] >> (7 - lv % 8)) & 0x01))

@findix
Copy link
Contributor

findix commented Aug 27, 2024

#159 also make a ERROR (1891873:level_list.c:141) str is [], can't find level error if don't set log level in the config file.

@breadmechanic
Copy link
Contributor Author

When the following two processes are triggered at the same time, a serious concurrency problem occurs. As a result, a null pointer occurs when the variable zlog_env_conf is accessed.

Process 1:

void vzlog(...)
{
    if (zlog_category_needless_level(category, level)) return;
    ...
}

Process 2:

int zlog_reload(...)
{
    rc = pthread_rwlock_wrlock(&zlog_env_lock);
    ...
    zlog_conf_del(zlog_env_conf);
    zlog_env_conf = new_conf;
    ...
    rc = pthread_rwlock_unlock(&zlog_env_lock);
}

If we have two threads in a single process and call these two functions at the same point in time, there is a serious concurrency problem.

The problem is caused by the code #159 modified in zlog 1.2.17.

The access to zlog_env_conf is added to the macro definition zlog_category_needless_level, but pthread_rwlock_wrlock is not invoked to lock. As a result, zlog_conf_del is invoked in zlog_reload. There is a low probability that the zlog_env_conf accessed by other threads is a null pointer.

This is a serious abnormal segment error problem. We hope that the problem can be solved as soon as possible and a patch or a new version can be provided.

@deemar deemar closed this as completed Sep 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants