Skip to content
Snippets Groups Projects
Commit 90dfbf1a authored by Adrien Béraud's avatar Adrien Béraud
Browse files

registration: prevent name conversion to binary

Web3 automatic conversion could interpret some names
as hex.
Prevent this by manually converting the name to hex.

Change-Id: I304c3a49623a72bd7ebd53a95418722eca430a8f
parent 68166edf
Branches
Tags beta/202502271729
No related merge requests found
...@@ -168,6 +168,10 @@ function checkName(name) { ...@@ -168,6 +168,10 @@ function checkName(name) {
} }
} }
function formatName(name) {
return '0x' + new Buffer(name, 'utf8').toString('hex');
}
function isHashZero(h) { function isHashZero(h) {
return !h || h == "0x" || h == "0x0" || h == "0x0000000000000000000000000000000000000000"; return !h || h == "0x" || h == "0x0" || h == "0x0000000000000000000000000000000000000000";
} }
...@@ -183,7 +187,7 @@ function formatAddress(s) { ...@@ -183,7 +187,7 @@ function formatAddress(s) {
s = s.substr(5); s = s.substr(5);
if (!s.startsWith("0x")) if (!s.startsWith("0x"))
s = "0x" + s; s = "0x" + s;
if (new BigNumber(s) == 0) if (new BigNumber(s.substr(2), 16) == 0)
return undefined; return undefined;
return s; return s;
} catch (err) {} } catch (err) {}
...@@ -204,7 +208,7 @@ function startServer() { ...@@ -204,7 +208,7 @@ function startServer() {
// Register name lookup handler // Register name lookup handler
app.get("/name/:name", function(req, http_res) { app.get("/name/:name", function(req, http_res) {
try { try {
reg.addr(req.params.name, function(err, res) { reg.addr(formatName(req.params.name), function(err, res) {
try { try {
if (err) if (err)
console.log("Name lookup error: " + err); console.log("Name lookup error: " + err);
...@@ -314,7 +318,7 @@ function startServer() { ...@@ -314,7 +318,7 @@ function startServer() {
} else { } else {
console.log("Remaing gaz: " + getRemainingGaz()); console.log("Remaing gaz: " + getRemainingGaz());
unlockAccount(); unlockAccount();
reg.reserveFor.sendTransaction(req.params.name, req.body.owner, addr, { reg.reserveFor.sendTransaction(formatName(req.params.name), req.body.owner, addr, {
from: coinbase, from: coinbase,
gas: 3000000 gas: 3000000
}, function(terr, reg_c) { }, function(terr, reg_c) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment