aboutsummaryrefslogtreecommitdiffstats
path: root/libinstaller
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2010-07-02 09:39:18 -0700
committerH. Peter Anvin <hpa@zytor.com>2010-07-02 09:39:18 -0700
commitcb88d31c15a2803950e81663e4d808a31ba4f8c0 (patch)
tree5b71201fa9b454ab8e4e818053455dc9f831f92b /libinstaller
parent63a5a1a7cac1147e80534edcef3b410e5a8119b8 (diff)
downloadsyslinux-cb88d31c15a2803950e81663e4d808a31ba4f8c0.tar.gz
syslinux-cb88d31c15a2803950e81663e4d808a31ba4f8c0.tar.xz
syslinux-cb88d31c15a2803950e81663e4d808a31ba4f8c0.zip
installers: handle asprintf() correctly
It appears that the glibc version of asprintf() is braindamaged, and doesn't set the target pointer to NULL in the event of an error (only returns -1). Therefore we need to check the return value. Just in case someone else made the *opposite* error, also check the pointer. Bleh. The glibc documentation states that *BSD sets the pointer to NULL, but instead of following that, the glibc people put warn_unused_result on asprintf. Sigh. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'libinstaller')
-rw-r--r--libinstaller/advio.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/libinstaller/advio.c b/libinstaller/advio.c
index 7bfc098c..56f607d0 100644
--- a/libinstaller/advio.c
+++ b/libinstaller/advio.c
@@ -45,11 +45,12 @@ int read_adv(const char *path, const char *cfg)
int fd = -1;
struct stat st;
int err = 0;
+ int rv;
- asprintf(&file, "%s%s%s",
- path, path[0] && path[strlen(path) - 1] == '/' ? "" : "/", cfg);
+ rv = asprintf(&file, "%s%s%s", path,
+ path[0] && path[strlen(path) - 1] == '/' ? "" : "/", cfg);
- if (!file) {
+ if (rv < 0 || !file) {
perror(program);
return -1;
}
@@ -97,11 +98,12 @@ int write_adv(const char *path, const char *cfg)
int fd = -1;
struct stat st, xst;
int err = 0;
+ int rv;
- err = asprintf(&file, "%s%s%s",
- path, path[0] && path[strlen(path) - 1] == '/' ? "" : "/", cfg);
+ rv = asprintf(&file, "%s%s%s", path,
+ path[0] && path[strlen(path) - 1] == '/' ? "" : "/", cfg);
- if (!file) {
+ if (rv < 0 || !file) {
perror(program);
return -1;
}