From: Otto Moerbeek Date: Tue, 5 Feb 2019 12:04:43 +0000 (+0100) Subject: sprintf, strcpy and const method case X-Git-Tag: auth-4.2.0-beta1~35^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=385b86f68bbf47d358ba66d0a6f118fb9006c7cc;p=thirdparty%2Fpdns.git sprintf, strcpy and const method case --- diff --git a/modules/ldapbackend/powerldap.cc b/modules/ldapbackend/powerldap.cc index bfec0cd34f..a2c1a5353f 100644 --- a/modules/ldapbackend/powerldap.cc +++ b/modules/ldapbackend/powerldap.cc @@ -456,7 +456,7 @@ const string PowerLDAP::escape( const string& str ) (unsigned char)*i == '\0' || (unsigned char)*i > 127) { - sprintf(tmp,"\\%02x", (unsigned char)*i); + snprintf(tmp, sizeof(tmp), "\\%02x", (unsigned char)*i); a += tmp; } diff --git a/pdns/bindlexer.l b/pdns/bindlexer.l index 8003a2740e..370dbff331 100644 --- a/pdns/bindlexer.l +++ b/pdns/bindlexer.l @@ -60,25 +60,17 @@ include BEGIN(incl); include_stack_ln[include_stack_ptr++]=linenumber; linenumber=1; - if(*(yytext+1)=='/') { - if (strlen(yytext+1) >= sizeof(filename)) { - fprintf( stderr, "Filename '%s' is too long\n",yytext+1); - exit( 1 ); - } - strcpy(filename,yytext+1); - } - else { - size_t bind_directory_len = strlen(bind_directory); - if (bind_directory_len >= sizeof(filename) || - strlen(yytext+1) + 2 >= sizeof(filename) - bind_directory_len) { - fprintf( stderr, "Filename '%s' is too long\n",yytext+1); - exit( 1 ); - } - strcpy(filename,bind_directory); - strcat(filename,"/"); - strcat(filename,yytext+1); - } - filename[sizeof(filename)-1]='\0'; + int ret; + if(*(yytext+1)=='/') { + ret = snprintf(filename, sizeof(filename), "%s", yytext+1); + } + else { + ret = snprintf(filename, sizeof(filename), "%s/%s", bind_directory, yytext+1); + } + if (ret == -1 || ret >= sizeof(filename)) { + fprintf( stderr, "Filename '%s' is too long\n",yytext+1); + exit( 1 ); + } if (!(yyin=fopen(filename,"r"))) { fprintf( stderr, "Unable to open '%s': %s\n",filename,strerror(errno)); diff --git a/pdns/communicator.hh b/pdns/communicator.hh index 087a3dbc58..5413e4dacf 100644 --- a/pdns/communicator.hh +++ b/pdns/communicator.hh @@ -209,7 +209,7 @@ private: time_t d_tickinterval; set d_tocheck; struct cmp { - bool operator()(const DNSPacket& a, const DNSPacket& b) { + bool operator()(const DNSPacket& a, const DNSPacket& b) const { return a.qdomain < b.qdomain; }; }; diff --git a/pdns/misc.cc b/pdns/misc.cc index f9259d3d72..9293a49242 100644 --- a/pdns/misc.cc +++ b/pdns/misc.cc @@ -582,7 +582,7 @@ string makeHexDump(const string& str) ret.reserve((int)(str.size()*2.2)); for(string::size_type n=0;n