glusterfs/extras/geo-rep/gsync-sync-gfid.c
Lalatendu Mohanty 115ecc8da8 Core: Fix issues reported by Cppcheck
Fixed in this patch:

[glusterfs/extras/geo-rep/gsync-sync-gfid.c:105]: (error) Resource leak: fp
[glusterfs/libglusterfs/src/xlator.c:651]: (error) Uninitialized variable: gfid
[glusterfs/libglusterfs/src/xlator.c:652]: (error) Uninitialized variable: gfid
[glusterfs/xlators/cluster/ha/src/ha.c:2699]: (error) Possible null pointer dereference: priv
[glusterfs/xlators/features/changelog/src/changelog.c:1464]: (error) Possible null pointer dereference: priv
[glusterfs/xlators/mgmt/glusterd/src/glusterd-mgmt-handler.c:865]: (error) Possible null pointer dereference: ctx
[glusterfs/xlators/mgmt/glusterd/src/glusterd-mgmt-handler.c:194]: (error) Possible null pointer dereference: ctx
[glusterfs/xlators/mgmt/glusterd/src/glusterd-syncop.c:1408]: (error) Possible null pointer dereference: this
[glusterfs/xlators/mgmt/glusterd/src/glusterd-utils.c:7002]: (error) Possible null pointer dereference: path_tokens

