Skip to content

Commit

Permalink
Merge pull request #572 from aerospike/CLIENT-2466
Browse files Browse the repository at this point in the history
Added additional input validation.
  • Loading branch information
DomPeliniAerospike authored Aug 2, 2023
2 parents ec9037f + ef0baa9 commit 45eadfe
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 77 deletions.
110 changes: 36 additions & 74 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,7 @@ Client.prototype.batchGet = function (keys, policy, callback) {
* all bins; if false and <code>bins</code> is specified, read specified bins;
* if false and <code>bins</code> is not specified, read only record meta data
* (generation, expiration, etc.)
* @param {Object[]} [records[].ops] - List of {@link module:aerospike/operations|operations}
* @param {BatchPolicy} [policy] - The Batch Policy to use for this operation.
* @param {batchRecordsCallback} [callback] - The function to call when
* the operation completes, with the results of the batch operation.
Expand Down Expand Up @@ -800,81 +801,42 @@ Client.prototype.batchRead = function (records, policy, callback) {
*
* @since v5.0.0
*
* @example
* const Aerospike = require('aerospike')
* const batchType = Aerospike.batchType
* const op = Aerospike.operations
* const GeoJSON = Aerospike.GeoJSON
* const exp = Aerospike.exp
*
* // INSERT HOSTNAME AND PORT NUMBER OF AEROSPIKE SERVER NODE HERE!
* var config = {
* hosts: '192.168.33.10:3000',
* // Timeouts disabled, latency dependent on server location. Configure as needed.
* policies: {
* batch : new Aerospike.BatchPolicy({socketTimeout : 0, totalTimeout : 0}),
* }
* @example <caption>Apply a UDF to a batch of ten keys</caption>
*
* const Aerospike = require('aerospike');
* const batchType = Aerospike.batchType;
*
* // Define host configuration
* let config = {hosts: '127.0.0.1:3000'};
*
* // Create batch of keys
* let keys = [];
* for(i = 0; i < 10; i++){
* keys.push(new Aerospike.Key('sandbox', 'ufodata', i + 1));
* }
*
* var batchRecords = [
* { type: batchType.BATCH_READ,
* key: new Aerospike.Key('test', 'demo', 'key1'),
* bins: ['i', 's'] },
* { type: batchType.BATCH_READ,
* key: new Aerospike.Key('test', 'demo', 'key2'),
* readAllBins: true },
* { type: batchType.BATCH_READ,
* key: new Aerospike.Key('test', 'demo', 'key3'),
* ops:[
* op.read('blob')
* ]},
* { type: batchType.BATCH_WRITE,
* key: new Aerospike.Key('test', 'demo', 'key4'),
* ops:[
* op.write('geo', new GeoJSON({ type: 'Point', coordinates: [123.456, 1.308] })),
* op.write('blob', Buffer.from('bar'))
* ],
* policy: new Aerospike.BatchWritePolicy({
* filterExpression: exp.eq(exp.binInt('i'), exp.int(37)),
* key: Aerospike.policy.key.SEND,
* commitLevel: Aerospike.policy.commitLevel.ALL,
* gen: Aerospike.policy.gen.EQ,
* exists: Aerospike.policy.exists.CREATE,
* durableDelete: true
* }),
* { type: batchType.BATCH_REMOVE,
* key: new Aerospike.Key('test', 'demo', 'key5'),
* policy: new Aerospike.BatchRemovePolicy({
* filterExpression: exp.eq(exp.binInt('i'), exp.int(37)),
* key: Aerospike.policy.key.SEND,
* commitLevel: Aerospike.policy.commitLevel.ALL,
* gen: Aerospike.policy.gen.EQ,
* durableDelete: true
* }),
* }
* ]
*
* Aerospike.connect(config, (error, client) => {
* if (error) throw error
* client.batchWrite(batchRecords, (error, results) => {
* if (error) throw error
* results.forEach((result) => {
* switch (result.status) {
* case Aerospike.status.OK:
* console.log("Record found")
* break
* case Aerospike.status.ERR_RECORD_NOT_FOUND:
* console.log("Record not found")
* break
* default:
* // error while reading record
* console.log("Other error")
* break
* }
* })
* client.close()
* })
* })
*
* ;(async () => {
* // Establishes a connection to the server
* let client = await Aerospike.connect(config);
*
* // Execute the UDF
* let batchResult = await client.batchApply(batchRecords,
* {
* module: 'example',
* funcname: 'getDaysBetween',
* args: ['occurred', 'posted']
* }
* );
*
* // Access the records
* batchResult.forEach(result => {
* // Do something
* console.info("%o days between occurrence and post", result.record.bins.SUCCESS);
* });
*
* // Close the connection to the server
* client.close();
* })();
*/
Client.prototype.batchWrite = function (records, policy, callback) {
if (typeof policy === 'function') {
Expand Down
7 changes: 6 additions & 1 deletion lib/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,12 @@ Query.prototype.foreach = function (policy, dataCb, errorCb, endCb) {
if (this.paginate) {
args.push(this.queryState)
args.push(this.maxRecords)
args.push(this.filters[0].context ? { context: this.filters[0].context } : null)
if ((this.filters == null) && (this.filters[0].context)) {
args.push({ context: this.filters[0].context })
}
else {
args.push(null)
}
cmd = new Commands.QueryPages(stream, args)
} else {
cmd = new Commands.Query(stream, args)
Expand Down
3 changes: 2 additions & 1 deletion src/main/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ int config_from_jsobject(as_config *config, Local<Object> configObj,
goto Cleanup;
}
else if (defined) {
strcpy(config->lua.user_path, user_path);
strncpy(config->lua.user_path, user_path, ((strlen(user_path) + 1) < AS_CONFIG_PATH_MAX_SIZE) ?
(strlen(user_path) + 1) : AS_CONFIG_PATH_MAX_SIZE);
}
else {
as_v8_debug(log, "Using default Lua user path: %s",
Expand Down
4 changes: 3 additions & 1 deletion src/main/util/conversions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,9 @@ int host_from_jsobject(Local<Object> obj, char **addr, uint16_t *port,

if (v8_addr->IsString()) {
*addr = (char *)malloc(HOST_ADDRESS_SIZE);
strcpy(*addr, *Nan::Utf8String(v8_addr.As<String>()));
Local<String> v8_string_addr = v8_addr.As<String>();
strncpy(*addr, *Nan::Utf8String(v8_string_addr), ((v8_string_addr->Length() + 1) < HOST_ADDRESS_SIZE) ?
(v8_string_addr->Length() + 1) : HOST_ADDRESS_SIZE);
as_v8_detail(log, "host addr : %s", (*addr));
}
else {
Expand Down

0 comments on commit 45eadfe

Please sign in to comment.