commit 4f85d27efdf443cccf18ba29a3221f524904cce2 from: Mergen Imeev via: Igor Munkin date: Tue Nov 07 12:05:52 2023 UTC sql: fix segmentation fault when JOIN uses USING Before this patch, nameInUsingClause() expected old_col to be non-NULL, but this may not be the case. This patch fixes this feature accordingly. Follow-up #4467 NO_DOC=bugfix NO_CHANGELOG=feature was not released yet commit - 6cb86dc1738d40d5aba3f3001a1e01b3dae5cd16 commit + 4f85d27efdf443cccf18ba29a3221f524904cce2 blob - 71de5a0fe99975c98114b162b4debd40bf63e7a8 blob + 48906542ebe563d3ccb92dde44e092299275a9c2 --- src/box/sql/resolve.c +++ src/box/sql/resolve.c @@ -137,16 +137,18 @@ resolveAlias(struct ExprList *pEList, int iCol, struct static bool nameInUsingClause(struct IdList *pUsing, const char *zCol, const char *old_col) { - if (pUsing) { - for (int k = 0; k < pUsing->nId; k++) { - if (strcmp(pUsing->a[k].zName, zCol) == 0) - return true; - } - for (int i = 0; i < pUsing->nId; i++) { - if (strcmp(pUsing->a[i].zName, old_col) == 0) - return true; - } + if (pUsing == NULL) + return false; + for (int k = 0; k < pUsing->nId; k++) { + if (strcmp(pUsing->a[k].zName, zCol) == 0) + return true; } + if (old_col == NULL) + return false; + for (int i = 0; i < pUsing->nId; i++) { + if (strcmp(pUsing->a[i].zName, old_col) == 0) + return true; + } return false; } blob - 47db22cd5546d67eb45e6eee579cbf9a15534bc1 blob + f17147cb8153acff6236540ea30e403d2c14f034 --- test/sql-luatest/gh_4467_sql_id_backwards_compatibility_test.lua +++ test/sql-luatest/gh_4467_sql_id_backwards_compatibility_test.lua @@ -661,3 +661,12 @@ g.test_drop_constraint = function() box.func.check_ASD_THREE:drop() end) end + +-- Make sure USING in JOIN does not cause segfault. +g.test_using_in_join = function() + g.server:exec(function() + box.execute([[CREATE TABLE T(I INT PRIMARY KEY, A INT);]]) + box.execute([[SELECT * FROM T LEFT JOIN T USING(A);]]) + box.execute([[DROP TABLE T;]]) + end) +end