From: "n.pettik" <korablev@tarantool.org>
To: tarantool-patches@freelists.org
Cc: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Subject: [tarantool-patches] Re: [PATCH 1/2] sql: fix tuple format leak
Date: Fri, 13 Apr 2018 11:39:22 +0300 [thread overview]
Message-ID: <0970BD07-7BA0-4EF3-B50B-1F821F7B3570@tarantool.org> (raw)
In-Reply-To: <b2b9ed52-14ee-f1ee-4e88-792319296a16@tarantool.org>
> On 12 Apr 2018, at 14:58, Vladislav Shpilevoy <v.shpilevoy@tarantool.org> wrote:
>
> Hello. Thank you for contributing! See below 3 comments.
>
>> diff --git a/src/box/sql.c b/src/box/sql.c
>> index a6713f1f0..dd0cfcc1a 100644
>> --- a/src/box/sql.c
>> +++ b/src/box/sql.c
>> @@ -451,17 +451,13 @@ int tarantoolSqlite3EphemeralCreate(BtCursor *pCur, uint32_t field_count,
>> *
>> * @retval SQLITE_OK on success, SQLITE_TARANTOOL_ERROR otherwise.
>> */
>> -int tarantoolSqlite3EphemeralInsert(BtCursor *pCur)
>> +int tarantoolSqlite3EphemeralInsert(struct space *space, char *tuple,
>> + char *tuple_end)
>
> 1. Please, update the comment as well. And lets move it to a header, as it is done in tarantool core.
Fixed:
@@ -441,18 +441,8 @@ int tarantoolSqlite3EphemeralCreate(BtCursor *pCur, uint32_t field_count,
return tarantoolSqlite3First(pCur, &unused);
}
-/*
- * Insert tuple which is contained in pX into ephemeral space. In contrast to
- * ordinary spaces, there is no need to create and fill request or handle
- * transaction routine.
- *
- * @param pCur Cursor pointing to ephemeral space.
- * @param pX Payload containing tuple to insert.
- *
- * @retval SQLITE_OK on success, SQLITE_TARANTOOL_ERROR otherwise.
- */
+int tarantoolSqlite3EphemeralInsert(struct space *space, const char *tuple,
+ const char *tuple_end)
@@ -98,8 +100,19 @@ int tarantoolSqlite3RenameParentTable(int iTab, const char *zOldParentName,
/* Interface for ephemeral tables. */
int tarantoolSqlite3EphemeralCreate(BtCursor * pCur, uint32_t filed_count,
struct coll *aColl);
-int tarantoolSqlite3EphemeralInsert(struct space *space, char *tuple,
- char *tuple_end);
+/**
+ * Insert tuple into ephemeral space.
+ * In contrast to ordinary spaces, there is no need to create and
+ * fill request or handle transaction routine.
+ *
+ * @param space Ephemeral space.
+ * @param tuple Tuple to be inserted.
+ * @param tuple_end End of tuple to be inserted.
+ *
+ * @retval SQLITE_OK on success, SQLITE_TARANTOOL_ERROR otherwise.
+ */
+int tarantoolSqlite3EphemeralInsert(struct space *space, const char *tuple,
+ const char *tuple_end);
>
>> {
>> - assert(pCur);
>> - assert(pCur->curFlags & BTCF_TEphemCursor);
>> - mp_tuple_assert(pCur->key, pCur->key + pCur->nKey);
>> -
>> - if (space_ephemeral_replace(pCur->space, pCur->key,
>> - pCur->key + pCur->nKey) != 0) {
>> - diag_log();
>> + assert(space != NULL);
>> + mp_tuple_assert(tuple, tuple_end);
>> + if (space_ephemeral_replace(space, tuple, tuple_end) != 0)
>> return SQL_TARANTOOL_INSERT_FAIL;
>> - }
>> return SQLITE_OK;
>> }
>> @@ -475,28 +471,29 @@ int tarantoolSqlite3EphemeralDrop(BtCursor *pCur)
>> }
>> static inline int
>> -insertOrReplace(BtCursor *pCur, enum iproto_type type)
>> +insertOrReplace(struct space *space, char *tuple, char *tuple_end,
>> + enum iproto_type type)
>
> 2. Please, make a pointer be const, if it is not changed. Here it is const. Const specifier helps compiler to do more accurate optimization.
Fixed:
@@ -471,7 +461,7 @@ int tarantoolSqlite3EphemeralDrop(BtCursor *pCur)
}
static inline int
-insertOrReplace(struct space *space, char *tuple, char *tuple_end,
+insertOrReplace(struct space *space, const char *tuple, const char *tuple_end,
>
>> -int tarantoolSqlite3Insert(BtCursor *pCur)
>> +int tarantoolSqlite3Insert(struct space *space, char *tuple, char *tuple_end)
>> {
>> - return insertOrReplace(pCur, IPROTO_INSERT);
>> + return insertOrReplace(space, tuple, tuple_end, IPROTO_INSERT);
>> }
>> -int tarantoolSqlite3Replace(BtCursor *pCur)
>> +int tarantoolSqlite3Replace(struct space *space, char *tuple, char *tuple_end)
>
> 3. Same.
-int tarantoolSqlite3Replace(struct space *space, char *tuple, char *tuple_end)
+int tarantoolSqlite3Replace(struct space *space, const char *tuple,
+ const char *tuple_end)
-int tarantoolSqlite3Insert(struct space *space, char *tuple, char *tuple_end)
+int tarantoolSqlite3Insert(struct space *space, const char *tuple,
+ const char *tuple_end)
src/box/sql/tarantoolInt.h:
-int tarantoolSqlite3Insert(struct space *space, char *tuple, char *tuple_end);
-int tarantoolSqlite3Replace((struct space *space, char *tuple, char *tuple_end);
+int tarantoolSqlite3Insert(struct space *space, const char *tuple,
+ const char *tuple_end);
+int tarantoolSqlite3Replace(struct space *space, const char *tuple,
+ const char *tuple_end);
next prev parent reply other threads:[~2018-04-13 8:39 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-11 19:35 [tarantool-patches] [PATCH 0/2] sql: SQL bindings refactoring Nikita Pettik
2018-04-11 19:35 ` [tarantool-patches] [PATCH 1/2] sql: fix tuple format leak Nikita Pettik
2018-04-12 11:58 ` [tarantool-patches] " Vladislav Shpilevoy
2018-04-13 8:39 ` n.pettik [this message]
2018-04-11 19:35 ` [tarantool-patches] [PATCH 2/2] sql: refactor cursor closing routine Nikita Pettik
2018-04-12 13:28 ` [tarantool-patches] " Vladislav Shpilevoy
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=0970BD07-7BA0-4EF3-B50B-1F821F7B3570@tarantool.org \
--to=korablev@tarantool.org \
--cc=tarantool-patches@freelists.org \
--cc=v.shpilevoy@tarantool.org \
--subject='[tarantool-patches] Re: [PATCH 1/2] sql: fix tuple format leak' \
/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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox