Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buffer() is deprecated due to security and usability issues #109

Closed
asterizk opened this issue Apr 28, 2021 · 0 comments
Closed

Buffer() is deprecated due to security and usability issues #109

asterizk opened this issue Apr 28, 2021 · 0 comments

Comments

@asterizk
Copy link

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

This got rid of the warning described here: DylanPiercey/local-devices#14

Here is the diff that solved my problem:

diff --git a/node_modules/ip/lib/ip.js b/node_modules/ip/lib/ip.js
index c1799a8..dbd83e1 100644
--- a/node_modules/ip/lib/ip.js
+++ b/node_modules/ip/lib/ip.js
@@ -10,7 +10,7 @@ ip.toBuffer = function(ip, buff, offset) {
   var result;
 
   if (this.isV4Format(ip)) {
-    result = buff || new Buffer(offset + 4);
+    result = buff || new Buffer.alloc(offset + 4);
     ip.split(/\./g).map(function(byte) {
       result[offset++] = parseInt(byte, 10) & 0xff;
     });
@@ -45,7 +45,7 @@ ip.toBuffer = function(ip, buff, offset) {
       sections.splice.apply(sections, argv);
     }
 
-    result = buff || new Buffer(offset + 16);
+    result = buff || new Buffer.alloc(offset + 16);
     for (i = 0; i < sections.length; i++) {
       var word = parseInt(sections[i], 16);
       result[offset++] = (word >> 8) & 0xff;
@@ -110,7 +110,7 @@ ip.fromPrefixLen = function(prefixlen, family) {
   if (family === 'ipv6') {
     len = 16;
   }
-  var buff = new Buffer(len);
+  var buff = new Buffer.alloc(len);
 
   for (var i = 0, n = buff.length; i < n; ++i) {
     var bits = 8;
@@ -129,7 +129,7 @@ ip.mask = function(addr, mask) {
   addr = ip.toBuffer(addr);
   mask = ip.toBuffer(mask);
 
-  var result = new Buffer(Math.max(addr.length, mask.length));
+  var result = new Buffer.alloc(Math.max(addr.length, mask.length));
 
   var i = 0;
   // Same protocol - do bitwise and

This issue body was partially generated by patch-package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant