summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2012-06-20 10:07:12 +0200
committerAnand Avati <avati@redhat.com>2012-07-02 15:37:26 -0700
commit2310671cd15cd1639436a824922fa0a924cd6367 (patch)
tree8e32b0606370f0f53908469b2b306e26856ccd9f /xlators/mgmt
parent13e7f9dc6971be887fc73a460517fa84e11b927c (diff)
geo-rep: handle input without trailing newline; don't reference buf[-1]
Do not truncate final byte of a line that does not end in a newline. Do not clobber stack (resbuf[-1]) for input that starts with a NUL byte. Likewise in glusterd_urltransform. Change-Id: Ifdcad02d908c8dcbc1a0eee78d318dd4e7860322 BUG: 789278 Signed-off-by: Jim Meyering <meyering@redhat.com> Reviewed-on: http://review.gluster.com/3595 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Anand Avati <avati@redhat.com>
Diffstat (limited to 'xlators/mgmt')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-geo-rep.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c
index c66b2db578e..62122dbc27f 100644
--- a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c
+++ b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c
@@ -229,6 +229,7 @@ glusterd_urltransform (runner_t *runner, char ***linearrp)
arr_idx = 0;
for (;;) {
+ size_t len;
line = GF_MALLOC (1024, gf_gld_mt_linebuf);
if (!line) {
error = _gf_true;
@@ -239,12 +240,13 @@ glusterd_urltransform (runner_t *runner, char ***linearrp)
NULL)
break;
- if (line[strlen (line) - 1] != '\n') {
+ len = strlen (line);
+ if (len == 0 || line[len - 1] != '\n') {
GF_FREE (line);
error = _gf_true;
goto out;
}
- line[strlen (line) - 1] = '\0';
+ line[len - 1] = '\0';
if (arr_idx == arr_len) {
arr_len <<= 1;
@@ -383,8 +385,11 @@ _fcbk_singleline(char *resbuf, size_t blen, FILE *fp, void *data)
errno = 0;
ptr = fgets (resbuf, blen, fp);
- if (ptr)
- resbuf[strlen(resbuf)-1] = '\0'; //strip off \n
+ if (ptr) {
+ size_t len = strlen(resbuf);
+ if (len && resbuf[len-1] == '\n')
+ resbuf[len-1] = '\0'; //strip off \n
+ }
return errno ? -1 : 0;
}