File: libpreload.c

package info (click to toggle)
flatpak 1.16.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,020 kB
  • sloc: ansic: 101,028; xml: 11,453; sh: 4,871; python: 2,251; yacc: 1,236; makefile: 86; csh: 20
file content (31 lines) | stat: -rw-r--r-- 799 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* vi:set et sw=2 sts=2 cin cino=t0,f0,(0,{s,>2s,n-s,^-s,e-s:
 * Copyright 2021 Collabora Ltd.
 * SPDX-License-Identifier: LGPL-2-or-later
 */

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

__attribute__((constructor)) static void
ctor (void)
{
  pid_t me = getpid ();
  struct stat buf;

  fprintf (stderr, "LD_PRELOAD module got loaded by process %d\n", me);

  if (stat ("/.flatpak-info", &buf) == 0)
    {
      fprintf (stderr, "OK: pid %d is in a Flatpak sandbox\n", me);
    }
  else
    {
      /* If the --env=LD_PRELOAD had come from a call to flatpak-portal,
       * then this would be a sandbox escape (GHSA-4ppf-fxf6-vxg2). */
      fprintf (stderr, "Error: pid %d is not in a Flatpak sandbox\n", me);
      abort ();
    }
}