diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2015-03-15 15:59:23 -0400 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2015-03-15 17:26:58 -0400 |
commit | 0daa5666da6fab8864e313dd594a2648d882e0cf (patch) | |
tree | aa744e7fcef5e90754bc275e4d7a120479a536cf | |
parent | cc3bc3e6203e0c615e31b8b68796362e1385f28a (diff) |
util: check asprintf return value
CID #1237546.
-rw-r--r-- | src/shared/util.c | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/src/shared/util.c b/src/shared/util.c index f1f7a5db66..5cbbe8fb7d 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -2926,31 +2926,30 @@ int get_ctty(pid_t pid, dev_t *_devnr, char **r) { /* This is an ugly hack */ if (major(devnr) == 136) { - asprintf(&b, "pts/%u", minor(devnr)); - goto finish; - } + if (asprintf(&b, "pts/%u", minor(devnr)) < 0) + return -ENOMEM; + } else { + /* Probably something like the ptys which have no + * symlink in /dev/char. Let's return something + * vaguely useful. */ - /* Probably something like the ptys which have no - * symlink in /dev/char. Let's return something - * vaguely useful. */ + b = strdup(fn + 5); + if (!b) + return -ENOMEM; + } + } else { + if (startswith(s, "/dev/")) + p = s + 5; + else if (startswith(s, "../")) + p = s + 3; + else + p = s; - b = strdup(fn + 5); - goto finish; + b = strdup(p); + if (!b) + return -ENOMEM; } - if (startswith(s, "/dev/")) - p = s + 5; - else if (startswith(s, "../")) - p = s + 3; - else - p = s; - - b = strdup(p); - -finish: - if (!b) - return -ENOMEM; - *r = b; if (_devnr) *_devnr = devnr; |