From: Alex Elder <aelder@sgi.com>
To: xfs@oss.sgi.com
Subject: [PATCH 07/12] xfsprogs: use pointers in generate_obfuscated_name()
Date: Thu, 30 Dec 2010 14:41:23 -0600 [thread overview]
Message-ID: <1293741683.2294.366.camel@doink> (raw)
Switch from using array references to using pointers to
refer to the pathname characters as they get generated.
Also limit the scope of a few automatic variables.
Signed-off-by: Alex Elder <aelder@sgi.com>
---
db/metadump.c | 42 ++++++++++++++++++++++--------------------
1 file changed, 22 insertions(+), 20 deletions(-)
Index: b/db/metadump.c
===================================================================
--- a/db/metadump.c
+++ b/db/metadump.c
@@ -415,11 +415,8 @@ generate_obfuscated_name(
{
xfs_dahash_t hash;
name_ent_t *p;
- int i;
int dup;
- xfs_dahash_t newhash;
uchar_t newname[NAME_MAX];
- uchar_t *newp = &newname[0];
/*
* Our obfuscation algorithm requires at least 5-character
@@ -450,7 +447,12 @@ generate_obfuscated_name(
if (*name == '/')
name++;
do {
- uchar_t high_bit;
+ int i;
+ xfs_dahash_t newhash = 0;
+ uchar_t *newp = &newname[0];
+ uchar_t *first;
+ uchar_t high_bit;
+ int shift;
dup = 0;
@@ -460,10 +462,10 @@ generate_obfuscated_name(
* characters. Accumulate its new hash value as we
* go.
*/
- newhash = 0;
for (i = 0; i < namelen - 5; i++) {
- newp[i] = random_filename_char();
- newhash = newp[i] ^ rol32(newhash, 7);
+ *newp = random_filename_char();
+ newhash = *newp ^ rol32(newhash, 7);
+ newp++;
}
/*
@@ -478,16 +480,16 @@ generate_obfuscated_name(
*/
newhash = rol32(newhash, 3) ^ hash;
+ first = newp;
high_bit = 0;
- for (i = 5; i > 0; i--) {
- int shift = (i - 1) * 7;
-
- newp[namelen - i] = ((newhash >> shift) & 0x7f) ^ high_bit;
- if (is_invalid_char(newp[namelen - i])) {
- newp[namelen - i] ^= 1;
+ for (shift = 28; shift >= 0; shift -= 7) {
+ *newp = (newhash >> shift & 0x7f) ^ high_bit;
+ if (is_invalid_char(*newp)) {
+ *newp ^= 1;
high_bit = 0x80;
} else
high_bit = 0;
+ newp++;
}
/*
@@ -497,12 +499,12 @@ generate_obfuscated_name(
* we flip one more bit in both bytes.
*/
if (high_bit) {
- newp[namelen - 5] ^= 0x10;
- if (is_invalid_char(newp[namelen - 5])) {
- newp[namelen - 1] ^= 2;
- newp[namelen - 5] ^= 0x20;
- ASSERT(!is_invalid_char(newp[namelen - 1]));
- ASSERT(!is_invalid_char(newp[namelen - 5]));
+ *first ^= 0x10;
+ if (is_invalid_char(*first)) {
+ *--newp ^= 2;
+ *first ^= 0x20;
+ ASSERT(!is_invalid_char(*newp));
+ ASSERT(!is_invalid_char(*first));
}
}
@@ -510,7 +512,7 @@ generate_obfuscated_name(
for (p = nametable[hash % NAME_TABLE_SIZE]; p; p = p->next) {
if (p->hash == hash && p->namelen == namelen &&
- memcmp(p->name, newname, namelen) == 0){
+ !memcmp(p->name, newname, namelen)) {
dup = 1;
break;
}
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
reply other threads:[~2010-12-30 20:39 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1293741683.2294.366.camel@doink \
--to=aelder@sgi.com \
--cc=xfs@oss.sgi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.