- char remain[NAME_MAX];
- int ret, proto, proto_offset = 0;
-
- ret = sscanf(path, "net%d%s", &proto, remain);
- if (ret < 2) {
+ char remain[2][NAME_MAX];
+ int ret = -1, proto, proto_offset = 0;
+ size_t path_len = strlen(path);
+
+ /*
+ * Since sscanf API does not allow easily checking string length
+ * against a size defined by a macro. Test it beforehand on the
+ * input. We know the output is always <= than the input length.
+ */
+ if (path_len > NAME_MAX) {
+ goto end;
+ }
+ ret = sscanf(path, "net%d://", &proto);
+ if (ret < 1) {