Files
systemd/src/basic
Frantisek Sumsal f392dfb5a1 tree-wide: check memstream buffer after closing the handle
When closing the FILE handle attached to a memstream, it may attempt to
do a realloc() that may fail during OOM situations, in which case we are
left with the buffer pointer pointing to NULL and buffer size > 0. For
example:

```
    #include <errno.h>
    #include <stdio.h>
    #include <stdlib.h>

    void *realloc(void *ptr, size_t size) {
        return NULL;
    }

    int main(int argc, char *argv[])
    {
        FILE *f;
        char *buf;
        size_t sz = 0;

        f = open_memstream(&buf, &sz);
        if (!f)
            return -ENOMEM;

        fputs("Hello", f);

        fflush(f);
        printf("buf: 0x%lx, sz: %lu, errno: %d\n",
                    (unsigned long) buf, sz, errno);
        fclose(f);
        printf("buf: 0x%lx, sz: %lu, errno: %d\n",
                    (unsigned long) buf, sz, errno);

        return 0;
    }
```

```
$ gcc -o main main.c
$ ./main
buf: 0x74d4a0, sz: 5, errno: 0
buf: 0x0, sz: 5, errno: 0
```

This might do unexpected things if the underlying code expects a valid
pointer to the memstream buffer after closing the handle.

Found by Nallocfuzz.
2023-05-24 21:59:10 +02:00
..
…
…
…
2023-02-09 15:32:33 +00:00
2022-11-08 13:41:14 +01:00
…
2023-05-24 13:56:22 +02:00
2023-05-05 09:10:56 +02:00
2023-03-22 21:54:20 +01:00
2023-04-20 09:20:08 +02:00
2023-03-22 21:54:20 +01:00
2023-03-22 21:54:20 +01:00
2023-03-29 13:00:33 +09:00
2022-08-02 02:43:38 +09:00
2023-02-24 14:11:31 +01:00
2023-03-15 01:18:59 +00:00
2023-04-03 15:28:00 +02:00
2022-11-09 11:14:10 +01:00
2023-05-05 08:54:28 +02:00
2023-03-10 09:47:39 +01:00
2023-03-10 09:47:39 +01:00
2022-12-23 23:26:26 +01:00
2022-12-23 23:26:26 +01:00
2022-11-08 18:21:10 +01:00
…
2022-09-13 08:13:27 +02:00
2022-03-18 09:42:38 +01:00
…
…
2023-04-20 13:43:37 +02:00
2023-02-14 12:51:38 +01:00