Skip to content

Commit

Permalink
s3: vfs: snapper: Add and use len_before_gmt, calculated as (p-name).
Browse files Browse the repository at this point in the history
Make the code closer to the same functionality in shadow_copy2.c:shadow_copy2_strip_snapshot().

BUG: https://bugzilla.samba.org/show_bug.cgi?id=12150

Signed-off-by: Jeremy Allison <[email protected]>
Reviewed-by: Christof Schmitt <[email protected]>
Reviewed-by: David Disseldorp <[email protected]>
  • Loading branch information
jrasamba authored and ddiss committed Aug 18, 2016
1 parent abf18f4 commit 3e3b9be
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions source3/modules/vfs_snapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -1729,6 +1729,7 @@ static bool snapper_gmt_strip_snapshot(TALLOC_CTX *mem_ctx,
char *q;
char *stripped;
size_t rest_len, dst_len;
ptrdiff_t len_before_gmt;

p = strstr_m(name, "@GMT-");
if (p == NULL) {
Expand All @@ -1737,6 +1738,7 @@ static bool snapper_gmt_strip_snapshot(TALLOC_CTX *mem_ctx,
if ((p > name) && (p[-1] != '/')) {
goto no_snapshot;
}
len_before_gmt = p - name;
q = strptime(p, GMT_FORMAT, &tm);
if (q == NULL) {
goto no_snapshot;
Expand All @@ -1763,7 +1765,7 @@ static bool snapper_gmt_strip_snapshot(TALLOC_CTX *mem_ctx,
q += 1;

rest_len = strlen(q);
dst_len = (p-name) + rest_len;
dst_len = len_before_gmt + rest_len;

if (pstripped != NULL) {
stripped = talloc_array(mem_ctx, char, dst_len+1);
Expand All @@ -1772,10 +1774,10 @@ static bool snapper_gmt_strip_snapshot(TALLOC_CTX *mem_ctx,
return false;
}
if (p > name) {
memcpy(stripped, name, p-name);
memcpy(stripped, name, len_before_gmt);
}
if (rest_len > 0) {
memcpy(stripped + (p-name), q, rest_len);
memcpy(stripped + len_before_gmt, q, rest_len);
}
stripped[dst_len] = '\0';
*pstripped = stripped;
Expand Down

0 comments on commit 3e3b9be

Please sign in to comment.