diff options
author | Kelvin M. Klann <kmk3.code@protonmail.com> | 2023-07-20 04:51:35 -0300 |
---|---|---|
committer | Kelvin M. Klann <kmk3.code@protonmail.com> | 2023-07-20 05:01:43 -0300 |
commit | 142f55107064d4cbd4e70ae625e909caa8d13952 (patch) | |
tree | 54db786d18ef6ef3a66a66727d8be4f4daf014c6 /src | |
parent | modif: drop deprecated 'shell' option references (#5894) (diff) | |
download | firejail-142f55107064d4cbd4e70ae625e909caa8d13952.tar.gz firejail-142f55107064d4cbd4e70ae625e909caa8d13952.tar.zst firejail-142f55107064d4cbd4e70ae625e909caa8d13952.zip |
hostnames.c: fix scan-build warning
This is breaking scan-build in CI[1]:
/usr/share/clang/scan-build-14/bin/../libexec/ccc-analyzer [...] -c hostnames.c -o hostnames.o
hostnames.c:59:10: warning: Null pointer passed to 1st parameter expecting 'nonnull' [core.NonNullParamChecker]
return strdup(rv);
^~~~~~~~~~
1 warning generated.
Likely caused by commit d2802ce60 ("fnettrace cleanup", 2023-07-15).
This also fixes a memory leak of `cmd`.
[1] https://github.com/netblue30/firejail/actions/runs/5568460702/jobs/10171098449
Diffstat (limited to 'src')
-rw-r--r-- | src/fnettrace/hostnames.c | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/src/fnettrace/hostnames.c b/src/fnettrace/hostnames.c index 7cb34e2c4..14ebc4ca0 100644 --- a/src/fnettrace/hostnames.c +++ b/src/fnettrace/hostnames.c | |||
@@ -40,30 +40,32 @@ char *retrieve_hostname(uint32_t ip) { | |||
40 | errExit("asprintf"); | 40 | errExit("asprintf"); |
41 | 41 | ||
42 | FILE *fp = popen(cmd, "r"); | 42 | FILE *fp = popen(cmd, "r"); |
43 | if (fp) { | 43 | if (!fp) { |
44 | char *ptr; | 44 | geoip_not_found = 1; |
45 | if (fgets(buf, MAXBUF, fp)) { | 45 | goto out; |
46 | ptr = strchr(buf, '\n'); | 46 | } |
47 | if (ptr) | 47 | |
48 | *ptr = '\0'; | 48 | char *ptr; |
49 | if (strncmp(buf, "GeoIP Country Edition:", 22) == 0) { | 49 | if (fgets(buf, MAXBUF, fp)) { |
50 | ptr = buf + 22; | 50 | ptr = strchr(buf, '\n'); |
51 | if (*ptr == ' ' && *(ptr + 3) == ',' && *(ptr + 4) == ' ') { | 51 | if (ptr) |
52 | rv = ptr + 5; | 52 | *ptr = '\0'; |
53 | if (strcmp(rv, "United States") == 0) | 53 | if (strncmp(buf, "GeoIP Country Edition:", 22) == 0) { |
54 | rv = "US"; | 54 | ptr = buf + 22; |
55 | } | 55 | if (*ptr == ' ' && *(ptr + 3) == ',' && *(ptr + 4) == ' ') { |
56 | rv = ptr + 5; | ||
57 | if (strcmp(rv, "United States") == 0) | ||
58 | rv = "US"; | ||
56 | } | 59 | } |
57 | } | 60 | } |
58 | pclose(fp); | ||
59 | return strdup(rv); | ||
60 | } | 61 | } |
61 | else | 62 | pclose(fp); |
62 | geoip_not_found = 1; | 63 | if (rv) |
64 | rv = strdup(rv); | ||
63 | 65 | ||
66 | out: | ||
64 | free(cmd); | 67 | free(cmd); |
65 | 68 | return rv; | |
66 | return NULL; | ||
67 | } | 69 | } |
68 | 70 | ||
69 | void load_hostnames(const char *fname) { | 71 | void load_hostnames(const char *fname) { |