Fixed in 3.4 and 3.5 branch (http://review.gluster.org/#/c/7583/ ,
http://review.gluster.org/#/c/7605/ will be backported in a separate patch)

[glusterfs/xlators/mount/fuse/src/fuse-bridge.c:4688]: (error) Uninitialized variable: finh
[glusterfs/xlators/mount/fuse/src/fuse-bridge.c:3081]: (error) Possible null pointer dereference: state
[glusterfs/xlators/cluster/dht/src/dht-rebalance.c:1719]: (error) Possible null pointer dereference: ctx
[glusterfs/xlators/cluster/stripe/src/stripe.c:4940]: (error) Possible null pointer dereference: local
[glusterfs/xlators/mgmt/glusterd/src/glusterd-replace-brick.c:915]: (error) Resource leak: file
[glusterfs/xlators/mgmt/glusterd/src/glusterd-replace-brick.c:999]: (error) Resource leak: file
[glusterfs/xlators/mgmt/glusterd/src/glusterd-sm.c:248]: (error) Possible null pointer dereference: new_ev_ctx
[glusterfs/xlators/mgmt/glusterd/src/glusterd-utils.c:5297]: (error) Possible null pointer dereference: this
[glusterfs/xlators/mgmt/glusterd/src/glusterd-utils.c:6273]: (error) Possible null pointer dereference: this
[glusterfs/xlators/performance/quick-read/src/quick-read.c:586]: (error) Possible null pointer dereference: iobuf
[glusterfs/xlators/nfs/server/src/nfs-common.c:89]: (error) Dangerous usage of 'volname' (strncpy doesn't always null-terminate it).

False positives

[glusterfs/geo-replication/src/gsyncd.c:99]: (error) Memory leak: str
[glusterfs/geo-replication/src/gsyncd.c:395]: (error) Memory leak: argv
[glusterfs/xlators/nfs/server/src/nlm4.c:1199]: (error) Possible null pointer dereference: fde
[glusterfs/xlators/mgmt/glusterd/src/glusterd-geo-rep.c:1659]: (error) Possible null pointer dereference: command
[glusterfs/xlators/mgmt/glusterd/src/glusterd-utils.c:7001]: (error) Possible null pointer dereference: path_tokens

Insignificant/Don't care

[glusterfs/contrib/uuid/gen_uuid.c:369]: (warning) %ld in format string (no. 2) requires 'long *' but the argument type is 'unsigned long *'.
[glusterfs/contrib/uuid/gen_uuid.c:369]: (warning) %ld in format string (no. 3) requires 'long *' but the argument type is 'unsigned long *'.
[glusterfs/extras/test/test-ffop.c:27]: (error) Buffer overrun possible for long command line arguments.
[glusterfs/xlators/cluster/afr/src/afr-self-heal-common.c:138]: (error) Possible null pointer dereference: __ptr
[glusterfs/xlators/cluster/afr/src/afr-self-heal-common.c:140]: (error) Possible null pointer dereference: __ptr
[glusterfs/xlators/cluster/afr/src/afr-self-heal-common.c:331]: (error) Possible null pointer dereference: __ptr

Change-Id: I7696ed1a2a9553b79f9714e10210a8d563a5abd8
BUG: 1091677
Signed-off-by: Lalatendu Mohanty <lmohanty@redhat.com>
Reviewed-on: http://review.gluster.org/7693
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com>
Reviewed-by: Vijay Bellur <vbellur@redhat.com>
2014-06-12 04:20:34 -07:00

110 lines
3.1 KiB
C

#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <limits.h>
#include <sys/types.h>
#include <libgen.h>
#include <ctype.h>
#include <stdlib.h>
#include "glusterfs.h"
#include "syscall.h"
#ifndef UUID_CANONICAL_FORM_LEN
#define UUID_CANONICAL_FORM_LEN 36
#endif
#ifndef GF_FUSE_AUX_GFID_HEAL
#define GF_FUSE_AUX_GFID_HEAL "glusterfs.gfid.heal"
#endif
#define GLFS_LINE_MAX (PATH_MAX + (2 * UUID_CANONICAL_FORM_LEN))
int
main (int argc, char *argv[])
{
char *file = NULL;
char *tmp = NULL;
char *tmp1 = NULL;
char *parent_dir = NULL;
char *gfid = NULL;
char *bname = NULL;
int ret = -1;
int len = 0;
FILE *fp = NULL;
char line[GLFS_LINE_MAX] = {0,};
char *path = NULL;
void *blob = NULL;
void *tmp_blob = NULL;
if (argc != 2) {
/* each line in the file has the following format
* uuid-in-canonical-form path-relative-to-gluster-mount.
* Both uuid and relative path are from master mount.
*/
fprintf (stderr, "usage: %s <file-of-paths-to-be-synced>\n",
argv[0]);
goto out;
}
file = argv[1];
fp = fopen (file, "r");
if (fp == NULL) {
fprintf (stderr, "cannot open %s for reading (%s)\n",
file, strerror (errno));
goto out;
}
while (fgets (line, GLFS_LINE_MAX, fp) != NULL) {
tmp = line;
path = gfid = line;
path += UUID_CANONICAL_FORM_LEN + 1;
while(isspace (*path))
path++;
if ((strlen (line) < GLFS_LINE_MAX) &&
(line[strlen (line) - 1] == '\n'))
line[strlen (line) - 1] = '\0';
line[UUID_CANONICAL_FORM_LEN] = '\0';
tmp = strdup (path);
tmp1 = strdup (path);
parent_dir = dirname (tmp);
bname = basename (tmp1);
/* gfid + '\0' + bname + '\0' */
len = UUID_CANONICAL_FORM_LEN + 1 + strlen (bname) + 1;
blob = calloc (1, len);
memcpy (blob, gfid, UUID_CANONICAL_FORM_LEN);
tmp_blob = blob + UUID_CANONICAL_FORM_LEN + 1;
memcpy (tmp_blob, bname, strlen (bname));
ret = sys_lsetxattr (parent_dir, GF_FUSE_AUX_GFID_HEAL,
blob, len, 0);
if (ret < 0) {
fprintf (stderr, "setxattr on %s/%s failed (%s)\n",
parent_dir, bname, strerror (errno));
}
memset (line, 0, GLFS_LINE_MAX);
free (blob);
free (tmp); free (tmp1);
blob = NULL;
}
ret = 0;
out:
if (fp)
fclose(fp);
return ret;
}