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

top on Fedora error #1567

Closed
iapaddler opened this issue Jun 28, 2023 · 1 comment · Fixed by #1572
Closed

top on Fedora error #1567

iapaddler opened this issue Jun 28, 2023 · 1 comment · Fixed by #1572
Labels
bug Something isn't working libscope

Comments

@iapaddler
Copy link
Contributor

On Fedora desktop
LD_PRELOAD=/usr/lib/appscope/libscope.so top
results in:
unknown terminal type
top does not start

@iapaddler iapaddler added bug Something isn't working libscope labels Jun 28, 2023
michalbiesek added a commit to michalbiesek/appscope that referenced this issue Jul 3, 2023
Here is the implementation called on Fedora:

23│ int
24│ ___sprintf_chk (char *s, int flag, size_t slen, const char *format, ...)
25│ {
26│   /* For flag > 0 (i.e. __USE_FORTIFY_LEVEL > 1) request that %n
27│      can only come from read-only format strings.  */
28│   unsigned int mode = (flag > 0) ? PRINTF_FORTIFY : 0;
29│   va_list ap;
30│   int ret;
31│
32│   /* Regardless of the value of flag, let __vsprintf_internal know that
33│      this is a call from *printf_chk.  */
34│   mode |= PRINTF_CHK;
35│
36│   if (slen == 0)
37│     __chk_fail ();
38│
39|   va_start (ap, format);
40│├─>   ret = __vsprintf_internal (s, slen, format, ap, mode);
41│   va_end (ap);
42│
43│   return ret;
44│ }

Fixes criblio#1567
michalbiesek added a commit to michalbiesek/appscope that referenced this issue Jul 3, 2023
- add minimial nsterm example which reflects the
  issue with `top`

Ref: criblio#1567
michalbiesek added a commit to michalbiesek/appscope that referenced this issue Jul 3, 2023
The problematic code resides in `_nc_read_entry2`.

```
char filename[PATH_MAX]
...

    _nc_SPRINTF(filename, _nc_SLIMIT(PATH_MAX)
		"%.*s", PATH_MAX - 1, name);
```

The variable `name` above is set to "xterm".

In the absence of libscope.so, the aforementioned function assigns
the value "xterm" to the filename variable. However, when libscope.so
is loaded, the function assigns "xter" to filename.

In the Fedora environment, the invocation of `__sprintf_chk`
leads to the execution of `__vsprintf_internal`:

```
   va_start (ap, format);
   ret = __vsprintf_internal(s, slen, format, ap, mode);
   va_end (ap);
```

On the other hand, AppScope utilizes the following call:

```
   va_start(ap, format);
   rc = vsnprintf(str, strlen, format, ap);
   va_end(ap);
```

It should be noted that the implementations of `vsnprintf` and
`__vsprintf_internal` differ in standard library. This commit replaces
the `vsnprintf` call with `vsprintf` to address the discrepancy.

Fixes criblio#1567
michalbiesek added a commit to michalbiesek/appscope that referenced this issue Jul 4, 2023
- add minimial nsterm example which reflects the
  issue with `top`

Ref: criblio#1567
michalbiesek added a commit to michalbiesek/appscope that referenced this issue Jul 4, 2023
The problematic code resides in `_nc_read_entry2`.

```
char filename[PATH_MAX]
...

    _nc_SPRINTF(filename, _nc_SLIMIT(PATH_MAX)
		"%.*s", PATH_MAX - 1, name);
```

The variable `name` above is set to "xterm".

In the absence of libscope.so, the aforementioned function assigns
the value "xterm" to the filename variable. However, when libscope.so
is loaded, the function assigns "xter" to filename.

In the Fedora environment, the invocation of `__sprintf_chk`
leads to the execution of `__vsprintf_internal`:

```
   va_start (ap, format);
   ret = __vsprintf_internal(s, slen, format, ap, mode);
   va_end (ap);
```

On the other hand, AppScope utilizes the following call:

```
   va_start(ap, format);
   rc = vsnprintf(str, strlen, format, ap);
   va_end(ap);
```

It should be noted that the implementations of `vsnprintf` and
`__vsprintf_internal` differ in standard library. This commit replaces
the `vsnprintf` call with `vsprintf` to address the discrepancy.

Fixes criblio#1567
@michalbiesek
Copy link
Contributor

The #1572 address the issue.

The root cause:

The problematic code resides in _nc_read_entry2 in curses library.

char filename[PATH_MAX]
...

    _nc_SPRINTF(filename, _nc_SLIMIT(PATH_MAX)
		"%.*s", PATH_MAX - 1, name);

The variable name above is set to "xterm".

In the absence of libscope.so, the aforementioned function assigns
the value "xterm" to the filename variable. However, when libscope.so
is loaded, the function assigns "xter" to filename.

In the Fedora environment, the invocation of __sprintf_chk
leads to the execution of __vsprintf_internal:

   va_start (ap, format);
   ret = __vsprintf_internal(s, slen, format, ap, mode);
   va_end (ap);

On the other hand, AppScope utilizes the following call:

   va_start(ap, format);
   rc = vsnprintf(str, strlen, format, ap);
   va_end(ap);

It should be noted that the implementations of vsnprintf and
__vsprintf_internal differ in standard library. This commit replaces
the vsnprintf call with vsprintf to address the discrepancy.

The easiest way to test it is to try to scope top on Fedora.
Integration test was added to cover the issue.

michalbiesek added a commit that referenced this issue Jul 5, 2023
- add minimial nsterm example which reflects the
  issue with `top`

Ref: #1567
michalbiesek added a commit that referenced this issue Jul 5, 2023
The problematic code resides in `_nc_read_entry2`.

```
char filename[PATH_MAX]
...

    _nc_SPRINTF(filename, _nc_SLIMIT(PATH_MAX)
		"%.*s", PATH_MAX - 1, name);
```

The variable `name` above is set to "xterm".

In the absence of libscope.so, the aforementioned function assigns
the value "xterm" to the filename variable. However, when libscope.so
is loaded, the function assigns "xter" to filename.

In the Fedora environment, the invocation of `__sprintf_chk`
leads to the execution of `__vsprintf_internal`:

```
   va_start (ap, format);
   ret = __vsprintf_internal(s, slen, format, ap, mode);
   va_end (ap);
```

On the other hand, AppScope utilizes the following call:

```
   va_start(ap, format);
   rc = vsnprintf(str, strlen, format, ap);
   va_end(ap);
```

It should be noted that the implementations of `vsnprintf` and
`__vsprintf_internal` differ in standard library. This commit replaces
the `vsnprintf` call with `vsprintf` to address the discrepancy.

Fixes #1567
@michalbiesek michalbiesek linked a pull request Jul 5, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working libscope
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants