Skip to content
Browse files

Fix build on some linux distros & fix generic bug

 * Fix a bug in the use of asprintf. asprintf returns an error code
   and sets the buffer to NULL if it can't allocate memory. Handle
   that case gracefully.

 * Define _GNU_SOURCE globally since it seems that the stdlib includes
   in some Linux distributions (Gentoo, Ubuntu) are broken and don't
   work without giving warnings if _GNU_SOURCE isn't defined.

* Reported-by: Cody Schafer (jmesmon)
* Fixes-Issue: 1
  • Loading branch information...
1 parent a0d7aa0 commit 5205e1482285ee98052a5e17c09cbedf64719d46 @bwalex committed Aug 16, 2011
Showing with 8 additions and 7 deletions.
  1. +1 −0 Makefile
  2. +1 −1 io.c
  3. +6 −6 tcplay.c
View
1 Makefile
@@ -30,6 +30,7 @@ else
endif
ifeq (${SYSTEM}, linux)
+ CFLAGS+= -D_GNU_SOURCE
LIBS+= -lgcrypt -ldevmapper -luuid
SRCS+= crypto-gcrypt.c
OBJS+= crypto-gcrypt.o
View
2 io.c
@@ -350,7 +350,7 @@ read_passphrase(const char *prompt, char *pass, size_t passlen, time_t timeout)
cfd = 1;
}
- printf(prompt);
+ printf("%s", prompt);
fflush(stdout);
memset(pass, 0, passlen);
View
12 tcplay.c
@@ -27,10 +27,6 @@
* SUCH DAMAGE.
*/
-#if defined(__linux__)
-#define _GNU_SOURCE /* for asprintf */
-#endif
-
#include <sys/types.h>
#if defined(__DragonFly__)
@@ -1109,7 +1105,10 @@ dm_setup(const char *mapname, struct tcplay_info *info)
dm_udev_wait(cookie);
- asprintf(&uu_stack[uu_stack_idx++], "%s", map);
+ if ((r = asprintf(&uu_stack[uu_stack_idx++], "%s", map)) < 0)
+ tc_log(1, "warning, asprintf failed. won't be able to "
+ "unroll changes\n");
+
offset = 0;
start = 0;
@@ -1131,7 +1130,8 @@ dm_setup(const char *mapname, struct tcplay_info *info)
printf("Unrolling dm changes! j = %d (%s)\n", j-1,
uu_stack[j-1]);
#endif
- if ((r = dm_remove_device(uu_stack[--j])) != 0) {
+ if ((uu_stack[j-1] == NULL) ||
+ ((r = dm_remove_device(uu_stack[--j])) != 0)) {
tc_log(1, "Tried to unroll dm changes, "
"giving up.\n");
break;

0 comments on commit 5205e14

Please sign in to comment.
Something went wrong with that request. Please try again.