aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authormerakor <cem@ckyln.com>2020-06-03 19:24:46 +0000
committermerakor <cem@ckyln.com>2020-06-03 19:24:46 +0000
commit32fca65f3a4d7328342ad8ab84c60752d66e1c79 (patch)
tree3c392a48363adc7c26d60d9671dcbeabca7d811f /bin
parentc3f27bb1bd0eda5460f6207aec09c41881da1cdf (diff)
downloadcpt-32fca65f3a4d7328342ad8ab84c60752d66e1c79.tar.gz
kiss-stat: fix segfault
This fixes an issue when the file doesn't have a registered owner in the passwd database, but we still tried to print it. We now check if the entry exists before we try printing it. FossilOrigin-Name: f34d077df5b31e7fc810e6b32e8fd526962e1268544661c535477eb8ff40db60
Diffstat (limited to 'bin')
-rw-r--r--bin/kiss-stat.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/bin/kiss-stat.c b/bin/kiss-stat.c
index 5d62855..8692904 100644
--- a/bin/kiss-stat.c
+++ b/bin/kiss-stat.c
@@ -14,19 +14,24 @@
int main (int argc, char *argv[]) {
struct stat sb;
- // Exit if no or multiple arguments are given
+ // Exit if no or multiple arguments are given.
if (argc != 2 || strcmp(argv[1], "--help") == 0) {
fprintf(stderr, "Usage: %s <pathname>\n", argv[0]);
return(1);
}
- // Exit if file stat cannot be obtained
+ // Exit if file stat cannot be obtained.
if (lstat(argv[1], &sb) == -1) {
perror(argv[0]);
return(1);
}
- // Print the user name of file owner
+ // Exit if name of the owner cannot be retrieved.
+ if (!getpwuid(sb.st_uid)) {
+ return(1);
+ }
+
+ // Print the user name of file owner.
struct passwd *pw = getpwuid(sb.st_uid);
printf("%s\n", pw->pw_name);
return(0);