Skip to content

Commit c151d2d

Browse files
committed
standard: change uses of sprintf into snprintf and zend_string_concat2
1 parent a467465 commit c151d2d

File tree

4 files changed

+6
-8
lines changed

4 files changed

+6
-8
lines changed

ext/standard/dns.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ static uint8_t *php_parserr(uint8_t *cp, uint8_t *end, querybuf *answer, int typ
641641
tp[0] = ':';
642642
tp++;
643643
}
644-
tp += sprintf((char*)tp,"%x",s);
644+
tp += snprintf((char*)tp, sizeof(name) - (tp - (uint8_t *) name), "%x", s);
645645
} else {
646646
if (!have_v6_break) {
647647
have_v6_break = 1;
@@ -686,7 +686,7 @@ static uint8_t *php_parserr(uint8_t *cp, uint8_t *end, querybuf *answer, int typ
686686
tp[0] = ':';
687687
tp++;
688688
}
689-
sprintf((char*)tp, "%x", cp[0] & 0xFF);
689+
snprintf((char*)tp, sizeof(name) - (tp - (uint8_t *) name), "%x", cp[0] & 0xFF);
690690
} else {
691691
if (!have_v6_break) {
692692
have_v6_break = 1;
@@ -711,7 +711,7 @@ static uint8_t *php_parserr(uint8_t *cp, uint8_t *end, querybuf *answer, int typ
711711
tp[0] = ':';
712712
tp++;
713713
}
714-
tp += sprintf((char*)tp,"%x",s);
714+
tp += snprintf((char*)tp, sizeof(name) - (tp - (uint8_t *) name),"%x",s);
715715
} else {
716716
if (!have_v6_break) {
717717
have_v6_break = 1;

ext/standard/dns_win32.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ static void php_parserr(PDNS_RECORD pRec, int type_to_fetch, int store, bool raw
282282
tp[0] = ':';
283283
tp++;
284284
}
285-
tp += sprintf((char*)tp,"%x", out[i]);
285+
tp += snprintf((char*)tp, sizeof(buf) - (tp - (char *) buf), "%x", out[i]);
286286
} else {
287287
if (!have_v6_break) {
288288
have_v6_break = 1;

ext/standard/password.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,7 @@ static zend_string* php_password_bcrypt_hash(const zend_string *password, zend_a
201201
}
202202
ZSTR_VAL(salt)[ZSTR_LEN(salt)] = 0;
203203

204-
hash = zend_string_alloc(ZSTR_LEN(salt) + hash_format_len, 0);
205-
sprintf(ZSTR_VAL(hash), "%s%s", hash_format, ZSTR_VAL(salt));
206-
ZSTR_VAL(hash)[hash_format_len + ZSTR_LEN(salt)] = 0;
204+
hash = zend_string_concat2(hash_format, hash_format_len, ZSTR_VAL(salt), ZSTR_LEN(salt));
207205

208206
zend_string_release_ex(salt, 0);
209207

ext/standard/string.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3846,7 +3846,7 @@ PHPAPI zend_string *php_addcslashes_str(const char *str, size_t len, const char
38463846
case '\v': *target++ = 'v'; break;
38473847
case '\b': *target++ = 'b'; break;
38483848
case '\f': *target++ = 'f'; break;
3849-
default: target += sprintf(target, "%03o", (unsigned char) c);
3849+
default: target += snprintf(target, 4, "%03o", (unsigned char) c);
38503850
}
38513851
continue;
38523852
}

0 commit comments

Comments
 (0)