Skip to content

Commit 34fd04d

Browse files
committed
Merge pull request #301 from Jimbly/better_random
Change upload temporary file path generation to use crypto.randomBytes()
2 parents ac89c44 + 4cf6b7e commit 34fd04d

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

lib/incoming_form.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
if (global.GENTLY) require = GENTLY.hijack(require);
22

3+
var crypto = require('crypto');
34
var fs = require('fs');
45
var util = require('util'),
56
path = require('path'),
@@ -528,9 +529,10 @@ IncomingForm.prototype._initJSONencoded = function() {
528529
};
529530

530531
IncomingForm.prototype._uploadPath = function(filename) {
531-
var name = '';
532-
for (var i = 0; i < 32; i++) {
533-
name += Math.floor(Math.random() * 16).toString(16);
532+
var name = 'upload_';
533+
var buf = crypto.randomBytes(16);
534+
for (var i = 0; i < buf.length; ++i) {
535+
name += ('0' + buf[i].toString(16)).slice(-2);
534536
}
535537

536538
if (this.keepExtensions) {

0 commit comments

Comments
 (0)