Skip to content

Commit 72c22bb

Browse files
committed
Revert "kpartx: fix segfault when operating on regular files"
This reverts commit fab5d44.
1 parent b35369b commit 72c22bb

2 files changed

Lines changed: 9 additions & 12 deletions

File tree

kpartx/devmapper.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/*
22
* Copyright (c) 2004, 2005 Christophe Varoqui
33
*/
4-
#define _GNU_SOURCE
54
#include <stdio.h>
65
#include <stdlib.h>
76
#include <string.h>
@@ -700,13 +699,14 @@ int dm_find_part(const char *parent, const char *delim, int part,
700699

701700
char *nondm_create_uuid(dev_t devt)
702701
{
703-
char *uuid;
704-
705-
if (asprintf(&uuid, "%s_%u:%u_%s", NONDM_UUID_PREFIX, major(devt),
706-
minor(devt), NONDM_UUID_SUFFIX) >= 0)
707-
return uuid;
708-
else
709-
return NULL;
702+
#define NONDM_UUID_BUFLEN (34 + sizeof(NONDM_UUID_PREFIX) + \
703+
sizeof(NONDM_UUID_SUFFIX))
704+
static char uuid_buf[NONDM_UUID_BUFLEN];
705+
snprintf(uuid_buf, sizeof(uuid_buf), "%s_%u:%u_%s",
706+
NONDM_UUID_PREFIX, major(devt), minor(devt),
707+
NONDM_UUID_SUFFIX);
708+
uuid_buf[NONDM_UUID_BUFLEN-1] = '\0';
709+
return uuid_buf;
710710
}
711711

712712
int nondm_parse_uuid(const char *uuid, unsigned int *major, unsigned int *minor)

kpartx/kpartx.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,8 @@ main(int argc, char **argv){
334334
* This allows deletion of partitions created with older kpartx
335335
* versions which didn't use the fake UUID during creation.
336336
*/
337-
if (!uuid && !(what == DELETE && force_devmap)) {
337+
if (!uuid && !(what == DELETE && force_devmap))
338338
uuid = nondm_create_uuid(buf.st_rdev);
339-
if (!uuid)
340-
exit(1);
341-
}
342339

343340
if (delim == NULL) {
344341
delim = xmalloc(DELIM_SIZE);

0 commit comments

Comments
 (0)