简体   繁体   English

从函数返回时的SIGABRT

[英]SIGABRT when returning from function

my problem is that, just as I mentioned on the title, i have a function that, upon return, causes a SIGABRT to be raised. 我的问题是,正如我在标题中提到的那样,我有一个函数,该函数在返回时会引发SIGABRT。 I ran valgrind on my program and I got this at that exact point. 我在我的程序上运行了valgrind,并且在那个确切的时间点就明白了。

==5807== Process terminating with default action of signal 6 (SIGABRT)
==5807==    at 0x52F5428: raise (raise.c:54)
==5807==    by 0x52F7029: abort (abort.c:89)
==5807==    by 0x53377E9: __libc_message (libc_fatal.c:175)
==5807==    by 0x53D911B: __fortify_fail (fortify_fail.c:37)
==5807==    by 0x53D90BF: __stack_chk_fail (stack_chk_fail.c:28)
==5807==    by 0x402E8B: foo (file.c:43)
==5807==    by 0x202C27323939312C: ???
==5807==    by 0x592D4D4D2D444426: ???
==5807==    by 0x66202C2927595958: ???
==5807==    by 0x2965736C60: ???
==5807==    by 0x505770F: ??? (in /usr/lib/x86_64-linux-gnu/libodbc.so.2.0.0)

==5807==

This is the code i'm executing, the stack error causes the abort at the return ret statement from add_user: 这是我正在执行的代码,堆栈错误导致add_user的return ret语句中止:

int add_user(SQLHDBC dbc, char * mail, char * password, char * name,  char * date) {

char query[TAM];
SQLHSTMT stmt;
SQLRETURN ret;

if (mail == NULL || password == NULL || name == NULL ||  date == NULL)
    return ERR;

sprintf(query, "INSERT INTO mms_user values (default,'%s',encrypt_password('%s'),set_type(),'%s',to_date('%s', 'DD-MM-YYYY'), false)", mail, password, name,date);

ret= DBExecuteQuery(dbc, query, &stmt);

DBFreeHandle(&stmt);
return ret;
}

int DBExecuteQuery(SQLHDBC dbc, char * query, SQLHSTMT *stmt) {

SQLRETURN ret;

/*Error control*/
if (query == NULL || stmt == NULL)
    return ERR;

/*Allocates memory for a new statement*/
ret = SQLAllocHandle(SQL_HANDLE_STMT, dbc, stmt);
if (!SQL_SUCCEEDED(ret)) {
    return ERR;
}

/*Executes query and stores result in stmt*/
ret = SQLExecDirect(*stmt, (SQLCHAR *)query, SQL_NTS);
if (!SQL_SUCCEEDED(ret))
    return ERR;

return OK;

}

int DBFreeHandle(SQLHSTMT * stmt){

 int ret;
  /*Frees allocated memory*/
  ret = SQLFreeHandle(SQL_HANDLE_STMT, *stmt);
  if (!SQL_SUCCEEDED(ret)) {
      return ERR;
  }

}

The function executes normally as far as I have checked. 据我检查,该功能正常执行。 I don't know what could be happening, if any of you could provide any possible explanation, I would be really thankful. 我不知道会发生什么,如果任何人都可以提供任何可能的解释,我将非常感激。 Also feel free to ask for further information (this is the only useful info I've been taught to look for, so I might need some guidance in that case). 也可以随时询问更多信息(这是我被教导要寻找的唯一有用的信息,因此在这种情况下,我可能需要一些指导)。

Thank you in advance 先感谢您

This code is dangerous: 此代码很危险:

char query[TAM];
 .
 .
 .
sprintf(query, "INSERT INTO mms_user values"
    " (default,'%s',encrypt_password('%s'),set_type(),"
    "'%s',to_date('%s', 'DD-MM-YYYY'), false)",
     mail, password, name,date);

You do absolutely no bounds checking so it will overflow your stack easily. 您绝对没有边界检查,因此它很容易溢出堆栈。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM