Forum: PC-Programmierung Fühlt sich der gcc hier veralbert?


von Bauform B. (bauformb)


Lesenswert?

Guten Morgen,

ist dieser Fehler so dumm, dass der nicht einmal eine Warnung wert ist? 
Ungefähr 70 -W von -Waggregate-return bis -Wwrite-strings reichen nicht? 
Kann man dagegen etwas tun?
1
static void
2
foo (const char *bozo_exe)
3
{
4
   char   *args[16], *envs[4];
5
6
   printf ("Starting %s...\n", bozo_exe);
7
   asprintf (&envs[ 0], "HOME=%s",  "/");
8
   asprintf (&envs[ 1], "PWD=%s",   "/");
9
   asprintf (&envs[ 2], "LANG=%s",  "C");
10
   asprintf (&envs[ 3], "USER=%s",  cf.uid);
11
   asprintf (&envs[ 4], "PATH=%s",  "/sbin:/usr/sbin:/bin:/usr/bin");
12
   asprintf (&envs[ 5], "SHELL=%s", "/bin/sh");
13
   envs[ 6] = NULL;
14
15
   args[ 0] = strdup (bozo_exe);
16
   args[ 1] = strdup ("-P");
17
// ...
18
   if (execve (args[0], args, envs)) {
19
// ...
20
   }
21
}
$ gcc --version

gcc (Debian 15.3.0-1) 15.3.0
: Bearbeitet durch User
von Niklas G. (erlkoenig) Benutzerseite


Lesenswert?

Bauform B. schrieb:
> Kann man dagegen etwas tun?

Python verwenden
von Norbert (der_norbert)


Lesenswert?

splint -strict nutzen
1
unbenannt.c:26:15: Possible out-of-bounds read: envs[5]
2
    Unable to resolve constraint:
3
    requires maxRead(envs @ unbenannt.c:26:15) >= 5
4
     needed to satisfy precondition:
5
    requires maxRead(envs @ unbenannt.c:26:15) >= 5
6
  A memory read references memory beyond the allocated storage. (Use
7
  -boundsread to inhibit warning)
8
unbenannt.c:28:4: Likely out-of-bounds store: envs[6]
9
    Unable to resolve constraint:
10
    requires 3 >= 6
11
     needed to satisfy precondition:
12
    requires maxSet(envs @ unbenannt.c:28:4) >= 6
13
  A memory write may write to an address beyond the allocated buffer. (Use
14
  -likelyboundswrite to inhibit warning)
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.