aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2024-01-24 21:19:37 -0500
committerMike Frysinger <vapier@gentoo.org>2024-01-24 21:19:37 -0500
commit6be48eb30663e52678a26e303a29842ca15dadca (patch)
tree62dedc73ae34355ada1f9ac715d65f78297501a8 /pspax.c
parentpspax: fix buffer limiting in cmdline reading (diff)
downloadpax-utils-6be48eb30663e52678a26e303a29842ca15dadca.tar.gz
pax-utils-6be48eb30663e52678a26e303a29842ca15dadca.tar.bz2
pax-utils-6be48eb30663e52678a26e303a29842ca15dadca.zip
pspax: fix error handling when reading attr or ipaddr fail
If these functions weren't able to read data from the files, they'd return the previous buffer contents which would be pretty confusing. Fix it to return NULL instead like other get helpers in here. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'pspax.c')
-rw-r--r--pspax.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/pspax.c b/pspax.c
index f1644a3..04cae79 100644
--- a/pspax.c
+++ b/pspax.c
@@ -230,9 +230,14 @@ static const char *get_pid_attr(int pfd)
if ((fp = fopenat_r(pfd, "attr/current")) == NULL)
return NULL;
- if (fgets(buf, sizeof(buf), fp) != NULL)
- if ((p = strchr(buf, '\n')) != NULL)
- *p = 0;
+ if (fgets(buf, sizeof(buf), fp) == NULL) {
+ fclose(fp);
+ return NULL;
+ }
+
+ if ((p = strchr(buf, '\n')) != NULL)
+ *p = 0;
+
fclose(fp);
return buf;
@@ -247,9 +252,14 @@ static const char *get_pid_addr(int pfd)
if ((fp = fopenat_r(pfd, "ipaddr")) == NULL)
return NULL;
- if (fgets(buf, sizeof(buf), fp) != NULL)
- if ((p = strchr(buf, '\n')) != NULL)
- *p = 0;
+ if (fgets(buf, sizeof(buf), fp) == NULL) {
+ fclose(fp);
+ return NULL;
+ }
+
+ if ((p = strchr(buf, '\n')) != NULL)
+ *p = 0;
+
fclose(fp);
return buf;